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