lib/WebService/Braintree/AdvancedSearchNodes.pm

filter: Statementstmt 98.8% 174 / 176 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 98.0% 50 / 51 Podpod 0.0% 0 / 19 totaltotal 91.4% 235 / 257 CC 6 SCAR 2.4
CC
6
Cov
99%
difference_arrays
3.0
in
3.0
ends_with
2.0
CRAP 1.3
« lib/WebService/Braintree/_/Address.pm ↑ Summary lib/WebService/Braintree/AddOn.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 # Notes:
4 # 1. name() is only used in one error message
5 # 2. searcher() is returned so that every method can chain()
6  
7 {
8 package WebService::Braintree::AdvancedSearchNodes;
9 22 $WebService::Braintree::AdvancedSearchNodes::VERSION = '1.7';
10 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 }
15  
16 {
17 22 package WebService::Braintree::SearchNode;
18 22 $WebService::Braintree::SearchNode::VERSION = '1.7';
19 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 22 has searcher => (is => 'ro');
25 22 has name => (is => 'ro');
26  
27 119 ▶ has criteria => (is => 'rw', default => sub {shift->default_criteria()});
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 68 ▶ sub default_criteria {
Subroutine default_criteria: called CC=1 SCAR=0.0
Pod undocumented
30 68 return {};
31 }
32  
33 56 ▶ sub active {
Subroutine active: called CC=1 SCAR=0.0
Pod undocumented
34 56 my $self = shift;
35 56 return %{$self->criteria};
36 }
37  
38 11 ▶ sub add_node {
Subroutine add_node: called CC=1 SCAR=0.0
Pod undocumented
39 11 my ($self, $operator, $operand) = @_;
40 11 $self->criteria->{$operator} = $operand;
41 11 return $self->searcher;
42 }
43  
44 22 __PACKAGE__->meta->make_immutable;
45 }
46  
47 {
48 22 package WebService::Braintree::IsNode;
49 22 $WebService::Braintree::IsNode::VERSION = '1.7';
50 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 22 extends 'WebService::Braintree::SearchNode';
55  
56 4 ▶ sub is {
Subroutine is: called CC=1 SCAR=0.0
Pod undocumented
57 4 my ($self, $operand) = @_;
58 4 return $self->add_node(is => $operand);
59 }
60  
61 22 __PACKAGE__->meta->make_immutable;
62 }
63  
64 {
65 22 package WebService::Braintree::EqualityNode;
66 22 $WebService::Braintree::EqualityNode::VERSION = '1.7';
67 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 22 extends 'WebService::Braintree::IsNode';
72  
73 1 ▶ sub is_not {
Subroutine is_not: called CC=1 SCAR=0.0
Pod undocumented
74 1 my ($self, $operand) = @_;
75 1 return $self->add_node(is_not => $operand);
76 }
77  
78 22 __PACKAGE__->meta->make_immutable;
79 }
80  
81 {
82 22 package WebService::Braintree::KeyValueNode;
83 22 $WebService::Braintree::KeyValueNode::VERSION = '1.7';
84 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 22 extends 'WebService::Braintree::SearchNode';
89  
90 17 ▶ sub default_criteria {
Subroutine default_criteria: called CC=1 SCAR=0.0
Pod undocumented
91 17 return '';
92 }
93  
94 14 ▶ sub active {
Subroutine active: called CC=1 SCAR=0.0
Pod undocumented
95 14 my $self = shift;
96 14 return $self->criteria;
97 }
98  
99 1 ▶ sub is {
Subroutine is: called CC=1 SCAR=0.0
Pod undocumented
100 1 my ($self, $operand) = @_;
101 1 $self->criteria($operand);
102 1 return $self->searcher;
103 }
104  
105 22 __PACKAGE__->meta->make_immutable;
106 }
107  
108 {
109 22 package WebService::Braintree::PartialMatchNode;
110 22 $WebService::Braintree::PartialMatchNode::VERSION = '1.7';
111 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 22 extends 'WebService::Braintree::EqualityNode';
116  
117 1 ▶ sub starts_with {
Subroutine starts_with: called CC=1 SCAR=0.0
Pod undocumented
118 1 my ($self, $operand) = @_;
119 1 return $self->add_node(starts_with => $operand);
120 }
121  
122 0 ▶ sub ends_with {
Subroutine ends_with: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my ($self, $operand) = @_;
124 0 return $self->add_node(ends_with => $operand);
125 }
126  
127 22 __PACKAGE__->meta->make_immutable;
128 }
129  
130 {
131 22 package WebService::Braintree::TextNode;
132 22 $WebService::Braintree::TextNode::VERSION = '1.7';
133 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 22 extends 'WebService::Braintree::PartialMatchNode';
138  
139 1 ▶ sub contains {
Subroutine contains: called CC=1 SCAR=0.0
Pod undocumented
140 1 my ($self, $operand) = @_;
141 1 return $self->add_node(contains => $operand);
142 }
143  
144 22 __PACKAGE__->meta->make_immutable;
145 }
146  
147 {
148 22 package WebService::Braintree::RangeNode;
149 22 $WebService::Braintree::RangeNode::VERSION = '1.7';
150 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
151 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
152  
153 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 22 extends 'WebService::Braintree::EqualityNode';
155  
156 22 ▶ use overload ( '>=' => 'min', '<=' => 'max');
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158 2 ▶ sub min {
Subroutine min: called CC=1 SCAR=0.0
Pod undocumented
159 2 my ($self, $operand) = @_;
160 2 return $self->add_node(min => $operand);
161 }
162  
163 2 ▶ sub max {
Subroutine max: called CC=1 SCAR=0.0
Pod undocumented
164 2 my ($self, $operand) = @_;
165 2 return $self->add_node(max => $operand);
166 }
167  
168 1 ▶ sub between {
Subroutine between: called CC=1 SCAR=0.0
Pod undocumented
169 1 my ($self, $min, $max) = @_;
170 1 $self->min($min);
171 1 $self->max($max);
172 }
173  
174 22 __PACKAGE__->meta->make_immutable;
175 }
176  
177 {
178 22 package WebService::Braintree::MultipleValuesNode;
179 22 $WebService::Braintree::MultipleValuesNode::VERSION = '1.7';
180 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
181 22 ▶ use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183 22 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
184 22 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
185 22 ▶ use WebService::Braintree::Util qw(is_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
186 22 extends 'WebService::Braintree::SearchNode';
187  
188 22 has allowed_values => (is => 'ro');
189  
190 5 ▶ sub difference_arrays {
Subroutine difference_arrays: called CC=3 SCAR=11.0
Pod undocumented
191 5 my ($array1, $array2) = @_;
192 5 my @diff;
193 5 foreach my $element (@$array1) {
194 10 ▶ push(@diff, $element) unless grep { $element eq $_ } @$array2;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$element eq $_;} @$array2 6 4 10
195 }
196 5 return \@diff;
197 }
198  
199 34 ▶ sub default_criteria {
Subroutine default_criteria: called CC=1 SCAR=0.0
Pod undocumented
200 34 return [];
201 }
202  
203 28 ▶ sub active {
Subroutine active: called CC=1 SCAR=0.0
Pod undocumented
204 28 my $self = shift;
205 28 return @{$self->criteria};
206 }
207  
208 2 ▶ sub is {
Subroutine is: called CC=1 SCAR=0.0
Pod undocumented
209 2 shift->in(@_);
210 }
211  
212 5 ▶ sub _args_to_array {
Subroutine _args_to_array: called CC=2 SCAR=6.9
213 5 my $self = shift;
214 5 my @args;
215 5 ▶ if (is_arrayref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_arrayref($_[0])) { } 1 4 5
216 1 @args = @{$_[0]};
217 } else {
218 4 @args = @_;
219 }
220 5 return @args;
221 }
222  
223 5 ▶ sub in {
Subroutine in: called CC=3 SCAR=11.0
Pod undocumented
224 5 my $self = shift;
225 5 my @values = $self->_args_to_array(@_);
226  
227 5 my $bad_values = difference_arrays(\@values, $self->allowed_values);
228  
229 5 ▶ if (@$bad_values && $self->allowed_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$bad_values and $self->allowed_values) 2 3 5
Condition100%3/3
@$bad_values and $self->allowed_values
!ll&&!rl&&r
212
MC/DC100%2/2
@$bad_values and $self->allowed_values
@$bad_values $self->allowed_values
Truth table100%3/3
A and B
A= @$bad_valuesB= $self->allowed_values
ABresult
0X0
100
111
230 2 croak 'Invalid Argument(s) for ' . $self->name . ': ' . join(', ', @$bad_values);
231 }
232  
233 3 @{$self->criteria} = @values;
234 3 return $self->searcher;
235 }
236  
237 22 __PACKAGE__->meta->make_immutable;
238 }
239  
240 22 1;
241 __END__
« lib/WebService/Braintree/_/Address.pm ↑ Summary lib/WebService/Braintree/AddOn.pm »