API/Paginator.pm

filter: Statementstmt 95.0% 252 / 265 Branchbran 65.9% 91 / 138 Conditioncond 39.5% 32 / 81 MC/DCmcdc 6.0% 3 / 50 Subroutinesub 100% 29 / 29 Podpod 100% 5 / 5 totaltotal 72.5% 412 / 568 CC 110 SCAR 28.2
CC
110
Cov
77%
_same_value
49.9
_evaluate_selector
27.7
_set_value
16.6
CRAP 16.7
« API/Role/Services.pm ↑ Summary API/Paginator/Compiler.pm »
1 package Amazon::API::Paginator;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $VERSION = '2.8.2'; ## no critic (RequireInterpolationOfMetachars)
15  
16 12 __PACKAGE__->follow_best_practice;
17 12 __PACKAGE__->mk_accessors(
18 qw(
19 aggregate
20 current_tokens
21 definition
22 _has_next_page
23 page_count
24 parameters
25 preserved
26 previous_tokens
27 )
28 );
29  
30 ########################################################################
31 9 ▶sub new {
Subroutine new: called CC=10 SCAR=25.8
Pod documented
32 ########################################################################
33 9 my ( $class, @options ) = @_;
34  
35 0 ▶ my %options = ref $options[0] ? %{ $options[0] } : @options;
Branch: 1 branch
BranchTrueFalseTotal
ref $options[0] ? : 0 9 9
36  
37 9 foreach my $key (qw(definition parameters)) {
38 18 my $value = $options{$key};
39  
40 18 ▶ croak "$key is required"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 18 18
41 if !defined $value;
42  
43 18 ▶ croak "$key must be a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
if not ref $value or builtin::reftype($value) ne "HASH" 0 18 18
Condition33%1/3
not ref $value or builtin::reftype($value) ne "HASH"
l!l&&r!l&&!r
0018
MC/DC0%0/2
not ref $value or builtin::reftype($value) ne "HASH"
not ref $value builtin::reftype($value) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $valueB= builtin::reftype($value) ne "HASH"
ABresult
1X1
011
000
44 if !ref $value || reftype($value) ne 'HASH';
45 }
46  
47 9 my $definition = $options{definition};
48  
49 croak 'definition tokens must be an array reference'
50 if !ref $definition->{tokens}
51 9 ▶ || reftype( $definition->{tokens} ) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $definition->{"tokens"} or builtin::reftype($definition->{"tokens"}) ne "ARRAY" 0 9 9
Condition33%1/3
not ref $definition->{"tokens"} or builtin::reftype($definition->{"tokens"}) ne "ARRAY"
l!l&&r!l&&!r
009
MC/DC0%0/2
not ref $definition->{"tokens"} or builtin::reftype($definition->{"tokens"}) ne "ARRAY"
not ref $definition->{"tokens"} builtin::reftype($definition->{"tokens"}) ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $definition->{"tokens"}B= builtin::reftype($definition->{"tokens"}) ne "ARRAY"
ABresult
1X1
011
000
52  
53 croak 'definition results must be a hash reference'
54 if !ref $definition->{results}
55 9 ▶ || reftype( $definition->{results} ) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $definition->{"results"} or builtin::reftype($definition->{"results"}) ne "HASH" 0 9 9
Condition33%1/3
not ref $definition->{"results"} or builtin::reftype($definition->{"results"}) ne "HASH"
l!l&&r!l&&!r
009
MC/DC0%0/2
not ref $definition->{"results"} or builtin::reftype($definition->{"results"}) ne "HASH"
not ref $definition->{"results"} builtin::reftype($definition->{"results"}) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $definition->{"results"}B= builtin::reftype($definition->{"results"}) ne "HASH"
ABresult
1X1
011
000
56  
57 9 $options{aggregate} = {};
58 9 $options{current_tokens} = undef;
59 9 $options{_has_next_page} = 0;
60 9 $options{page_count} = 0;
61 9 $options{parameters} = { %{ $options{parameters} } };
62 9 $options{preserved} = {};
63 9 $options{previous_tokens} = undef;
64  
65 9 return $class->SUPER::new( \%options );
66 }
67  
68 ########################################################################
69 16 ▶sub add_page {
Subroutine add_page: called CC=11 SCAR=24.1
Pod documented
70 ########################################################################
71 16 my ( $self, $page ) = @_;
72  
73 16 ▶ croak 'page must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $page or builtin::reftype($page) ne "HASH" 0 16 16
Condition33%1/3
not ref $page or builtin::reftype($page) ne "HASH"
l!l&&r!l&&!r
0016
MC/DC0%0/2
not ref $page or builtin::reftype($page) ne "HASH"
not ref $page builtin::reftype($page) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $pageB= builtin::reftype($page) ne "HASH"
ABresult
1X1
011
000
74 if !ref $page || reftype($page) ne 'HASH';
75  
76 16 ▶ croak 'cannot add a page after pagination is complete'
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_page_count and not $self->has_next_page 0 16 16
Condition66%2/3
$self->get_page_count and not $self->has_next_page
!ll&&!rl&&r
970
MC/DC0%0/2
$self->get_page_count and not $self->has_next_page
$self->get_page_count not $self->has_next_page
Truth table66%2/3
A and not(B)
A= $self->get_page_countB= not $self->has_next_page
ABresult
0X0
100
111
77 if $self->get_page_count && !$self->has_next_page;
78  
79 16 my $page_count = $self->get_page_count + 1;
80 16 $self->set_page_count($page_count);
81  
82 16 ▶ $self->_preserve_page($page)
Branch: 1 branch
BranchTrueFalseTotal
if $page_count == 1 9 7 16
83 if $page_count == 1;
84  
85 16 $self->_aggregate_page($page);
86  
87 16 my $definition = $self->get_definition;
88  
89 16 ▶ if ( $definition->{continuation} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($definition->{"continuation"}) 5 11 16
90 5 my $continue = $self->_evaluate_expression( $page, $definition->{continuation}, );
91  
92 5 ▶ if ( !$self->_is_truthy($continue) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_truthy($continue)) 2 3 5
93 2 $self->set_previous_tokens( $self->get_current_tokens );
94 2 $self->set_current_tokens( {} );
95 2 $self->set__has_next_page(0);
96 2 return $self;
97 }
98 }
99  
100 14 my $next_tokens = $self->_next_tokens($page);
101 14 ▶ my $has_next = any { $self->_is_usable_token($_) } values %{$next_tokens};
Subroutine __ANON__: called CC=1 SCAR=0.0
102  
103 14 ▶ if ( !$has_next ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_next) 4 10 14
104 4 $self->set_previous_tokens( $self->get_current_tokens );
105 4 $self->set_current_tokens($next_tokens);
106 4 $self->set__has_next_page(0);
107 4 return $self;
108 }
109  
110 10 my $current_tokens = $self->get_current_tokens;
111  
112 10 ▶ if ( $current_tokens && $self->_same_token_set( $current_tokens, $next_tokens ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_tokens and $self->_same_token_set($current_tokens, $next_tokens)) 2 8 10
Condition66%2/3
$current_tokens and $self->_same_token_set($current_tokens, $next_tokens)
!ll&&!rl&&r
802
MC/DC50%1/2
$current_tokens and $self->_same_token_set($current_tokens, $next_tokens)
$current_tokens $self->_same_token_set($current_tokens, $next_tokens)
Truth table66%2/3
A and B
A= $current_tokensB= $self->_same_token_set($current_tokens, $next_tokens)
ABresult
0X0
100
111
113 2 local $Data::Dumper::Sortkeys = 1;
114 2 local $Data::Dumper::Terse = 1;
115  
116 2 croak 'the same next token was received twice: ' . Dumper($next_tokens);
117 }
118  
119 8 $self->set_previous_tokens($current_tokens);
120 8 $self->set_current_tokens($next_tokens);
121 8 $self->set__has_next_page(1);
122  
123 8 return $self;
124 }
125  
126 ########################################################################
127 18 ▶sub has_next_page {
Subroutine has_next_page: called CC=2 SCAR=6.9
Pod documented
128 ########################################################################
129 18 my ($self) = @_;
130  
131 18 ▶ return $self->get__has_next_page ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->get__has_next_page ? : 14 4 18
132 }
133  
134 ########################################################################
135 5 ▶sub next_parameters {
Subroutine next_parameters: called CC=4 SCAR=13.9
Pod documented
136 ########################################################################
137 5 my ($self) = @_;
138  
139 return
140 5 ▶ if !$self->has_next_page;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_next_page 1 4 5
141  
142 4 my %parameters = %{ $self->get_parameters };
143 4 my $tokens = $self->get_current_tokens;
144  
145 4 foreach my $token ( @{ $self->get_definition->{tokens} } ) {
146 6 my $input = $token->{input};
147 6 my $value = $tokens->{$input};
148  
149 6 ▶ if ( $self->_is_usable_token($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_usable_token($value)) 5 1 6
150 5 $parameters{$input} = $value;
151 5 next;
152 }
153  
154 1 delete $parameters{$input};
155 }
156  
157 4 return \%parameters;
158 }
159  
160 ########################################################################
161 4 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod documented
162 ########################################################################
163 4 my ($self) = @_;
164  
165 4 my $result = $self->get_aggregate;
166  
167 4 $self->_merge_hashes( $result, $self->get_preserved );
168  
169 4 return $result;
170 }
171  
172 ########################################################################
173 16 ▶sub _aggregate_page {
Subroutine _aggregate_page: called CC=5 SCAR=16.2
174 ########################################################################
175 16 my ( $self, $page ) = @_;
176  
177 16 my $results = $self->get_definition->{results};
178  
179 16 foreach my $verb ( sort keys %{$results} ) {
180 22 my $method = "_aggregate_$verb";
181  
182 22 ▶ croak "unsupported paginator result verb: $verb"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 22 22
183 if !$self->can($method);
184  
185 22 foreach my $selector ( @{ $results->{$verb} } ) {
186 24 my $value = $self->_evaluate_selector( $page, $selector );
187  
188 next
189 24 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 24 24
190  
191 24 $self->$method( $selector, $value );
192 }
193 }
194  
195 16 return;
196 }
197  
198 ########################################################################
199 2 ▶sub _aggregate_add {
Subroutine _aggregate_add: called CC=3 SCAR=11.0
200 ########################################################################
201 2 my ( $self, $selector, $value ) = @_;
202  
203 2 ▶ croak 'add result value must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 2 2
204 if ref $value;
205  
206 2 my $aggregate = $self->get_aggregate;
207 2 my $existing = $self->_evaluate_selector( $aggregate, $selector );
208  
209 2 ▶ if ( !defined $existing ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $existing) 1 1 2
210 1 $self->_set_value( $aggregate, $selector, $value );
211 1 return;
212 }
213  
214 1 $self->_set_value( $aggregate, $selector, $existing + $value );
215  
216 1 return;
217 }
218  
219 ########################################################################
220 16 ▶sub _aggregate_append {
Subroutine _aggregate_append: called CC=6 SCAR=18.7
221 ########################################################################
222 16 my ( $self, $selector, $value ) = @_;
223  
224 16 ▶ croak 'append result value must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $value or builtin::reftype($value) ne "ARRAY" 0 16 16
Condition33%1/3
not ref $value or builtin::reftype($value) ne "ARRAY"
l!l&&r!l&&!r
0016
MC/DC0%0/2
not ref $value or builtin::reftype($value) ne "ARRAY"
not ref $value builtin::reftype($value) ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $valueB= builtin::reftype($value) ne "ARRAY"
ABresult
1X1
011
000
225 if !ref $value || reftype($value) ne 'ARRAY';
226  
227 16 my $aggregate = $self->get_aggregate;
228 16 my $existing = $self->_evaluate_selector( $aggregate, $selector );
229  
230 16 ▶ if ( !defined $existing ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $existing) 9 7 16
231 9 $self->_set_value( $aggregate, $selector, [ @{$value} ] );
232 9 return;
233 }
234  
235 7 ▶ croak 'existing append result value must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $existing or builtin::reftype($existing) ne "ARRAY" 0 7 7
Condition33%1/3
not ref $existing or builtin::reftype($existing) ne "ARRAY"
l!l&&r!l&&!r
007
MC/DC0%0/2
not ref $existing or builtin::reftype($existing) ne "ARRAY"
not ref $existing builtin::reftype($existing) ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $existingB= builtin::reftype($existing) ne "ARRAY"
ABresult
1X1
011
000
236 if !ref $existing || reftype($existing) ne 'ARRAY';
237  
238 7 push @{$existing}, @{$value};
239  
240 7 return;
241 }
242  
243 ########################################################################
244 2 ▶sub _aggregate_concat {
Subroutine _aggregate_concat: called CC=3 SCAR=11.0
245 ########################################################################
246 2 my ( $self, $selector, $value ) = @_;
247  
248 2 ▶ croak 'concat result value must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 2 2
249 if ref $value;
250  
251 2 my $aggregate = $self->get_aggregate;
252 2 my $existing = $self->_evaluate_selector( $aggregate, $selector );
253  
254 2 ▶ if ( !defined $existing ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $existing) 1 1 2
255 1 $self->_set_value( $aggregate, $selector, $value );
256 1 return;
257 }
258  
259 1 $self->_set_value( $aggregate, $selector, $existing . $value );
260  
261 1 return;
262 }
263  
264 ########################################################################
265 4 ▶sub _aggregate_first {
Subroutine _aggregate_first: called CC=2 SCAR=6.9
266 ########################################################################
267 4 my ( $self, $selector, $value ) = @_;
268  
269 4 my $aggregate = $self->get_aggregate;
270 4 my $existing = $self->_evaluate_selector( $aggregate, $selector );
271  
272 return
273 4 ▶ if defined $existing;
Branch: 1 branch
BranchTrueFalseTotal
if defined $existing 2 2 4
274  
275 2 $self->_set_value( $aggregate, $selector, $value );
276  
277 2 return;
278 }
279  
280 ########################################################################
281 9 ▶sub _preserve_page {
Subroutine _preserve_page: called CC=3 SCAR=11.0
282 ########################################################################
283 9 my ( $self, $page ) = @_;
284  
285 9 ▶ my $preserve = $self->get_definition->{preserve} // [];
Condition100%2/2
$self->get_definition->{"preserve"} // []
l!l
18
MC/DC100%1/1
$self->get_definition->{"preserve"} // []
$self->get_definition->{"preserve"}
Truth table100%2/2
A
A= $self->get_definition->{"preserve"}
Aresult
11
00
286  
287 9 foreach my $selector ( @{$preserve} ) {
288 1 my $value = $self->_evaluate_selector( $page, $selector );
289 1 $self->_set_value( $self->get_preserved, $selector, $value );
290 }
291  
292 9 return;
293 }
294  
295 ########################################################################
296 14 ▶sub _next_tokens {
Subroutine _next_tokens: called CC=3 SCAR=11.0
297 ########################################################################
298 14 my ( $self, $page ) = @_;
299  
300 14 my %tokens;
301  
302 14 foreach my $token ( @{ $self->get_definition->{tokens} } ) {
303 16 my $input = $token->{input};
304 16 my $value = $self->_evaluate_expression( $page, $token->{output} );
305  
306 16 ▶ $tokens{$input}
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_usable_token($value) ? : 11 5 16
307 = $self->_is_usable_token($value)
308 ? $value
309 : undef;
310 }
311  
312 14 return \%tokens;
313 }
314  
315 ########################################################################
316 21 ▶sub _evaluate_expression {
Subroutine _evaluate_expression: called CC=7 SCAR=21.3
317 ########################################################################
318 21 my ( $self, $source, $expression ) = @_;
319  
320 21 my $selectors = $expression->{selectors};
321  
322 croak 'paginator expression selectors must be an array reference'
323 21 ▶ if !ref $selectors || reftype($selectors) ne 'ARRAY' || !@{$selectors};
Branch: 1 branch
BranchTrueFalseTotal
if not ref $selectors or builtin::reftype($selectors) ne "ARRAY" or not @{$selectors;} 0 21 21
Condition33%2/6
not ref $selectors or builtin::reftype($selectors) ne "ARRAY" or not @{$selectors;}
l!l&&r!l&&!r
0021
not ref $selectors or builtin::reftype($selectors) ne "ARRAY"
l!l&&r!l&&!r
0021
MC/DC0%0/3
not ref $selectors or builtin::reftype($selectors) ne "ARRAY" or not @{$selectors;}
not ref $selectors builtin::reftype($selectors) ne "ARRAY" not @{$selectors;}
Truth table25%1/4
not(A) or B or not(C)
A= not ref $selectorsB= builtin::reftype($selectors) ne "ARRAY"C= not @{$selectors;}
ABCresult
1XX1
01X1
0011
0000
324  
325 21 foreach my $idx ( 0 .. $#{$selectors} ) {
326 22 my $value = $self->_evaluate_selector( $source, $selectors->[$idx] );
327  
328 return $value
329 22 ▶ if $idx == $#{$selectors};
Branch: 1 branch
BranchTrueFalseTotal
if $idx == $#{$selectors;} 21 1 22
330  
331 1 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_truthy($value) 0 1 1
332 if $self->_is_truthy($value);
333 }
334  
335 0 return;
336 }
337  
338 ########################################################################
339 71 ▶sub _evaluate_selector {
Subroutine _evaluate_selector: called CC=17 SCAR=33.2
340 ########################################################################
341 71 my ( $self, $source, $selector ) = @_;
342  
343 71 ▶ croak 'selector must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $selector or builtin::reftype($selector) ne "ARRAY" 0 71 71
Condition33%1/3
not ref $selector or builtin::reftype($selector) ne "ARRAY"
l!l&&r!l&&!r
0071
MC/DC0%0/2
not ref $selector or builtin::reftype($selector) ne "ARRAY"
not ref $selector builtin::reftype($selector) ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $selectorB= builtin::reftype($selector) ne "ARRAY"
ABresult
1X1
011
000
344 if !ref $selector || reftype($selector) ne 'ARRAY';
345  
346 71 my $value = $source;
347  
348 71 foreach my $step ( @{$selector} ) {
349 return
350 82 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 82 82
351  
352 82 ▶ if ( !ref $step ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $step) 80 2 82
353 return
354 80 ▶ if !ref $value || reftype($value) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $value or builtin::reftype($value) ne "HASH" 0 80 80
Condition33%1/3
not ref $value or builtin::reftype($value) ne "HASH"
l!l&&r!l&&!r
0080
MC/DC0%0/2
not ref $value or builtin::reftype($value) ne "HASH"
not ref $value builtin::reftype($value) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $valueB= builtin::reftype($value) ne "HASH"
ABresult
1X1
011
000
355  
356 return
357 80 ▶ if !exists $value->{$step};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $value->{$step} 16 64 80
358  
359 64 $value = $value->{$step};
360 64 next;
361 }
362  
363 croak 'invalid selector index step'
364 if reftype($step) ne 'HASH'
365 || !exists $step->{index}
366 2 ▶ || keys %{$step} != 1;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($step) ne "HASH" or not exists $step->{"index"} or keys %{$step;} != 1 0 2 2
Condition33%2/6
builtin::reftype($step) ne "HASH" or not exists $step->{"index"} or keys %{$step;} != 1
l!l&&r!l&&!r
002
builtin::reftype($step) ne "HASH" or not exists $step->{"index"}
l!l&&r!l&&!r
002
MC/DC0%0/3
builtin::reftype($step) ne "HASH" or not exists $step->{"index"} or keys %{$step;} != 1
builtin::reftype($step) ne "HASH" not exists $step->{"index"} keys %{$step;} != 1
Truth table25%1/4
A or not(B) or C
A= builtin::reftype($step) ne "HASH"B= not exists $step->{"index"}C= keys %{$step;} != 1
ABCresult
1XX1
01X1
0011
0000
367  
368 return
369 2 ▶ if !ref $value || reftype($value) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $value or builtin::reftype($value) ne "ARRAY" 0 2 2
Condition33%1/3
not ref $value or builtin::reftype($value) ne "ARRAY"
l!l&&r!l&&!r
002
MC/DC0%0/2
not ref $value or builtin::reftype($value) ne "ARRAY"
not ref $value builtin::reftype($value) ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $valueB= builtin::reftype($value) ne "ARRAY"
ABresult
1X1
011
000
370  
371 2 my $index = $step->{index};
372 2 ▶ $index += @{$value}
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 2 0 2
373 if $index < 0;
374  
375 return
376 2 ▶ if $index < 0 || $index > $#{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 or $index > $#{$value;} 0 2 2
Condition33%1/3
$index < 0 or $index > $#{$value;}
l!l&&r!l&&!r
002
MC/DC0%0/2
$index < 0 or $index > $#{$value;}
$index < 0 $index > $#{$value;}
Truth table33%1/3
A or B
A= $index < 0B= $index > $#{$value;}
ABresult
1X1
011
000
377  
378 2 $value = $value->[$index];
379 }
380  
381 55 return $value;
382 }
383  
384 ########################################################################
385 16 ▶sub _set_value {
Subroutine _set_value: called CC=12 SCAR=28.1
386 ########################################################################
387 16 my ( $self, $target, $selector, $value ) = @_;
388  
389 16 ▶ croak 'target must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if not ref $target or builtin::reftype($target) ne "HASH" 0 16 16
Condition33%1/3
not ref $target or builtin::reftype($target) ne "HASH"
l!l&&r!l&&!r
0016
MC/DC0%0/2
not ref $target or builtin::reftype($target) ne "HASH"
not ref $target builtin::reftype($target) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $targetB= builtin::reftype($target) ne "HASH"
ABresult
1X1
011
000
390 if !ref $target || reftype($target) ne 'HASH';
391  
392 croak 'target selector must be a non-empty array reference'
393 if !ref $selector
394 || reftype($selector) ne 'ARRAY'
395 16 ▶ || !@{$selector};
Branch: 1 branch
BranchTrueFalseTotal
if not ref $selector or builtin::reftype($selector) ne "ARRAY" or not @{$selector;} 0 16 16
Condition33%2/6
not ref $selector or builtin::reftype($selector) ne "ARRAY" or not @{$selector;}
l!l&&r!l&&!r
0016
not ref $selector or builtin::reftype($selector) ne "ARRAY"
l!l&&r!l&&!r
0016
MC/DC0%0/3
not ref $selector or builtin::reftype($selector) ne "ARRAY" or not @{$selector;}
not ref $selector builtin::reftype($selector) ne "ARRAY" not @{$selector;}
Truth table25%1/4
not(A) or B or not(C)
A= not ref $selectorB= builtin::reftype($selector) ne "ARRAY"C= not @{$selector;}
ABCresult
1XX1
01X1
0011
0000
396  
397 16 my $current = $target;
398  
399 16 foreach my $idx ( 0 .. $#{$selector} ) {
400 18 my $step = $selector->[$idx];
401  
402 18 ▶ croak 'indexed selectors cannot be result targets'
Branch: 1 branch
BranchTrueFalseTotal
if ref $step 0 18 18
403 if ref $step;
404  
405 18 ▶ if ( $idx == $#{$selector} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == $#{$selector;}) 16 2 18
406 16 $current->{$step} = $value;
407 16 last;
408 }
409  
410 2 ▶ $current->{$step} //= {};
Condition50%1/2
$current->{$step} //= {}
l!l
02
MC/DC0%0/1
$current->{$step} //= {}
$current->{$step}
Truth table50%1/2
A
A= $current->{$step}
Aresult
11
00
411  
412 croak "result target $step is not a hash reference"
413 if !ref $current->{$step}
414 2 ▶ || reftype( $current->{$step} ) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $current->{$step} or builtin::reftype($current->{$step}) ne "HASH" 0 2 2
Condition33%1/3
not ref $current->{$step} or builtin::reftype($current->{$step}) ne "HASH"
l!l&&r!l&&!r
002
MC/DC0%0/2
not ref $current->{$step} or builtin::reftype($current->{$step}) ne "HASH"
not ref $current->{$step} builtin::reftype($current->{$step}) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $current->{$step}B= builtin::reftype($current->{$step}) ne "HASH"
ABresult
1X1
011
000
415  
416 2 $current = $current->{$step};
417 }
418  
419 16 return;
420 }
421  
422 ########################################################################
423 5 ▶sub _merge_hashes {
Subroutine _merge_hashes: called CC=7 SCAR=20.5
424 ########################################################################
425 5 my ( $self, $target, $source ) = @_;
426  
427 5 foreach my $key ( keys %{$source} ) {
428 2 my $value = $source->{$key};
429  
430 2 ▶ if ( ref $value && reftype($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and builtin::reftype($value) eq "HASH") 1 1 2
Condition66%2/3
ref $value and builtin::reftype($value) eq "HASH"
!ll&&!rl&&r
101
MC/DC50%1/2
ref $value and builtin::reftype($value) eq "HASH"
ref $value builtin::reftype($value) eq "HASH"
Truth table66%2/3
A and B
A= ref $valueB= builtin::reftype($value) eq "HASH"
ABresult
0X0
100
111
431 1 ▶ if ( !exists $target->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $target->{$key}) 0 1 1
432 0 $target->{$key} = {};
433 }
434  
435 croak "cannot merge paginator result at $key"
436 if !ref $target->{$key}
437 1 ▶ || reftype( $target->{$key} ) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $target->{$key} or builtin::reftype($target->{$key}) ne "HASH" 0 1 1
Condition33%1/3
not ref $target->{$key} or builtin::reftype($target->{$key}) ne "HASH"
l!l&&r!l&&!r
001
MC/DC0%0/2
not ref $target->{$key} or builtin::reftype($target->{$key}) ne "HASH"
not ref $target->{$key} builtin::reftype($target->{$key}) ne "HASH"
Truth table33%1/3
not(A) or B
A= not ref $target->{$key}B= builtin::reftype($target->{$key}) ne "HASH"
ABresult
1X1
011
000
438  
439 1 $self->_merge_hashes( $target->{$key}, $value );
440 1 next;
441 }
442  
443 1 $target->{$key} = $value;
444 }
445  
446 5 return;
447 }
448  
449 ########################################################################
450 42 ▶sub _is_truthy {
Subroutine _is_truthy: called CC=12 SCAR=27.5
451 ########################################################################
452 42 my ( $self, $value ) = @_;
453  
454 42 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 9 33 42
455 if !defined $value;
456  
457 33 ▶ if ( !ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value) 24 9 33
458 24 ▶ return length "$value" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length "$value" ? : 22 2 24
459 }
460  
461 9 ▶ if ( blessed($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value)) 5 4 9
462 5 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 3 2 5
463 }
464  
465 4 ▶ my $type = reftype($value) // q{};
Condition50%1/2
builtin::reftype($value) // ""
l!l
40
MC/DC0%0/1
builtin::reftype($value) // ""
builtin::reftype($value)
Truth table50%1/2
A
A= builtin::reftype($value)
Aresult
11
00
466  
467 0 ▶ return @{$value} ? 1 : 0
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "ARRAY" 0 4 4
@{$value;} ? : 0 0 0
468 if $type eq 'ARRAY';
469  
470 4 ▶ return keys %{$value} ? 1 : 0
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "HASH" 4 0 4
keys %{$value;} ? : 4 0 4
471 if $type eq 'HASH';
472  
473 0 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
474 }
475  
476 ########################################################################
477 36 ▶sub _is_usable_token {
Subroutine _is_usable_token: called CC=1 SCAR=0.0
478 ########################################################################
479 36 my ( $self, $value ) = @_;
480  
481 36 return $self->_is_truthy($value);
482 }
483  
484 ########################################################################
485 2 ▶sub _same_token_set {
Subroutine _same_token_set: called CC=1 SCAR=0.0
486 ########################################################################
487 2 my ( $self, $left, $right ) = @_;
488  
489 2 return $self->_same_value( $left, $right );
490 }
491  
492 ########################################################################
493 6 ▶sub _same_value {
Subroutine _same_value: called CC=19 SCAR=39.1
494 ########################################################################
495 6 my ( $self, $left, $right ) = @_;
496  
497 6 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left or defined $right 0 6 6
Condition33%1/3
defined $left or defined $right
l!l&&r!l&&!r
600
MC/DC0%0/2
defined $left or defined $right
defined $left defined $right
Truth table33%1/3
A or B
A= defined $leftB= defined $right
ABresult
1X1
011
000
498 if !defined $left && !defined $right;
499  
500 6 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left and defined $right 0 6 6
Condition33%1/3
defined $left and defined $right
!ll&&!rl&&r
006
MC/DC0%0/2
defined $left and defined $right
defined $left defined $right
Truth table33%1/3
A and B
A= defined $leftB= defined $right
ABresult
0X0
100
111
501 if !defined $left || !defined $right;
502  
503 6 ▶ my $left_type = ref $left ? reftype($left) : q{};
Branch: 1 branch
BranchTrueFalseTotal
ref $left ? : 4 2 6
504 6 ▶ my $right_type = ref $right ? reftype($right) : q{};
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 4 2 6
505  
506 6 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $left_type ne $right_type 0 6 6
507 if $left_type ne $right_type;
508  
509 6 ▶ return "$left" eq "$right" ? 1 : 0
Branch: 2 branches
BranchTrueFalseTotal
unless $left_type 2 4 6
"$left" eq "$right" ? : 2 0 2
510 if !$left_type;
511  
512 4 ▶ if ( $left_type eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_type eq "ARRAY") 0 4 4
513 return 0
514 0 ▶ if @{$left} != @{$right};
Branch: 1 branch
BranchTrueFalseTotal
if @{$left;} != @{$right;} 0 0 0
515  
516 0 foreach my $idx ( 0 .. $#{$left} ) {
517 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_value($left->[$idx], $right->[$idx]) 0 0 0
518 if !$self->_same_value( $left->[$idx], $right->[$idx] );
519 }
520  
521 0 return 1;
522 }
523  
524 4 ▶ if ( $left_type eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_type eq "HASH") 4 0 4
525 return 0
526 4 ▶ if keys %{$left} != keys %{$right};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$left;} != keys %{$right;} 0 4 4
527  
528 4 foreach my $key ( keys %{$left} ) {
529 return 0
530 if !exists $right->{$key}
531 4 ▶ || !$self->_same_value( $left->{$key}, $right->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $right->{$key} and $self->_same_value($left->{$key}, $right->{$key}) 0 4 4
Condition33%1/3
exists $right->{$key} and $self->_same_value($left->{$key}, $right->{$key})
!ll&&!rl&&r
004
MC/DC0%0/2
exists $right->{$key} and $self->_same_value($left->{$key}, $right->{$key})
exists $right->{$key} $self->_same_value($left->{$key}, $right->{$key})
Truth table33%1/3
A and B
A= exists $right->{$key}B= $self->_same_value($left->{$key}, $right->{$key})
ABresult
0X0
100
111
532 }
533  
534 4 return 1;
535 }
536  
537 0 croak "unsupported paginator token type: $left_type";
538 }
539  
540 12 1;
541  
542 __END__
« API/Role/Services.pm ↑ Summary API/Paginator/Compiler.pm »