| 1 | package Catalyst::Action; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Catalyst::Action - Catalyst Action | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | <form action="[%c.uri_for(c.action)%]"> | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | $c->forward( $action->private_path ); | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | This class represents a Catalyst Action. You can access the object for the | ||||||||||||||||||||||||||||||||||||||||||
| 16 | currently dispatched action via $c->action. See the L<Catalyst::Dispatcher> | ||||||||||||||||||||||||||||||||||||||||||
| 17 | for more information on how actions are dispatched. Actions are defined in | ||||||||||||||||||||||||||||||||||||||||||
| 18 | L<Catalyst::Controller> subclasses. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 155 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 155 | ▶ | use Scalar::Util 'looks_like_number', 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 155 | ▶ | use Moose::Util::TypeConstraints (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 155 | with 'MooseX::Emulate::Class::Accessor::Fast'; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 155 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 155 | has class => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 155 | has instance => (is=>'ro', required=>0, predicate=>'has_instance'); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 155 | has namespace => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 155 | has 'reverse' => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 155 | has attributes => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 155 | has name => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 155 | has code => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 35 | has private_path => ( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | reader => 'private_path', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | default => sub { '/'.shift->reverse }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 155 | ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 155 | has number_of_args => ( | |||||||||||||||||||||||||||||||||||||||||
| 44 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa=>'Int|Undef', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | builder=>'_build_number_of_args'); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1327 | ▶ | sub _build_number_of_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_number_of_args: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1327 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1327 | ▶ | if( ! exists $self->attributes->{Args} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | # When 'Args' does not exist, that means we want 'any number of args'. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 859 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } elsif(!defined($self->attributes->{Args}[0])) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # When its 'Args' that internal cue for 'unlimited' | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 59 | ▶ | } elsif( | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
scalar @{$self->attributes->{"Args"};} == 1 and &looks_like_number($self->attributes->{"Args"}[0])
MC/DC50%1/2
scalar @{$self->attributes->{"Args"};} == 1 and &looks_like_number($self->attributes->{"Args"}[0])
scalar @{$self->attributes->{"Args"};} == 1
&looks_like_number($self->attributes->{"Args"}[0])
Truth table66%2/3
A and B
A= scalar @{$self->attributes->{"Args"};} == 1B= &looks_like_number($self->attributes->{"Args"}[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 452 | scalar(@{$self->attributes->{Args}}) == 1 && | |||||||||||||||||||||||||||||||||||||||||
| 61 | looks_like_number($self->attributes->{Args}[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # 'Old school' numbered args (is allowed to be undef as well) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 426 | return $self->attributes->{Args}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # New hotness named arg constraints | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 26 | return $self->number_of_args_constraints; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 56 | ▶ | sub normalized_arg_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalized_arg_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 56 | return $_[0]->number_of_args; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 6447 | ▶ | sub comparable_arg_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comparable_arg_number: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6447 | ▶ | return defined($_[0]->number_of_args) ? $_[0]->number_of_args : ~0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 155 | has number_of_args_constraints => ( | |||||||||||||||||||||||||||||||||||||||||
| 80 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | isa=>'Int|Undef', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | builder=>'_build_number_of_args_constraints'); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 26 | ▶ | sub _build_number_of_args_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_number_of_args_constraints: called CC=15 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 26 | ▶ | return unless $self->has_args_constraints; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # If there is one constraint and its a ref, we need to decide | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # if this number 'unknown' number or if the ref allows us to | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # determine a length. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 26 | ▶ | if(scalar @{$self->args_constraints} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 24 | my $tc = $self->args_constraints->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
MC/DC100%2/2
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
$tc->can("is_strictly_a_type_of")
$tc->is_strictly_a_type_of("Tuple")
Truth table100%3/3
A and B
A= $tc->can("is_strictly_a_type_of")B= $tc->is_strictly_a_type_of("Tuple")
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | $tc->can('is_strictly_a_type_of') && | ||||||||||||||||||||||||||||||||||||||||||
| 99 | $tc->is_strictly_a_type_of('Tuple')) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my @parameters = @{ $tc->parameters||[] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tc->parameters || []
MC/DC0%0/1
$tc->parameters || []
$tc->parameters
Truth table50%1/2
A
A= $tc->parameters
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $final = $parameters[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if ( defined $final ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ( blessed $final ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | # modern form of slurpy | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | if ($final->can('is_strictly_a_type_of') && $final->is_strictly_a_type_of('Slurpy')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$final->can("is_strictly_a_type_of") and $final->is_strictly_a_type_of("Slurpy")
MC/DC50%1/2
$final->can("is_strictly_a_type_of") and $final->is_strictly_a_type_of("Slurpy")
$final->can("is_strictly_a_type_of")
$final->is_strictly_a_type_of("Slurpy")
Truth table66%2/3
A and B
A= $final->can("is_strictly_a_type_of")B= $final->is_strictly_a_type_of("Slurpy")
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # old form of slurpy | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if (ref $final eq 'HASH' && $final->{slurpy}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $final eq "HASH" and $final->{"slurpy"}
MC/DC0%0/2
ref $final eq "HASH" and $final->{"slurpy"}
ref $final eq "HASH"
$final->{"slurpy"}
Truth table0%0/3
A and B
A= ref $final eq "HASH"B= $final->{"slurpy"}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return scalar @parameters; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } elsif($tc->is_a_type_of('Ref')) { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 21 | return 1; # Its a normal 1 arg type constraint. | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # We need to loop through and error on ref types. We don't allow a ref type | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # in the middle. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | foreach my $tc( @{$self->args_constraints}) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | ▶ | if($tc->is_a_type_of('Ref')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | die "$tc is a Ref type constraint. You cannot mix Ref and non Ref type constraints in Args for action ${\$self->reverse}"; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | ++$total; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | return $total; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 155 | has args_constraints => ( | |||||||||||||||||||||||||||||||||||||||||
| 139 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | traits=>['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 142 | isa=>'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | builder=>'_build_args_constraints', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | has_args_constraints => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 148 | args_constraint_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | all_args_constraints => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 575 | ▶ | sub _build_args_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_args_constraints: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 575 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 575 | ▶ | my @arg_protos = @{$self->attributes->{Args}||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->attributes->{'Args'} || []
MC/DC100%1/1
$self->attributes->{'Args'} || []
$self->attributes->{'Args'}
Truth table100%2/2
A
A= $self->attributes->{'Args'}
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 575 | ▶ | return [] unless scalar(@arg_protos); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 260 | ▶ | return [] unless defined($arg_protos[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | # If there is only one arg and it looks like a number | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # we assume its 'classic' and the number is the number of | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # constraints. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 244 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 244 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
MC/DC50%1/2
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
scalar @arg_protos == 1
&looks_like_number($arg_protos[0])
Truth table66%2/3
A and B
A= scalar @arg_protos == 1B= &looks_like_number($arg_protos[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | scalar(@arg_protos) == 1 && | ||||||||||||||||||||||||||||||||||||||||||
| 165 | looks_like_number($arg_protos[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 218 | return \@args; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | @args = | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 26 | ▶ | map { my @tc = $self->resolve_type_constraint($_); scalar(@tc) ? @tc : die "$_ is not a constraint!" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | @arg_protos; | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 26 | return \@args; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 155 | has number_of_captures_constraints => ( | |||||||||||||||||||||||||||||||||||||||||
| 177 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 178 | isa=>'Int|Undef', | ||||||||||||||||||||||||||||||||||||||||||
| 179 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | builder=>'_build_number_of_capture_constraints'); | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | ▶ | sub _build_number_of_capture_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_number_of_capture_constraints: called CC=11 SCAR=26.3
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | ▶ | return unless $self->has_captures_constraints; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # If there is one constraint and its a ref, we need to decide | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # if this number 'unknown' number or if the ref allows us to | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # determine a length. | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | if(scalar @{$self->captures_constraints} == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | my $tc = $self->captures_constraints->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
MC/DC100%2/2
$tc->can("is_strictly_a_type_of") and $tc->is_strictly_a_type_of("Tuple")
$tc->can("is_strictly_a_type_of")
$tc->is_strictly_a_type_of("Tuple")
Truth table100%3/3
A and B
A= $tc->can("is_strictly_a_type_of")B= $tc->is_strictly_a_type_of("Tuple")
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | $tc->can('is_strictly_a_type_of') && | ||||||||||||||||||||||||||||||||||||||||||
| 196 | $tc->is_strictly_a_type_of('Tuple')) | ||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | my @parameters = @{ $tc->parameters||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tc->parameters || []
MC/DC0%0/1
$tc->parameters || []
$tc->parameters
Truth table50%1/2
A
A= $tc->parameters
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | if( defined($parameters[-1]) and exists($parameters[-1]->{slurpy})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $parameters[-1] and exists $parameters[-1]{"slurpy"}
MC/DC0%0/2
defined $parameters[-1] and exists $parameters[-1]{"slurpy"}
defined $parameters[-1]
exists $parameters[-1]{"slurpy"}
Truth table33%1/3
A and B
A= defined $parameters[-1]B= exists $parameters[-1]{"slurpy"}
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | return my $total_params = scalar(@parameters); | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } elsif($tc->is_a_type_of('Ref')) { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | die "You cannot use CaptureArgs($tc) in ${\$self->reverse} because we cannot determined the number of its parameters"; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | return 1; # Its a normal 1 arg type constraint. | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # We need to loop through and error on ref types. We don't allow a ref type | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # in the middle. | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | my $total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | foreach my $tc( @{$self->captures_constraints}) { | |||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | if($tc->is_a_type_of('Ref')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | die "$tc is a Ref type constraint. You cannot mix Ref and non Ref type constraints in CaptureArgs for action ${\$self->reverse}"; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | ++$total; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return $total; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 155 | has captures_constraints => ( | |||||||||||||||||||||||||||||||||||||||||
| 225 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 226 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | traits=>['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 228 | isa=>'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||
| 229 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | builder=>'_build_captures_constraints', | ||||||||||||||||||||||||||||||||||||||||||
| 232 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | has_captures_constraints => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 234 | captures_constraints_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 235 | all_captures_constraints => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 236 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 83 | ▶ | sub _build_captures_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_captures_constraints: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 83 | ▶ | my @arg_protos = @{$self->attributes->{CaptureArgs}||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->attributes->{'CaptureArgs'} || []
MC/DC100%1/1
$self->attributes->{'CaptureArgs'} || []
$self->attributes->{'CaptureArgs'}
Truth table100%2/2
A
A= $self->attributes->{'CaptureArgs'}
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 83 | ▶ | return [] unless scalar(@arg_protos); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 68 | ▶ | return [] unless defined($arg_protos[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | # If there is only one arg and it looks like a number | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # we assume its 'classic' and the number is the number of | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # constraints. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 68 | my @args = (); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 68 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
MC/DC50%1/2
scalar @arg_protos == 1 and &looks_like_number($arg_protos[0])
scalar @arg_protos == 1
&looks_like_number($arg_protos[0])
Truth table66%2/3
A and B
A= scalar @arg_protos == 1B= &looks_like_number($arg_protos[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | scalar(@arg_protos) == 1 && | ||||||||||||||||||||||||||||||||||||||||||
| 250 | looks_like_number($arg_protos[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 62 | return \@args; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | @args = | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | ▶ | map { my @tc = $self->resolve_type_constraint($_); scalar(@tc) ? @tc : die "$_ is not a constraint!" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | @arg_protos; | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 6 | return \@args; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 32 | ▶ | sub resolve_type_constraint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_type_constraint: called CC=19 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 32 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 32 | ▶ | if(defined($name) && blessed($name) && $name->can('check')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $name and builtin::blessed($name) and $name->can("check")
defined $name and builtin::blessed($name)
MC/DC0%0/3
defined $name and builtin::blessed($name) and $name->can("check")
defined $name
builtin::blessed($name)
$name->can("check")
Truth table25%1/4
A and B and C
A= defined $nameB= builtin::blessed($name)C= $name->can("check")
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Its already a TC, good to go. | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # This is broken for when there is more than one constraint | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 32 | ▶ | if($name=~m/::/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | eval "use Type::Registry; 1" || die "Can't resolve type constraint $name without installing Type::Tiny"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | my $tc = Type::Registry->new->foreign_lookup($name); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return defined $tc ? $tc : die "'$name' not a full namespace type constraint in ${\$self->private_path}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 31 | my @tc = grep { defined $_ } (eval("package ${\$self->class}; $name")); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 31 | ▶ | unless(scalar @tc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | # ok... so its not defined in the package. we need to look at all the roles | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # and superclasses, look for attributes and figure it out. | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # Superclasses take precedence; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | my @supers = $self->class->can('meta') ? map { $_->meta } $self->class->meta->superclasses : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | ▶ | my @roles = $self->class->can('meta') ? $self->class->meta->calculate_all_roles : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # So look through all the super and roles in order and return the | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # first type constraint found. We should probably find all matching | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # type constraints and try to do some sort of resolution. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | foreach my $parent (@roles, @supers) { | |||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | ▶ | if(my $m = $parent->get_method($self->name)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | ▶ | if($m->can('attributes')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 2 | my ($key, $value) = map { $_ =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/ } | |||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | ▶ | grep { $_=~/^Args\(/ or $_=~/^CaptureArgs\(/ } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_ =~ /^Args\(/ || $_ =~ /^CaptureArgs\(/
MC/DC50%1/2
$_ =~ /^Args\(/ || $_ =~ /^CaptureArgs\(/
$_ =~ /^Args\(/
$_ =~ /^CaptureArgs\(/
Truth table66%2/3
A || B
A= $_ =~ /^Args\(/B= $_ =~ /^CaptureArgs\(/
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | @{$m->attributes}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | next unless $value eq $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | my @tc = eval "package ${\$parent->name}; $name"; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | ▶ | if(scalar(@tc)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | return map { ref($_) ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @tc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $classes = join(',', $self->class, @roles, @supers); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | die "'$name' not a type constraint in '${\$self->private_path}', Looked in: $classes"; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 29 | ▶ | if(scalar(@tc)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 29 | ▶ | return map { ref($_) ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @tc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 155 | has number_of_captures => ( | |||||||||||||||||||||||||||||||||||||||||
| 320 | is=>'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 321 | init_arg=>undef, | ||||||||||||||||||||||||||||||||||||||||||
| 322 | isa=>'Int', | ||||||||||||||||||||||||||||||||||||||||||
| 323 | required=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | lazy=>1, | ||||||||||||||||||||||||||||||||||||||||||
| 325 | builder=>'_build_number_of_captures'); | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 148 | ▶ | sub _build_number_of_captures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_number_of_captures: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 148 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 148 | ▶ | if( ! exists $self->attributes->{CaptureArgs} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | # If there are no defined capture args, thats considered 0. | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 30 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } elsif(!defined($self->attributes->{CaptureArgs}[0])) { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # If you fail to give a defined value, that's also 0 | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 335 | ▶ | } elsif( | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
scalar @{$self->attributes->{"CaptureArgs"};} == 1 and &looks_like_number($self->attributes->{"CaptureArgs"}[0])
MC/DC50%1/2
scalar @{$self->attributes->{"CaptureArgs"};} == 1 and &looks_like_number($self->attributes->{"CaptureArgs"}[0])
scalar @{$self->attributes->{"CaptureArgs"};} == 1
&looks_like_number($self->attributes->{"CaptureArgs"}[0])
Truth table66%2/3
A and B
A= scalar @{$self->attributes->{"CaptureArgs"};} == 1B= &looks_like_number($self->attributes->{"CaptureArgs"}[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 118 | scalar(@{$self->attributes->{CaptureArgs}}) == 1 && | |||||||||||||||||||||||||||||||||||||||||
| 337 | looks_like_number($self->attributes->{CaptureArgs}[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 339 | # 'Old school' numbered captures | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 112 | return $self->attributes->{CaptureArgs}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # New hotness named arg constraints | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | return $self->number_of_captures_constraints; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 155 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # Stringify to reverse for debug output etc. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 35588 | ▶ | q{""} => sub { shift->{reverse} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Codulate to execute to invoke the encapsulated action coderef | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | # Make general $stuff still work | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 155 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 155 | ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 155 | ▶ | no warnings 'recursion'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 9194 | ▶ | sub dispatch { # Execute ourselves against a context | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 9194 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 9194 | ▶ | if($self->has_instance) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | return $c->execute( $self->instance, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 367 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 9192 | return $c->execute( $self->class, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 9194 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 9194 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 9194 | $self->code->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 1562 | ▶ | sub match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 1562 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 1562 | return $self->match_args($c, $c->req->args); | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1572 | ▶ | sub match_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_args: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 1572 | my ($self, $c, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 1572 | ▶ | my @args = @{$args||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args || []
MC/DC0%0/1
$args || []
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | # There there are arg constraints, we must see to it that the constraints | ||||||||||||||||||||||||||||||||||||||||||
| 387 | # check positive for each arg in the list. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 1572 | ▶ | if($self->has_args_constraints) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | # If there is only one type constraint, and its a Ref or subtype of Ref, | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # That means we expect a reference, so use the full args arrayref. | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 89 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->args_constraint_count == 1 and $self->args_constraints->[0]->is_a_type_of("Ref") || $self->args_constraints->[0]->is_a_type_of("ClassName")
$self->args_constraints->[0]->is_a_type_of("Ref") or $self->args_constraints->[0]->is_a_type_of("ClassName")
MC/DC66%2/3
$self->args_constraint_count == 1 and $self->args_constraints->[0]->is_a_type_of("Ref") || $self->args_constraints->[0]->is_a_type_of("ClassName")
$self->args_constraint_count == 1
$self->args_constraints->[0]->is_a_type_of("Ref")
$self->args_constraints->[0]->is_a_type_of("ClassName")
Truth table75%3/4
A and B or C
A= $self->args_constraint_count == 1B= $self->args_constraints->[0]->is_a_type_of("Ref")C= $self->args_constraints->[0]->is_a_type_of("ClassName")
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | $self->args_constraint_count == 1 && | ||||||||||||||||||||||||||||||||||||||||||
| 393 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 394 | $self->args_constraints->[0]->is_a_type_of('Ref') || | ||||||||||||||||||||||||||||||||||||||||||
| 395 | $self->args_constraints->[0]->is_a_type_of('ClassName') | ||||||||||||||||||||||||||||||||||||||||||
| 396 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 397 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # Ok, the the type constraint is a ref type, which is allowed to have | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # any number of args. We need to check the arg length, if one is defined. | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # If we had a ref type constraint that allowed us to determine the allowed | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # number of args, we need to match that number. Otherwise if there was an | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # undetermined number (~0) then we allow all the args. This is more of an | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # Optimization since Tuple[Int, Int] would fail on 3,4,5 anyway, but this | ||||||||||||||||||||||||||||||||||||||||||
| 404 | # way we can avoid calling the constraint when the arg length is incorrect. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 8 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->comparable_arg_number == '18446744073709551615' or scalar @args == $self->comparable_arg_number
MC/DC100%2/2
$self->comparable_arg_number == '18446744073709551615' or scalar @args == $self->comparable_arg_number
$self->comparable_arg_number == '18446744073709551615'
scalar @args == $self->comparable_arg_number
Truth table100%3/3
A or B
A= $self->comparable_arg_number == '18446744073709551615'B= scalar @args == $self->comparable_arg_number
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | $self->comparable_arg_number == ~0 || | ||||||||||||||||||||||||||||||||||||||||||
| 407 | scalar( @args ) == $self->comparable_arg_number | ||||||||||||||||||||||||||||||||||||||||||
| 408 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 7 | return $self->args_constraints->[0]->check($args); | |||||||||||||||||||||||||||||||||||||||||
| 410 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # Removing coercion stuff for the first go | ||||||||||||||||||||||||||||||||||||||||||
| 414 | #if($self->args_constraints->[0]->coercion && $self->attributes->{Coerce}) { | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # my $coerced = $self->args_constraints->[0]->coerce($c) || return 0; | ||||||||||||||||||||||||||||||||||||||||||
| 416 | # $c->req->args([$coerced]); | ||||||||||||||||||||||||||||||||||||||||||
| 417 | # return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 418 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 419 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # Because of the way chaining works, we can expect args that are totally not | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # what you'd expect length wise. When they don't match length, thats a fail | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 81 | ▶ | return 0 unless scalar( @args ) == $self->comparable_arg_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 44 | for my $i(0..$#args) { | |||||||||||||||||||||||||||||||||||||||||
| 425 | 47 | ▶ | $self->args_constraints->[$i]->check($args[$i]) || return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 27 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # If infinite args with no constraints, we always match | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 1483 | ▶ | return 1 if $self->comparable_arg_number == ~0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | # Otherwise, we just need to match the number of args. | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 839 | return scalar( @args ) == $self->comparable_arg_number; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 672 | ▶ | sub match_captures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_captures: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 672 | my ($self, $c, $captures) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 672 | ▶ | my @captures = @{$captures||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$captures || []
MC/DC0%0/1
$captures || []
$captures
Truth table50%1/2
A
A= $captures
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 672 | ▶ | return 1 unless scalar(@captures); # If none, just say its ok | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 462 | ▶ | return $self->has_captures_constraints ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | $self->match_captures_constraints($c, $captures) : 1; | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 51 | ▶ | sub match_captures_constraints { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_captures_constraints: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 51 | my ($self, $c, $captures) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 51 | ▶ | my @captures = @{$captures||[]}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$captures || []
MC/DC0%0/1
$captures || []
$captures
Truth table50%1/2
A
A= $captures
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | # Match is positive if you don't have any. | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 51 | ▶ | return 1 unless $self->has_captures_constraints; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 51 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->captures_constraints_count == 1 and $self->captures_constraints->[0]->is_a_type_of("Ref") || $self->captures_constraints->[0]->is_a_type_of("ClassName")
$self->captures_constraints->[0]->is_a_type_of("Ref") or $self->captures_constraints->[0]->is_a_type_of("ClassName")
MC/DC66%2/3
$self->captures_constraints_count == 1 and $self->captures_constraints->[0]->is_a_type_of("Ref") || $self->captures_constraints->[0]->is_a_type_of("ClassName")
$self->captures_constraints_count == 1
$self->captures_constraints->[0]->is_a_type_of("Ref")
$self->captures_constraints->[0]->is_a_type_of("ClassName")
Truth table75%3/4
A and B or C
A= $self->captures_constraints_count == 1B= $self->captures_constraints->[0]->is_a_type_of("Ref")C= $self->captures_constraints->[0]->is_a_type_of("ClassName")
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | $self->captures_constraints_count == 1 && | ||||||||||||||||||||||||||||||||||||||||||
| 458 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 459 | $self->captures_constraints->[0]->is_a_type_of('Ref') || | ||||||||||||||||||||||||||||||||||||||||||
| 460 | $self->captures_constraints->[0]->is_a_type_of('ClassName') | ||||||||||||||||||||||||||||||||||||||||||
| 461 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 462 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 13 | return $self->captures_constraints->[0]->check($captures); | |||||||||||||||||||||||||||||||||||||||||
| 464 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 38 | for my $i(0..$#captures) { | |||||||||||||||||||||||||||||||||||||||||
| 466 | 45 | ▶ | $self->captures_constraints->[$i]->check($captures[$i]) || return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 23 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 1868 | ▶ | sub compare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 1868 | my ($a1, $a2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 1868 | return $a1->comparable_arg_number <=> $a2->comparable_arg_number; | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | sub equals { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equals: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my ($self, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | return $self->private_path eq $target->private_path ? $self : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 32 | ▶ | sub scheme { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scheme: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 32 | ▶ | return exists $_[0]->attributes->{Scheme} ? $_[0]->attributes->{Scheme}[0] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 55 | ▶ | sub list_extra_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_extra_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 55 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 490 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 55 | Args => $self->normalized_arg_number, | |||||||||||||||||||||||||||||||||||||||||
| 492 | CaptureArgs => $self->number_of_captures, | ||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 155 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 155 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | __END__ | ||||||||||||||||||||||||||||||||||||||||||