| 1 | package Magpie::Matcher; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | #ABSTRACT: Multi-purpose Dispatcher Magic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 43 | $Magpie::Matcher::VERSION = '1.163200'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 43 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 43 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 43 | ▶ | use HTTP::Negotiate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 43 | ▶ | use Data::Printer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 43 | has plack_request => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | isa => 'Plack::Request', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | trigger => \&choose_variant, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | has match_candidates => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => 'ArrayRef[ArrayRef]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 43 | handles => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | add_candidates => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 43 | has evaluation_map => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => 'HashRef[ArrayRef]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | has_candidate => 'exists', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | get_candidate => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 114 | ▶ | sub _build_evaluation_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_evaluation_map: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 114 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 114 | my $candidates = $self->match_candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 114 | my $evaled = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 114 | my @submatches = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 114 | my @to_skip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # first, eval the frames to see what matches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 114 | foreach my $frame (@{$candidates}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 440 | my @components = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 440 | my $machine_token = $frame->[3], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | my $match_token = $frame->[4]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 440 | ▶ | $evaled->{$machine_token} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$evaled->{$machine_token} ||= []
MC/DC100%1/1
$evaled->{$machine_token} ||= []
$evaled->{$machine_token}
Truth table100%2/2
A
A= $evaled->{$machine_token}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 440 | my $added = $self->eval_match($frame); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 440 | ▶ | if (scalar @{$added} > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 150 | my @subs_here = grep {/__MATCH__/} @{$added}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 150 | push @submatches, @subs_here; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 150 | push @{$evaled->{$machine_token}}, [$match_token, $added]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 290 | my @subs_here = grep {/__MATCH__/} @{$frame->[2]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 290 | push @to_skip, @subs_here; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # now that we know what matches, flatten the pipelines by resolving the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # match tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 114 | my $out = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 114 | foreach my $machine (keys( %{$evaled} )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 70 | $out->{$machine} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 70 | foreach my $slot (@{$evaled->{$machine}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 150 | ▶ | next if scalar grep { $_ eq $slot->[0] } (@submatches, @to_skip); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 80 | my $components = resolve($evaled->{$machine}, $slot->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 80 | foreach my $component (@{$components}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 275 | ▶ | if ($component eq '__RESET__') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | $out->{$machine} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 273 | push @{$out->{$machine}}, $component; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | #push @{$out->{$machine}}, @{$components}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 114 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | has accept_matrix => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | isa => 'ArrayRef[ArrayRef]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 43 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 43 | has accept_variant => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | isa => 'Str|Undef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | #lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 114 | ▶ | sub choose_variant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choose_variant: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 114 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 114 | my $plack_request = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 114 | my $accept_matrix = $self->accept_matrix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 114 | ▶ | if ($accept_matrix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 114 | my $variant = HTTP::Negotiate::choose($accept_matrix, $plack_request->headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 114 | $self->accept_variant($variant); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _build_accept_variant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_accept_variant: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $ret = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $accept_matrix = $self->accept_matrix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($accept_matrix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $ret = HTTP::Negotiate::choose($accept_matrix, $self->plack_request->headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 144 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 144 | my $machine = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 144 | my $component_list = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 144 | ▶ | my $stack = shift || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 144 | foreach my $component (@{$component_list}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 339 | ▶ | if ($component =~ /__MATCH__/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 64 | my @new_list = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 64 | foreach my $thing (@{$machine}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 232 | ▶ | if ($thing->[0] eq $component) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 28 | push @new_list, @{$thing->[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 64 | my $resolved = resolve($machine, \@new_list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 64 | ▶ | push @{$stack}, @{$resolved} if $resolved; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 275 | push @{$stack}, $component; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 144 | return $stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 440 | ▶ | sub eval_match { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eval_match: called CC=23 SCAR=33.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 440 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 440 | my $frame = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 440 | my $req = $self->plack_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 440 | my $env = $req->env; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 440 | my $path = $req->path_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 440 | my $accept_variant = $self->accept_variant; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 440 | my @out = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 440 | my $match_type = $frame->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 440 | ▶ | if ($match_type eq 'STRING') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | ▶ | push @out, @{$frame->[2]} if $frame->[1] eq $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ▶ | elsif ($match_type eq 'REGEXP' || ($match_type eq 'SCALAR' && re::is_regexp($frame->[0]) == 1 )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$match_type eq "REGEXP" or $match_type eq "SCALAR" and &re::is_regexp($frame->[0]) == 1
$match_type eq "SCALAR" and &re::is_regexp($frame->[0]) == 1
MC/DC33%1/3
$match_type eq "REGEXP" or $match_type eq "SCALAR" and &re::is_regexp($frame->[0]) == 1
$match_type eq "REGEXP"
$match_type eq "SCALAR"
&re::is_regexp($frame->[0]) == 1
Truth table50%2/4
A or B and C
A= $match_type eq "REGEXP"B= $match_type eq "SCALAR"C= &re::is_regexp($frame->[0]) == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 272 | ▶ | push @out, @{$frame->[2]} if $path =~ /$frame->[1]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | elsif ($match_type eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $temp = $frame->[1]->($env); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | push @out, @{$temp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | elsif ($match_type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 86 | my $rules = $frame->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 86 | my $matched = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 86 | foreach my $k (keys %{$rules} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 86 | ▶ | last unless defined $env->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 48 | my $val = $rules->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 48 | my $val_type = reftype $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 48 | ▶ | if ($val_type && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$val_type and $val_type eq "REGEXP" || $val_type eq "SCALAR" && &re::is_regexp($val) == 1
$val_type eq "REGEXP" or $val_type eq "SCALAR" and &re::is_regexp($val) == 1
$val_type eq "SCALAR" and &re::is_regexp($val) == 1
MC/DC25%1/4
$val_type and $val_type eq "REGEXP" || $val_type eq "SCALAR" && &re::is_regexp($val) == 1
$val_type
$val_type eq "REGEXP"
$val_type eq "SCALAR"
&re::is_regexp($val) == 1
Truth table40%2/5
A and B or C and D
A= $val_typeB= $val_type eq "REGEXP"C= $val_type eq "SCALAR"D= &re::is_regexp($val) == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ( $val_type eq 'REGEXP' || ($val_type eq 'SCALAR' && re::is_regexp($val) == 1 )) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 30 | ▶ | $matched++ if $env->{$k} =~ m/$val/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 18 | ▶ | $matched++ if qq($env->{$k}) eq qq($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 86 | ▶ | push @out, @{$frame->[2]} if $matched == scalar keys %{$rules}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif ($match_type eq 'AUTO') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | push @out, @{$frame->[2]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | elsif ($match_type eq 'ACCEPT') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 64 | ▶ | push @out, @{$frame->[2]} if length $accept_variant && $frame->[1] eq $accept_variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $accept_variant and $frame->[1] eq $accept_variant
MC/DC100%2/2
length $accept_variant and $frame->[1] eq $accept_variant
length $accept_variant
$frame->[1] eq $accept_variant
Truth table100%3/3
A and B
A= length $accept_variantB= $frame->[1] eq $accept_variant
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif ($match_type eq 'RESET') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | push @out, '__RESET__'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | warn"I don't know how to match '$match_type', skipping.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 440 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub machine_token_lookup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
machine_token_lookup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return shift->token_lookup(@_, 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub match_token_lookup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_token_lookup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return shift->token_lookup(@_, 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub token_lookup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
token_lookup: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $token = shift || '__default__'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || '__default__'
MC/DC0%0/1
shift() || '__default__'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $index = shift || 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 4
MC/DC0%0/1
shift() || 4
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $candidates = $self->match_candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $ret = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | foreach my $frame (@{$candidates}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($frame->[$index] eq $token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | push @{$ret}, $frame; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 114 | ▶ | sub construct_pipeline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
construct_pipeline: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 114 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 114 | my $tokenized = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 114 | ▶ | unless ($tokenized) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $tokenized = ['__default__']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 114 | my @new = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 114 | my $map = $self->evaluation_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 114 | my @tokens = keys( %{$map} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 114 | foreach my $step ( @{$tokenized} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 200 | ▶ | if ( grep { $_ eq $step } @tokens ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 70 | push @new, @{$map->{$step}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 130 | push @new, $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 114 | return \@new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | #SEEALSO: Magpie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 43 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||