lib/Catalyst/ActionRole/QueryMatching.pm

filter: Statementstmt 85.9% 49 / 57 Branchbran 86.6% 26 / 30 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 80.9% 85 / 105 CC 21 SCAR 20.2
CC
21
Cov
83%
_build_query_constraints
14.0
__ANON__
7.0
_compare_arrays
4.0
CRAP 7.5
« lib/Catalyst/Stats.pm ↑ Summary lib/Catalyst/ActionChain.pm »
1 package Catalyst::ActionRole::QueryMatching;
2  
3 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose::Util::TypeConstraints ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 requires 'match', 'match_captures', 'list_extra_info';
7  
8 15 ▶sub _query_attr { @{shift->attributes->{Query}||[]} }
Subroutine _query_attr: called CC=2 SCAR=7.2
Condition50%1/2
+(shift())->attributes->{'Query'} || []
l!l
150
MC/DC0%0/1
+(shift())->attributes->{'Query'} || []
+(shift())->attributes->{'Query'}
Truth table50%1/2
A
A= +(shift())->attributes->{'Query'}
Aresult
11
00
9  
10 2 has is_slurpy => (
11 is=>'ro',
12 init_arg=>undef,
13 isa=>'Bool',
14 required=>1,
15 lazy=>1,
16 builder=>'_build_is_slurpy');
17  
18 7 ▶ sub _build_is_slurpy {
Subroutine _build_is_slurpy: called CC=2 SCAR=6.9
19 7 my $self = shift;
20 7 my($query, @extra) = $self->_query_attr;
21 7 ▶ return $query =~m/^.+,\.\.\.$/ ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$query =~ /^.+,\.\.\.$/ ? : 4 3 7
22 }
23  
24 2 has query_constraints => (
25 is=>'ro',
26 init_arg=>undef,
27 isa=>'ArrayRef|Ref',
28 required=>1,
29 lazy=>1,
30 builder=>'_build_query_constraints');
31  
32 8 ▶ sub _build_query_constraints {
Subroutine _build_query_constraints: called CC=10 SCAR=26.4
33 8 my $self = shift;
34 8 my ($constraint_proto, @extra) = $self->_query_attr;
35  
36 0 ▶ die "Action ${\$self->private_path} defines more than one 'Query' attribute" if scalar @extra;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @extra 0 8 8
37 8 ▶ return +{} unless defined($constraint_proto);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $constraint_proto 0 8 8
38  
39 8 $constraint_proto =~s/^(.+),\.\.\.$/$1/; # slurpy is handled elsewhere
40  
41 # Query may be a Hash like Query(p=>Int,q=>Str) OR it may be a Ref like
42 # Query(Tuple[p=>Int, slurpy HashRef]). The only way to figure is to eval it
43 # and look at what we have.
44 8 ▶ my @signature = eval "package ${\$self->class}; $constraint_proto"
Branch: 1 branch
BranchTrueFalseTotal
my(@signature) = eval "package ${\$self->class;}; $constraint_proto" or die "'${constraint_proto}' is not valid Query Contraint at action ${\$self->private_path;}, error '$@'" 8 0 8
45 0 or die "'$constraint_proto' is not valid Query Contraint at action ${\$self->private_path}, error '$@'";
46  
47 8 ▶ if(scalar(@signature) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @signature > 1) { } 7 1 8
48 # Do a dance to support old school stringy types
49 # At this point we 'should' have a hash...
50 7 my %pairs = @signature;
51 7 foreach my $key(keys %pairs) {
52 10 ▶ next if ref $pairs{$key};
Branch: 1 branch
BranchTrueFalseTotal
if ref $pairs{$key} 8 2 10
53 2 ▶ $pairs{$key} = Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key}) ||
Condition50%1/2
Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key}) || die("'$pairs{$key}' is not a valid type constraint in Action ${\$self->private_path;}")
l!l
20
MC/DC0%0/1
Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key}) || die("'$pairs{$key}' is not a valid type constraint in Action ${\$self->private_path;}")
Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key})
Truth table50%1/2
A
A= Moose::Util::TypeConstraints::find_or_parse_type_constraint($pairs{$key})
Aresult
11
00
54 0 die "'$pairs{$key}' is not a valid type constraint in Action ${\$self->private_path}";
55 }
56 7 return \%pairs;
57 } else {
58 # We have a 'reference type' constraint, like Dict[p=>Int,...]
59 1 ▶ return $signature[0] if ref($signature[0]); # Is like Tiny::Type
Branch: 1 branch
BranchTrueFalseTotal
if ref $signature[0] 1 0 1
60 0 ▶ return Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0]) ||
Condition0%0/2
Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0]) || die("'$signature[0]' is not a valid type constraint in Action ${\$self->private_path;}")
l!l
00
MC/DC0%0/1
Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0]) || die("'$signature[0]' is not a valid type constraint in Action ${\$self->private_path;}")
Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0])
Truth table0%0/2
A
A= Moose::Util::TypeConstraints::find_or_parse_type_constraint($signature[0])
Aresult
11
00
61 0 die "'$signature[0]' is not a valid type constraint in Action ${\$self->private_path}";
62 }
63 }
64  
65 24 ▶around ['match','match_captures'] => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
66 24 my ($orig, $self, $c, @args) = @_;
67 24 my $tc = $self->query_constraints;
68 24 ▶ if(ref $tc eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tc eq 'HASH') { } 21 3 24
69 # Do the key names match, unless slurpy?
70 21 ▶ unless($self->is_slurpy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_slurpy) 9 12 21
71 9 ▶ return 0 unless $self->_compare_arrays([sort keys %$tc],[sort keys %{$c->req->query_parameters}]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_compare_arrays([sort(keys %$tc)], [sort(keys %{$c->req->query_parameters;})]) 2 7 9
72 }
73 19 for my $key(keys %$tc) {
74 24 ▶ $tc->{$key}->check($c->req->query_parameters->{$key}) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$tc->{$key}->check($c->req->query_parameters->{$key}) or return 0 15 9 24
75 }
76 } else {
77 3 ▶ $tc->check($c->req->query_parameters) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$tc->check($c->req->query_parameters) or return 0 1 2 3
78 }
79  
80 11 return $self->$orig($c, @args);
81 2 };
82  
83 0 ▶around 'list_extra_info' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 my ($orig, $self, @args) = @_;
85 return {
86 0 %{ $self->$orig(@args) },
87 };
88 2 };
89  
90 9 ▶sub _compare_arrays {
Subroutine _compare_arrays: called CC=4 SCAR=13.9
91 9 my ($self, $first, $second) = @_;
92 2 ▶ no warnings; # silence spurious -w undef complaints
Subroutine BEGIN: called CC=1 SCAR=0.0
93 9 ▶ return 0 unless @$first == @$second;
Branch: 1 branch
BranchTrueFalseTotal
unless @$first == @$second 1 8 9
94 8 ▶ for (my $i = 0; $i < @$first; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$first) 15 7 22
95 15 ▶ return 0 if $first->[$i] ne $second->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $first->[$i] ne $second->[$i] 1 14 15
96 }
97 7 return 1;
98 }
99  
100 2 1;
101  
102 =head1 NAME
103  
104 Catalyst::ActionRole::QueryMatching - Match on GET parameters using type constraints
105  
106 =head1 SYNOPSIS
107  
108 TBD
109  
110 =head1 DESCRIPTION
111  
112 TBD
113  
114 =head1 METHODS
115  
116 This role defines the following methods
117  
118 =head2 TBD
119  
120 TBD
121  
122 =head1 AUTHORS
123  
124 Catalyst Contributors, see Catalyst.pm
125  
126 =head1 COPYRIGHT
127  
128 This library is free software. You can redistribute it and/or modify it under
129 the same terms as Perl itself.
130  
131 =cut
« lib/Catalyst/Stats.pm ↑ Summary lib/Catalyst/ActionChain.pm »