| 1 | package CGI::Application::Plugin::RunmodeParseKeyword; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | $CGI::Application::Plugin::RunmodeParseKeyword::VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | CGI::Application::Plugin::RunmodeParseKeyword - Declare runmodes using Parse::Keyword | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | our @EXPORT = qw(runmode errormode startmode); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Sub::Name 'subname'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Parse::Keyword {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | $Carp::Internal{ (__PACKAGE__) }++; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 14 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 14 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 14 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 14 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 14 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 14 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | Parse::Keyword->import( { runmode => sub { my ($kw) = @_; parse_mode($kw, $inv); } } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | ▶ | Parse::Keyword->import( { errormode => sub { my ($kw) = @_; parse_mode($kw, $inv); } } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | ▶ | Parse::Keyword->import( { startmode => sub { my ($kw) = @_; parse_mode($kw, $inv); } } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 14 | for my $e(@EXPORT) { | |||||||||||||||||||||||||||||||||||||||||
| 32 | 42 | my $fn = $into . '::' . $e; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 42 | *$fn = \&$e; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 42 | *$fn if 0; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | sub runmode { @_ ? $_[0] : () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
runmode: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub errormode { @_ ? $_[0] : () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errormode: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | sub startmode { @_ ? $_[0] : () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startmode: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | my %REGISTRY; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | ▶ | sub _setup_runmode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_runmode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | my ($pkg, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 11 | ▶ | $pkg->add_callback( init => sub { $_[0]->run_modes([ $name ]) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | sub _setup_startmode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_startmode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | my ($pkg, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | no strict 'refs'; no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | # compile time check | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | croak "start mode redefined (from $REGISTRY{$pkg}{start_mode_installed})" if $REGISTRY{$pkg}{start_mode_installed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | $pkg->add_callback( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 26 | ▶ | init => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | # run time check | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | ▶ | return if exists $_[0]->{__START_MODE_SET_BY_RUNMODEDECLARE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | $_[0]->run_modes( [$name] ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | $_[0]->start_mode($name); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | $_[0]->{__START_MODE_SET_BY_RUNMODEDECLARE} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 8 | $REGISTRY{$pkg}{start_mode_installed} = join '::', $pkg, $name; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | sub _setup_errormode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_errormode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | my ($pkg, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | no strict 'refs'; no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | croak "error mode redefined (from $REGISTRY{$pkg}{error_mode_installed})" if $REGISTRY{$pkg}{error_mode_installed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | $pkg->add_callback( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 19 | ▶ | init => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | ▶ | return if exists $_[0]->{__ERROR_MODE_SET_BY_RUNMODEDECLARE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | $_[0]->error_mode($name); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | $_[0]->{__ERROR_MODE_SET_BY_RUNMODEDECLARE} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | $REGISTRY{$pkg}{error_mode_installed} = join '::', $pkg, $name; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =begin pod-coverage | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =item parse_mode - we hook into this to install cgiapp callbacks | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =item parse_name - identifier name parser | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =item parse_signature - runmode signature parser | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =item parse_attribute - parse one sub attr | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =item parse_attributes - parse sub attrs | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =item parse_body - parse code and inject defaults | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =end pod-coverage | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 28 | ▶ | sub parse_mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_mode: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 28 | my ($keyword, $invocant) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 28 | my $name = parse_name(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 28 | my $sig = parse_signature($invocant); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 27 | my $attr = parse_attributes(); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 27 | ▶ | my $body = parse_body($sig) or ($@ and die); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
(my $body = parse_body($sig)) || $@ && die()
$@ and die
MC/DC0%0/2
(my $body = parse_body($sig)) || $@ && die()
(my $body = parse_body($sig))
$@
Truth table66%2/3
A || B
A= (my $body = parse_body($sig))B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 25 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | my $full_name = join('::', compiling_package, $name); | |||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | *$full_name = subname $full_name, $body; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 25 | ▶ | if ($attr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | ▶ | use attributes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | attributes->import(compiling_package, $body, $_) for @$attr; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 25 | my $setup = '_setup_' . $keyword; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 25 | $setup->(compiling_package, $name, $body); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 25 | ▶ | return (sub {}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return (sub { $body }, 0); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | my $start_rx = qr/^[\p{ID_Start}_]$/; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | my $cont_rx = qr/^\p{ID_Continue}$/; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 59 | ▶ | sub parse_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_name: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 59 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 59 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 59 | my $char_rx = $start_rx; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 59 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 304 | my $char = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 304 | ▶ | last unless length $char; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 304 | ▶ | if ($char =~ $char_rx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 245 | $name .= $char; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 245 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 245 | $char_rx = $cont_rx; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 59 | last; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 59 | ▶ | return length($name) ? $name : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 28 | ▶ | sub parse_signature { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_signature: called CC=15 SCAR=30.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 28 | my ($invocant_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 28 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 28 | my @vars = ({ index => 0, name => $invocant_name }); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 28 | ▶ | return \@vars unless lex_peek eq '('; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 19 | my @attr = (); | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 19 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 19 | ▶ | if (lex_peek eq ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | return \@vars; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 18 | my $seen_slurpy; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 18 | ▶ | while ((my $sigil = lex_peek) ne ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 29 | my $var = {}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 29 | ▶ | die "syntax error: expected ')' but found '$sigil'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/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 table50%2/4
A or B or C
A= $sigil eq "\$"B= $sigil eq "\@"C= $sigil eq "%"
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | unless $sigil eq '$' || $sigil eq '@' || $sigil eq '%'; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 29 | ▶ | die "Can't declare parameters after a slurpy parameter" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | if $seen_slurpy; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 29 | ▶ | $seen_slurpy = 1 if $sigil eq '@' || $sigil eq '%'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sigil eq "\@" or $sigil eq "%"
MC/DC50%1/2
$sigil eq "\@" or $sigil eq "%"
$sigil eq "\@"
$sigil eq "%"
Truth table66%2/3
A or B
A= $sigil eq "\@"B= $sigil eq "%"
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 29 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 29 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 29 | my $name = parse_name(0); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 29 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 29 | $var->{name} = "$sigil$name"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 29 | ▶ | if (lex_peek eq '=') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | $var->{default} = parse_arithexpr; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 29 | $var->{index} = @vars - 1; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 29 | ▶ | if (lex_peek eq ':') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $vars[0] = $var; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 29 | push @vars, $var; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 29 | my $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 29 | ▶ | die "syntax error: expected ')' or ',' but found '$c'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c eq ")" or $c eq ","
MC/DC100%2/2
$c eq ")" or $c eq ","
$c eq ")"
$c eq ","
Truth table100%3/3
A or B
A= $c eq ")"B= $c eq ","
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | unless $c eq ')' || $c eq ','; | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 28 | ▶ | if (lex_peek eq ',') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 11 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 17 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 17 | return \@vars; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | # grabbed these two functions from | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # https://metacpan.org/release/PEVANS/XS-Parse-Keyword-0.22/source/hax/lexer-additions.c.inc#L74 | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | sub parse_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_attribute: called CC=9 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | my $name = parse_name; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | if (lex_peek ne '(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | $name .= lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | my $count = 1; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | my $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | while($count && length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$count and length $c
MC/DC0%0/2
$count and length $c
$count
length $c
Truth table33%1/3
A and B
A= $countB= length $c
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | ▶ | if($c eq '(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | ▶ | if($c eq ')') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | $count--; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | if($c eq '\\') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | # The next char does not bump count even if it is ( or ); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # the \\ is still captured | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $name .= $c; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if(! length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | goto unterminated; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # Don't append final closing ')' on split name/val | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | $name .= $c; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 8 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 8 | $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | ▶ | if(!length $c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | unterminated: | |||||||||||||||||||||||||||||||||||||||||
| 264 | croak("Unterminated attribute parameter in attribute list"); | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 27 | ▶ | sub parse_attributes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_attributes: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 27 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 27 | ▶ | return unless lex_peek eq ':'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | my @attrs; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | while (my $attr = parse_attribute) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | push @attrs, $attr; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | if (lex_peek eq ':') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | return \@attrs; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 27 | ▶ | sub parse_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_body: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 27 | my $sigs = shift; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 27 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 27 | lex_read_space; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 27 | my $c = lex_peek; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 27 | ▶ | croak "syntax error: expected start of block '{' but found '$c'" unless $c eq '{'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 26 | local $CAPRPK::{'DEFAULTS::'}; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 26 | ▶ | if ($sigs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 26 | lex_read; | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 26 | my $preamble = '{'; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | # invocant | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 26 | my $inv = shift @$sigs; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 26 | $preamble .= "my $inv->{name} = shift;"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | # arguments / query params | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 26 | my @names = map { $_->{name} } @$sigs; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 26 | $preamble .= 'my (' . join(', ', @names) . ') = @_;'; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 26 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 27 | my $p; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 27 | my $s = substr($name,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 312 | 27 | my $n = substr($name,1); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 27 | ▶ | if ($s eq '$') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 21 | $p = $inv->{name} . '->param("' . $n . '")'; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 21 | ▶ | $preamble .= $name . ' = ' . $p . ' unless ' . ( $s eq '$' ? 'defined ' : 'scalar ') . $name . ';'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 27 | ▶ | $p = $inv->{name} . '->query->' . ($s eq '@' ? 'multi_param' : 'param') . '("' . $n . '")'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 27 | ▶ | $preamble .= $name . ' = ' . $p . ' unless ' . ( $s eq '$' ? 'defined ' : 'scalar ') . $name . ';'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 27 | ▶ | if ($s eq '@') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 6 | ▶ | $p = $inv->{name} . '->query->' . ($s eq '@' ? 'multi_param' : 'param') . '("' . $n . '[]")'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | ▶ | $preamble .= $name . ' = ' . $p . ' unless ' . ( $s eq '$' ? 'defined ' : 'scalar ') . $name . ';'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 26 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 26 | for my $var (grep { defined $_->{default} } @$sigs) { | |||||||||||||||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 3 | ▶ | *{ 'CAPRPK::DEFAULTS::default_' . $index } = sub () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | $var->{default} | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | $preamble .= $var->{name} . ' = CAPRPK::DEFAULTS::default_' . $index . '->()' . ' unless ' . $var->{name} . ';'; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # warn $preamble . $/; | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 26 | lex_stuff($preamble); | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | $body = parse_block; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 26 | return $body; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | __END__ | ||||||||||||||||||||||||||||||||||||||||||