| 1 | package Web::Dispatch::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | sub DEBUG () { 0 } | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 16 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | if ($ENV{WEB_DISPATCH_PARSER_DEBUG}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | *DEBUG = sub () { 1 } | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | use Web::Dispatch::Predicates; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 16 | has _cache => ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'lazy', default => quote_sub q{ {} } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub diag { if (DEBUG) { warn $_[0] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub _wtf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wtf: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my ($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $hat = (' ' x (pos||0)).'^'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
pos $_ || 0
MC/DC0%0/1
pos $_ || 0
pos $_
Truth table0%0/2
A
A= pos $_
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | warn "Warning parsing dispatch specification: ${error}\n | |||||||||||||||||||||||||||||||||||||||||
| 26 | ${_} | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ${hat} here\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | sub _blam { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_blam: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my ($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | my $hat = (' ' x (pos||0)).'^'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
pos $_ || 0
MC/DC0%0/1
pos $_ || 0
pos $_
Truth table50%1/2
A
A= pos $_
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | die "Error parsing dispatch specification: ${error}\n | |||||||||||||||||||||||||||||||||||||||||
| 34 | ${_} | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ${hat} here\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 252 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 252 | my ($self, $spec) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 252 | $spec =~ s/\s+//g; # whitespace is not valid | |||||||||||||||||||||||||||||||||||||||||
| 41 | 252 | ▶ | return $self->_cache->{$spec} ||= $self->_parse_spec($spec); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->_cache->{$spec} ||= $self->_parse_spec($spec)
MC/DC0%0/2
$self->_cache->{$spec} ||= $self->_parse_spec($spec)
$self->_cache->{$spec}
$self->_parse_spec($spec)
Truth table66%2/3
A ||= B
A= $self->_cache->{$spec}B= $self->_parse_spec($spec)
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 146 | ▶ | sub _parse_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_spec: called CC=13 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 146 | my ($self, $spec, $nested) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 146 | ▶ | return match_true() unless length($spec); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 143 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 48 | 143 | my @match; | |||||||||||||||||||||||||||||||||||||||||
| 49 | my $close; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 143 | ▶ | PARSE: { do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 212 | ▶ | push @match, $self->_parse_spec_section($_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | or $self->_blam("Unable to work out what the next section is"); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 211 | ▶ | if (/\G\)/gc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | $self->_blam("Found closing ) with no opening (") unless $nested; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | $close = 1; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | last PARSE; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 208 | ▶ | last PARSE if (pos == length); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 73 | ▶ | $match[-1] = $self->_parse_spec_combinator($_, $match[-1]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | or $self->_blam('No valid combinator - expected + or |'); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } until (pos == length) }; # accept trailing whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 142 | ▶ | if (!$close and $nested and pos == length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $close and $nested and pos $_ == length $_
not $close and $nested
MC/DC66%2/3
not $close and $nested and pos $_ == length $_
not $close
$nested
pos $_ == length $_
Truth table75%3/4
not(A) and B and C
A= not $closeB= $nestedC= pos $_ == length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | pos = $nested - 1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $self->_blam("No closing ) found for opening ("); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 141 | ▶ | return $match[0] if (@match == 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 67 | return match_and(@match); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 73 | ▶ | sub _parse_spec_combinator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_spec_combinator: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 73 | my ($self, $spec, $match) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 73 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 73 | ▶ | /\G\+/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | return $match; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | /\G\|/gc and | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | return do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | my @match = $match; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | ▶ | PARSE: { do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | push @match, $self->_parse_spec_section($_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | or $self->_blam("Unable to work out what the next section is"); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | last PARSE if (pos == length); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | last PARSE unless /\G\|/gc; # give up when next thing isn't | | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } until (pos == length) }; # accept trailing whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | return match_or(@match); | |||||||||||||||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 218 | ▶ | sub _parse_spec_section { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_spec_section: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 218 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 218 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # ~ | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 218 | ▶ | /\G~/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | return match_path('^$'); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # GET POST PUT HEAD ... | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 216 | ▶ | /\G([A-Z]+)/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | return match_method($1); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # /... | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 191 | ▶ | /\G(?=\/)/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | return $self->_url_path_match($_); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # .* and .html | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 97 | ▶ | /\G\.(\*|\w+)/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | return match_extension($1); | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # (...) | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 92 | ▶ | /\G\(/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | return $self->_parse_spec($_, pos); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # !something | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 88 | ▶ | /\G!/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | return match_not($self->_parse_spec_section($_)); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # ?<param spec> | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 87 | ▶ | /\G\?/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | return $self->_parse_param_handler($_, 'query'); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | # %<param spec> | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | /\G\%/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | return $self->_parse_param_handler($_, 'body'); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # *<param spec> | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | /\G\*/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | return $self->_parse_param_handler($_, 'uploads'); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return; # () will trigger the blam in our caller | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 94 | ▶ | sub _url_path_match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_url_path_match: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 94 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 94 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 94 | my (@path, @names, $seen_nameless); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 94 | my $end = ''; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 94 | my $keep_dot; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 94 | ▶ | PATH: while (/\G\//gc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | /\G\.\.\./gc | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 192 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | $end = '(/.*)'; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | last PATH; | |||||||||||||||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 188 | ▶ | my ($segment) = $self->_url_path_segment_match($_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | or $self->_blam("Couldn't parse path match segment"); | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 188 | ▶ | if (ref($segment)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 17 | ($segment, $keep_dot, my $name) = @$segment; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | ▶ | if (defined($name)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | $self->_blam("Can't mix positional and named captures in path match") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | if $seen_nameless; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 6 | push @names, $name; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 11 | ▶ | $self->_blam("Can't mix positional and named captures in path match") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | if @names; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | $seen_nameless = 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 188 | push @path, $segment; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | /\G\.\.\./gc | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 188 | ▶ | and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | $end = '(|/.*)'; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | last PATH; | |||||||||||||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 184 | ▶ | /\G\.\*/gc | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | and $keep_dot = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 184 | ▶ | last PATH if $keep_dot; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 94 | ▶ | if (@path && !$end && !$keep_dot) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@path and not $end and not $keep_dot
@path and not $end
MC/DC100%3/3
@path and not $end and not $keep_dot
@path
not $end
not $keep_dot
Truth table100%4/4
A and not(B) and not(C)
A= @pathB= not $endC= not $keep_dot
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 83 | ▶ | length and $_ .= '(?:\.\w+)?' for $path[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 94 | my $re = '^('.join('/','',@path).')'.$end.'$'; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 94 | $re = qr/$re/; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 94 | ▶ | if ($end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | return match_path_strip($re, @names ? \@names : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 86 | ▶ | return match_path($re, @names ? \@names : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 188 | ▶ | sub _url_path_segment_match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_url_path_segment_match: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 188 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 188 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 199 | # trailing / -> require / on end of URL | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 188 | ▶ | /\G(?:(?=[+|\)])|$)/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | return ''; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # word chars only -> exact path part match | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 158 | ▶ | / | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | \G( | ||||||||||||||||||||||||||||||||||||||||||
| 205 | (?: # start matching at a space followed by: | ||||||||||||||||||||||||||||||||||||||||||
| 206 | [\w\-] # word chars or dashes | ||||||||||||||||||||||||||||||||||||||||||
| 207 | | # OR | ||||||||||||||||||||||||||||||||||||||||||
| 208 | \. # a period | ||||||||||||||||||||||||||||||||||||||||||
| 209 | (?!\.) # not followed by another period | ||||||||||||||||||||||||||||||||||||||||||
| 210 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 211 | + # then grab as far as possible | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | /gcx and | ||||||||||||||||||||||||||||||||||||||||||
| 214 | return "\Q$1"; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # ** -> capture unlimited path parts | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 17 | ▶ | /\G\*\*(?:(\.\*)?\:(\w+))?/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | return [ '(.*?[^/])', $1, $2 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # * -> capture path part | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # *:name -> capture named path part | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 12 | ▶ | /\G\*(?:(\.\*)?\:(\w+))?/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | return [ '([^/]+?)', $1, $2 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # :name -> capture named path part | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | /\G\:(\w+)/gc and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | return [ '([^/]+?)', 0, $1 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 87 | ▶ | sub _parse_param_handler { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_param_handler: called CC=12 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 87 | my ($self, $spec, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 87 | for ($_[1]) { | |||||||||||||||||||||||||||||||||||||||||
| 234 | 87 | my (@required, @single, %multi, $star, $multistar, %positional, $have_kw); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 87 | my %spec; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 87 | my $pos_idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 87 | ▶ | PARAM: { do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # ?:foo or ?@:foo | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 110 | my $is_kw = /\G\:/gc; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # ?@foo or ?@* | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 110 | my $multi = /\G\@/gc; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | # @* or * | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 110 | ▶ | if (/\G\*/gc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 17 | ▶ | $self->_blam("* is always named; no need to supply :") if $is_kw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 17 | ▶ | if ($star) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $self->_blam("Can only use one * or \@* in a parameter match"); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 17 | $spec{star} = { multi => $multi }; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # @foo= or foo= or @foo~ or foo~ | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 93 | ▶ | /\G([\w.]*)/gc or $self->_blam('Expected parameter name'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 93 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # check for = or ~ on the end | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | /\G\=/gc | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 93 | ▶ | ? push(@{$spec{required}||=[]}, $name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$spec{"required"} ||= []
/\G\~/cg or $self->_blam("Expected = or ~ after parameter name")
MC/DC100%1/1
$spec{"required"} ||= []
$spec{"required"}
MC/DC0%0/2
/\G\~/cg or $self->_blam("Expected = or ~ after parameter name")
/\G\~/cg
$self->_blam("Expected = or ~ after parameter name")
Truth table100%2/2
A
A= $spec{"required"}
Truth table33%1/3
A or B
A= /\G\~/cgB= $self->_blam("Expected = or ~ after parameter name")
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | : (/\G\~/gc or $self->_blam('Expected = or ~ after parameter name')); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # record positional or keyword | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 93 | ▶ | push @{$spec{$is_kw ? 'named' : 'positional'}||=[]}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$spec{$is_kw ? "named" : "positional"} ||= []
MC/DC100%1/1
$spec{$is_kw ? "named" : "positional"} ||= []
$spec{$is_kw ? "named" : "positional"}
Truth table100%2/2
A
A= $spec{$is_kw ? "named" : "positional"}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | { name => $name, multi => $multi }; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } while (/\G\&/gc) } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 87 | return Web::Dispatch::Predicates->can("match_${type}")->(\%spec); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||