| 1 | package Method::Signatures::Simple::ParseKeyword; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $Method::Signatures::Simple::ParseKeyword::VERSION = '1.14'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | Method::Signatures::Simple::ParseKeyword - method and func keywords using Parse::Keyword | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Sub::Name 'subname'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Parse::Keyword {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | our @EXPORT; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | our %MAP; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | $Carp::Internal{ (__PACKAGE__) }++; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 20 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 20 | my %kwds; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 20 | ▶ | my $into = delete $args{into} || $caller; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $args{'into'} || $caller
MC/DC0%0/2
delete $args{'into'} || $caller
delete $args{'into'}
$caller
Truth table66%2/3
A || B
A= delete $args{'into'}B= $caller
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | ▶ | my $inv = delete $args{invocant} || '$self'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'invocant'} || '$self'
MC/DC100%1/1
delete $args{'invocant'} || '$self'
delete $args{'invocant'}
Truth table100%2/2
A
A= delete $args{'invocant'}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | ▶ | my $meth = delete $args{name} || delete $args{method_keyword}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
delete $args{'name'} || delete $args{'method_keyword'}
MC/DC100%2/2
delete $args{'name'} || delete $args{'method_keyword'}
delete $args{'name'}
delete $args{'method_keyword'}
Truth table100%3/3
A || B
A= delete $args{'name'}B= delete $args{'method_keyword'}
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | my $func = delete $args{function_keyword}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # if no options are provided at all, then we supply defaults | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | unless (defined $meth || defined $func) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $meth or defined $func
MC/DC100%2/2
defined $meth or defined $func
defined $meth
defined $func
Truth table100%3/3
A or B
A= defined $methB= defined $func
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 15 | $meth = 'method'; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | $func = 'func'; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # input validation | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 20 | ▶ | $inv =~ m/^ \s* \$ [\p{ID_Start}_] \p{ID_Continue}* \s* $/x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | or croak "invocant must be a valid scalar identifier >$inv<"; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 19 | ▶ | if ($func) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | $func =~ m/^ \s* [\p{ID_Start}_] \p{ID_Continue}* \s* $/x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | or croak "function_keyword must be a valid identifier >$func<"; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | ▶ | *$func = sub { @_ ? $_[0] : () }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | my $parse = "parse_$func"; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | ▶ | *$parse = sub { my ($kw) = @_; parse_mode($kw); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 15 | $MAP{$func} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | $kwds{ $func } = \&$parse; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 15 | push @EXPORT, $func; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 18 | ▶ | if ($meth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | ▶ | $meth =~ m/^ \s* [\p{ID_Start}_] \p{ID_Continue}* \s* $/x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | or croak "method_keyword must be a valid identifier >$meth<"; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | ▶ | *$meth = sub { @_ ? $_[0] : () }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | my $parse = "parse_$meth"; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | ▶ | *$parse = sub { my ($kw) = @_; parse_mode($kw); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 16 | $MAP{$meth} = $inv; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | @kwds{ $meth } = \&$parse; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | push @EXPORT, $meth; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 17 | Parse::Keyword->import(\%kwds); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | for my $e (@EXPORT) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 48 | my $n = $e =~ s/[$%@]//r; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 48 | my $fn = $into. '::' . $n; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 48 | *$fn = $e; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 48 | my $k = *$fn; # avoid 'once' warning | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 21 | ▶ | sub parse_mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_mode: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 21 | my ($keyword, $invocant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 21 | ▶ | $invocant ||= $MAP{$keyword}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$invocant ||= $Method::Signatures::Simple::ParseKeyword::MAP{$keyword}
MC/DC50%1/2
$invocant ||= $Method::Signatures::Simple::ParseKeyword::MAP{$keyword}
$invocant
$Method::Signatures::Simple::ParseKeyword::MAP{$keyword}
Truth table66%2/3
A ||= B
A= $invocantB= $Method::Signatures::Simple::ParseKeyword::MAP{$keyword}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 21 | my $name = parse_name(); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 21 | my $sig = parse_signature($invocant); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | my $attr = parse_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 18 | my $body = parse_body($sig); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 18 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 18 | my $full_name = join('::', compiling_package, $name); | |||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 18 | *$full_name = subname $full_name, $body; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | if ($attr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | ▶ | use attributes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | attributes->import(compiling_package, $body, $_) for @$attr; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 18 | ▶ | return (sub {}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return (sub { $body }, 0); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | my $start_rx = qr/^[\p{ID_Start}_]$/; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | my $cont_rx = qr/^\p{ID_Continue}$/; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 45 | ▶ | sub parse_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_name: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 45 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 45 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 45 | my $char_rx = $start_rx; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 45 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 112 | 237 | my $char = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 237 | ▶ | last unless length $char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 237 | ▶ | if ($char =~ $char_rx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 192 | $name .= $char; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 192 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 192 | $char_rx = $cont_rx; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 45 | last; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 45 | ▶ | return length($name) ? $name : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 21 | ▶ | sub parse_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_signature: called CC=16 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 21 | my ($invocant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 21 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 21 | ▶ | my @vars = $invocant ? ({ index => 0, name => $invocant, is_inv => 1 }) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 21 | ▶ | return \@vars unless lex_peek eq '('; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 19 | my @attr = (); | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 19 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 19 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 19 | ▶ | if (lex_peek eq ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | return \@vars; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 16 | my $seen_slurpy; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 16 | ▶ | while ((my $sigil = lex_peek) ne ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 26 | my $var = {}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 26 | ▶ | croak qq{syntax error: expected sigil instead of "$sigil"} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$sigil eq "\$" or $sigil eq "\@" or $sigil eq "%"
$sigil eq "\$" or $sigil eq "\@"
MC/DC100%3/3
$sigil eq "\$" or $sigil eq "\@" or $sigil eq "%"
$sigil eq "\$"
$sigil eq "\@"
$sigil eq "%"
Truth table100%4/4
A or B or C
A= $sigil eq "\$"B= $sigil eq "\@"C= $sigil eq "%"
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | unless $sigil eq '$' || $sigil eq '@' || $sigil eq '%'; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 25 | ▶ | croak "Can't declare parameters after a slurpy parameter" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | if $seen_slurpy; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 24 | ▶ | $seen_slurpy = 1 if $sigil eq '@' || $sigil eq '%'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sigil eq "\@" or $sigil eq "%"
MC/DC100%2/2
$sigil eq "\@" or $sigil eq "%"
$sigil eq "\@"
$sigil eq "%"
Truth table100%3/3
A or B
A= $sigil eq "\@"B= $sigil eq "%"
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 24 | my $name = parse_name(0); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 24 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 24 | $var->{name} = "$sigil$name"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 24 | ▶ | if (lex_peek eq '=') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $var->{default} = parse_arithexpr; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | $var->{index} = @vars - 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | ▶ | if (lex_peek eq ':') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | $vars[0] = $var; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 20 | push @vars, $var; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 20 | ▶ | croak qq{syntax error: expected ')' or ',' instead of "} . lex_peek . q{"} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
lex_peek() eq ")" or lex_peek() eq ","
MC/DC0%0/2
lex_peek() eq ")" or lex_peek() eq ","
lex_peek() eq ")"
lex_peek() eq ","
Truth table0%0/3
A or B
A= lex_peek() eq ")"B= lex_peek() eq ","
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | unless lex_peek eq ')' || lex_peek eq ','; | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 19 | ▶ | if (lex_peek eq ',') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 9 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 13 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 13 | return \@vars; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # grabbed these two functions from | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # https://metacpan.org/release/PEVANS/XS-Parse-Keyword-0.22/source/hax/lexer-additions.c.inc#L74 | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub parse_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_attribute: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $name = parse_name; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (lex_peek ne '(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $name .= lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $count = 1; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | while($count && length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count and length $c
MC/DC0%0/2
$count and length $c
$count
length $c
Truth table0%0/3
A and B
A= $countB= length $c
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if($c eq '(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if($c eq ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $count--; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if($c eq '\\') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | # The next char does not bump count even if it is ( or ); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # the \\ is still captured | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $name .= $c; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if(! length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | goto unterminated; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # Don't append final closing ')' on split name/val | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $name .= $c; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if(!length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | unterminated: | |||||||||||||||||||||||||||||||||||||||||
| 236 | croak("Unterminated attribute parameter in attribute list"); | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 18 | ▶ | sub parse_attributes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_attributes: called CC=4 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 18 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 18 | ▶ | return unless lex_peek eq ':'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my @attrs; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | while (my $attr = parse_attribute) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | push @attrs, $attr; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (lex_peek eq ':') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return \@attrs; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 18 | ▶ | sub parse_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_body: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 18 | my ($sigs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 18 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 18 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 18 | ▶ | if (lex_peek eq '{') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | local $CAPRPK::{'DEFAULTS::'}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 18 | ▶ | if ($sigs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 18 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | my $preamble = '{'; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # arguments / query params | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # if this is a method, unshift the invocant from @_ | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 18 | ▶ | if (@$sigs && $sigs->[0]{is_inv}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$sigs and $sigs->[0]{"is_inv"}
MC/DC50%1/2
@$sigs and $sigs->[0]{"is_inv"}
@$sigs
$sigs->[0]{"is_inv"}
Truth table66%2/3
A and B
A= @$sigsB= $sigs->[0]{"is_inv"}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 11 | $preamble .= "my $sigs->[0]{name} = shift;"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 11 | shift @$sigs; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 18 | my @names = map { $_->{name} } @$sigs; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 18 | $preamble .= 'my (' . join(', ', @names) . ') = @_;'; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 18 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 18 | for my $var (grep { defined $_->{default} } @$sigs) { | |||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | ▶ | *{ 'CAPRPK::DEFAULTS::default_' . $index } = sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | $var->{default} | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $preamble .= $var->{name} . ' = CAPRPK::DEFAULTS::default_' . $index . '->()' . ' unless ' . $var->{name} . ';'; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 18 | $preamble .= "; ();"; # fix for empty method body | |||||||||||||||||||||||||||||||||||||||||
| 295 | 18 | lex_stuff($preamble); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 18 | $body = parse_block; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | die "syntax error"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 18 | return $body; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | __END__ | ||||||||||||||||||||||||||||||||||||||||||