| 1 | package Web::Dispatch::Predicates; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strictures 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 16 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 7 | match_and match_or match_not match_method match_path match_path_strip | ||||||||||||||||||||||||||||
| 8 | match_extension match_query match_body match_uploads match_true match_false | ||||||||||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 350 | ▶ | sub _matcher { bless shift, 'Web::Dispatch::Matcher' } | ||||||||||||||||||||||||||
|
Subroutine
_matcher: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | sub match_true { | ||||||||||||||||||||||||||
|
Subroutine
match_true: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | _matcher(sub { {} }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub match_false { | ||||||||||||||||||||||||||
|
Subroutine
match_false: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | _matcher(sub {}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 72 | ▶ | sub match_and { | ||||||||||||||||||||||||||
|
Subroutine
match_and: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 72 | my @match = @_; | |||||||||||||||||||||||||||
| 23 | 105 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 24 | 105 | my ($env) = @_; | |||||||||||||||||||||||||||
| 25 | 105 | my $my_env = { 'Web::Dispatch.original_env' => $env, %$env }; | |||||||||||||||||||||||||||
| 26 | 105 | my $new_env; | |||||||||||||||||||||||||||
| 27 | my @got; | ||||||||||||||||||||||||||||
| 28 | 105 | foreach my $match (@match) { | |||||||||||||||||||||||||||
| 29 | 201 | ▶ | if (my @this_got = $match->($my_env)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 161 | my %change_env = %{shift(@this_got)}; | |||||||||||||||||||||||||||
| 31 | 161 | @{$my_env}{keys %change_env} = values %change_env; | |||||||||||||||||||||||||||
| 32 | 161 | @{$new_env}{keys %change_env} = values %change_env; | |||||||||||||||||||||||||||
| 33 | 161 | push @got, @this_got; | |||||||||||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||||||||||
| 35 | 40 | return; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 65 | return ($new_env, @got); | |||||||||||||||||||||||||||
| 39 | }) | ||||||||||||||||||||||||||||
| 40 | 72 | } | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | sub match_or { | ||||||||||||||||||||||||||
|
Subroutine
match_or: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 4 | my @match = @_; | |||||||||||||||||||||||||||
| 44 | 16 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 45 | 16 | foreach my $try (@match) { | |||||||||||||||||||||||||||
| 46 | 30 | ▶ | if (my @ret = $try->(@_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 9 | return @ret; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 7 | return; | |||||||||||||||||||||||||||
| 51 | }) | ||||||||||||||||||||||||||||
| 52 | 4 | } | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub match_not { | ||||||||||||||||||||||||||
|
Subroutine
match_not: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 1 | my ($match) = @_; | |||||||||||||||||||||||||||
| 56 | 3 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if (my @discard = $match->($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | (); | |||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||
| 60 | 2 | ({}); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | }) | ||||||||||||||||||||||||||||
| 63 | 1 | } | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 65 | ▶ | sub match_method { | ||||||||||||||||||||||||||
|
Subroutine
match_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 65 | my ($method) = @_; | |||||||||||||||||||||||||||
| 67 | 92 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 68 | 92 | my ($env) = @_; | |||||||||||||||||||||||||||
| 69 | 92 | ▶ | $env->{REQUEST_METHOD} eq $method ? {} : () | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | }) | ||||||||||||||||||||||||||||
| 71 | 65 | } | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 98 | ▶ | sub match_path { | ||||||||||||||||||||||||||
|
Subroutine
match_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 98 | my ($re, $names) = @_; | |||||||||||||||||||||||||||
| 75 | 182 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 76 | 182 | my ($env) = @_; | |||||||||||||||||||||||||||
| 77 | 182 | ▶ | if (my @cap = ($env->{PATH_INFO} =~ /$re/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 129 | $cap[0] = {}; | |||||||||||||||||||||||||||
| 79 | 129 | ▶ | $cap[1] = do { my %c; @c{@$names} = splice @cap, 1; \%c } if $names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 129 | return @cap; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 53 | return; | |||||||||||||||||||||||||||
| 83 | }) | ||||||||||||||||||||||||||||
| 84 | 98 | } | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 12 | ▶ | sub match_path_strip { | ||||||||||||||||||||||||||
|
Subroutine
match_path_strip: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 12 | my ($re, $names) = @_; | |||||||||||||||||||||||||||
| 88 | 30 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 89 | 30 | my ($env) = @_; | |||||||||||||||||||||||||||
| 90 | 30 | ▶ | if (my @cap = ($env->{PATH_INFO} =~ /$re/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | $cap[0] = { | ||||||||||||||||||||||||||||
| 92 | 25 | ▶ | SCRIPT_NAME => ($env->{SCRIPT_NAME}||'').$cap[0], | ||||||||||||||||||||||||||
|
Condition100%2/2
$env->{'SCRIPT_NAME'} || ''
MC/DC100%1/1
$env->{'SCRIPT_NAME'} || ''
$env->{'SCRIPT_NAME'}
Truth table100%2/2
A
A= $env->{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||
| 93 | PATH_INFO => pop(@cap), | ||||||||||||||||||||||||||||
| 94 | }; | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $cap[1] = do { my %c; @c{@$names} = splice @cap, 1; \%c } if $names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 25 | return @cap; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 5 | return; | |||||||||||||||||||||||||||
| 99 | }) | ||||||||||||||||||||||||||||
| 100 | 12 | } | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 5 | ▶ | sub match_extension { | ||||||||||||||||||||||||||
|
Subroutine
match_extension: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 5 | my ($extension) = @_; | |||||||||||||||||||||||||||
| 104 | 5 | ▶ | my $wild = (!$extension or $extension eq '*'); | ||||||||||||||||||||||||||
|
Condition66%2/3
!$extension || $extension eq '*'
MC/DC50%1/2
!$extension || $extension eq '*'
!$extension
$extension eq '*'
Truth table66%2/3
not(A) || B
A= !$extensionB= $extension eq '*'
| |||||||||||||||||||||||||||||
| 105 | 5 | ▶ | my $re = $wild | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | ? qr/\.(\w+)$/ | ||||||||||||||||||||||||||||
| 107 | : qr/\.(\Q${extension}\E)$/; | ||||||||||||||||||||||||||||
| 108 | 10 | ▶ | _matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 109 | 10 | ▶ | if ($_[0]->{PATH_INFO} =~ $re) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 5 | ▶ | ($wild ? ({}, $1) : {}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 5 | (); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 5 | }); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 82 | ▶ | sub match_query { | ||||||||||||||||||||||||||
|
Subroutine
match_query: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 82 | _matcher(_param_matcher(query => $_[0])); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 6 | ▶ | sub match_body { | ||||||||||||||||||||||||||
|
Subroutine
match_body: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 6 | _matcher(_param_matcher(body => $_[0])); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | ▶ | sub match_uploads { | ||||||||||||||||||||||||||
|
Subroutine
match_uploads: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 1 | _matcher(_param_matcher(uploads => $_[0])); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 89 | ▶ | sub _param_matcher { | ||||||||||||||||||||||||||
|
Subroutine
_param_matcher: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 89 | my ($type, $spec) = @_; | |||||||||||||||||||||||||||
| 131 | # We're probably parsing a match spec while building the parser, and | ||||||||||||||||||||||||||||
| 132 | # on 5.8.8, loading ParamParser loads Encode which blows away $_ and pos. | ||||||||||||||||||||||||||||
| 133 | # Furthermore, localizing $_ doesn't restore pos afterwards. So do this | ||||||||||||||||||||||||||||
| 134 | # stupid thing instead to work on 5.8.8 | ||||||||||||||||||||||||||||
| 135 | 89 | my $saved_pos = pos; | |||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 89 | local $_; | |||||||||||||||||||||||||||
| 138 | 89 | require Web::Dispatch::ParamParser; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 89 | pos = $saved_pos; | |||||||||||||||||||||||||||
| 141 | 89 | my $unpack = Web::Dispatch::ParamParser->can("get_unpacked_${type}_from"); | |||||||||||||||||||||||||||
| 142 | 125 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 143 | 125 | _extract_params($unpack->($_[0]), $spec) | |||||||||||||||||||||||||||
| 144 | 89 | }; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 125 | ▶ | sub _extract_params { | ||||||||||||||||||||||||||
|
Subroutine
_extract_params: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||
| 148 | 125 | my ($raw, $spec) = @_; | |||||||||||||||||||||||||||
| 149 | 125 | ▶ | foreach my $name (@{$spec->{required}||[]}) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$spec->{'required'} || []
MC/DC100%1/1
$spec->{'required'} || []
$spec->{'required'}
Truth table100%2/2
A
A= $spec->{'required'}
| |||||||||||||||||||||||||||||
| 150 | 115 | ▶ | return unless exists $raw->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | my @ret = ( | ||||||||||||||||||||||||||||
| 153 | {}, | ||||||||||||||||||||||||||||
| 154 | map { | ||||||||||||||||||||||||||||
| 155 | 40 | ▶ | $_->{multi} ? $raw->{$_->{name}}||[] : $raw->{$_->{name}}->[-1] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$$raw{$_->{"name"}} or []
MC/DC100%1/1
$$raw{$_->{"name"}} or []
$$raw{$_->{"name"}}
Truth table100%2/2
A
A= $$raw{$_->{"name"}}
| |||||||||||||||||||||||||||||
| 156 | 88 | ▶ | } @{$spec->{positional}||[]} | ||||||||||||||||||||||||||
|
Condition100%2/2
$spec->{'positional'} || []
MC/DC100%1/1
$spec->{'positional'} || []
$spec->{'positional'}
Truth table100%2/2
A
A= $spec->{'positional'}
| |||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | # separated since 'or' is short circuit | ||||||||||||||||||||||||||||
| 159 | 88 | my ($named, $star) = ($spec->{named}, $spec->{star}); | |||||||||||||||||||||||||||
| 160 | 88 | ▶ | if ($named or $star) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$named or $star
MC/DC100%2/2
$named or $star
$named
$star
Truth table100%3/3
A or B
A= $namedB= $star
| |||||||||||||||||||||||||||||
| 161 | 57 | my %kw; | |||||||||||||||||||||||||||
| 162 | 57 | ▶ | if ($star) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | @kw{keys %$raw} = ( | ||||||||||||||||||||||||||||
| 164 | $star->{multi} | ||||||||||||||||||||||||||||
| 165 | 19 | ▶ | ? values %$raw | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | : map $_->[-1], values %$raw | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | 57 | ▶ | foreach my $n (@{$named||[]}) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$named || []
MC/DC100%1/1
$named || []
$named
Truth table100%2/2
A
A= $named
| |||||||||||||||||||||||||||||
| 170 | 55 | ▶ | next if !$n->{multi} and !exists $raw->{$n->{name}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n->{"multi"} or exists $$raw{$n->{"name"}}
MC/DC100%2/2
$n->{"multi"} or exists $$raw{$n->{"name"}}
$n->{"multi"}
exists $$raw{$n->{"name"}}
Truth table100%3/3
A or B
A= $n->{"multi"}B= exists $$raw{$n->{"name"}}
| |||||||||||||||||||||||||||||
| 171 | $kw{$n->{name}} = | ||||||||||||||||||||||||||||
| 172 | 51 | ▶ | $n->{multi} ? $raw->{$n->{name}}||[] : $raw->{$n->{name}}->[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$$raw{$n->{"name"}} or []
MC/DC100%1/1
$$raw{$n->{"name"}} or []
$$raw{$n->{"name"}}
Truth table100%2/2
A
A= $$raw{$n->{"name"}}
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 57 | push @ret, \%kw; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 88 | @ret; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 16 | 1; | |||||||||||||||||||||||||||