/usr/share/perl5/Parse/KeywordX.pm is in libkavorka-perl 0.036-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | use 5.014;
use strict;
use warnings;
use Exporter::Tiny ();
package Parse::KeywordX;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.036';
use Text::Balanced qw( extract_bracketed );
use PadWalker qw( closed_over set_closed_over peek_my );
use Parse::Keyword {};
our @ISA = qw( Exporter::Tiny );
our @EXPORT = qw( parse_name parse_variable parse_trait parse_block_or_match );
#### From p5-mop-redux
sub read_tokenish ()
{
my $token = '';
if ((my $next = lex_peek) =~ /[\$\@\%]/)
{
$token .= $next;
lex_read;
}
while ((my $next = lex_peek) =~ /\S/)
{
$token .= $next;
lex_read;
last if ($next . lex_peek) =~ /^\S\b/;
}
return $token;
}
#### From p5-mop-redux
sub parse_name
{
my ($what, $allow_package, $stop_at_single_colon) = @_;
my $name = '';
# XXX this isn't quite right, i think, but probably close enough for now?
my $start_rx = qr/^[\p{ID_Start}_]$/;
my $cont_rx = qr/^\p{ID_Continue}$/;
my $char_rx = $start_rx;
while (1)
{
my $char = lex_peek;
last unless length $char;
if ($char =~ $char_rx)
{
$name .= $char;
lex_read;
$char_rx = $cont_rx;
}
elsif ($allow_package && $char eq ':')
{
if (lex_peek(3) !~ /^::(?:[^:]|$)/)
{
return $name if $stop_at_single_colon;
die("Not a valid $what name: $name" . read_tokenish);
}
$name .= '::';
lex_read(2);
}
else
{
last;
}
}
die("Not a valid $what name: " . read_tokenish) unless length $name;
($name =~ /\A::/) ? "main$name" : $name;
}
sub parse_variable
{
my $allow_bare_sigil = $_[0];
my $sigil = lex_peek(1);
($sigil eq '$' or $sigil eq '@' or $sigil eq '%')
? lex_read(1)
: die("Not a valid variable name: " . read_tokenish);
my $name = $sigil;
my $escape_char = 0;
if (lex_peek(2) eq '{^')
{
lex_read(2);
$name .= '{^';
$name .= parse_name('escape-char variable', 0);
lex_peek(1) eq '}'
? ( lex_read(1), ($name .= '}') )
: die("Expected closing brace after escape-char variable");
return $name;
}
if (lex_peek =~ /[\w:]/)
{
$name .= parse_name('variable', 1, 1);
return $name;
}
if ($allow_bare_sigil)
{
return $name;
}
die "Expected variable name";
}
sub parse_trait
{
my $name = parse_name('trait', 0);
#lex_read_space;
my $extracted;
if (lex_peek eq '(')
{
my $peek = lex_peek(1000);
$extracted = extract_bracketed($peek, '()');
lex_read(length $extracted);
lex_read_space;
$extracted =~ s/(?: \A\( | \)\z )//xgsm;
}
my $evaled = 1;
if (defined $extracted)
{
my $ccstash = compiling_package;
$evaled = eval("package $ccstash; no warnings; no strict; local \$SIG{__WARN__}=sub{die}; [$extracted]");
}
($name, $extracted, $evaled);
}
sub parse_block_or_match
{
lex_read_space;
return parse_block(@_) if lex_peek eq '{';
require match::simple;
my $___term = parse_arithexpr(@_);
eval <<"CODE" or die("could not eval implied match::simple comparison: $@");
sub {
local \$_ = \@_ ? \$_[0] : \$_;
match::simple::match(\$_, \$___term->());
};
CODE
}
1;
|