| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | ▶ | croak "$key must be a hash reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $value or builtin::reftype($value) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $definition->{"tokens"} or builtin::reftype($definition->{"tokens"}) ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $definition->{"results"} or builtin::reftype($definition->{"results"}) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $page or builtin::reftype($page) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | if !ref $page || reftype($page) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | ▶ | croak 'cannot add a page after pagination is complete' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->get_page_count and not $self->has_next_page
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | my $continue = $self->_evaluate_expression( $page, $definition->{continuation}, ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | if ( !$self->_is_truthy($continue) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$current_tokens and $self->_same_token_set($current_tokens, $next_tokens)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $value or builtin::reftype($value) ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $existing or builtin::reftype($existing) ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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"} // []
MC/DC100%1/1
$self->get_definition->{"preserve"} // []
$self->get_definition->{"preserve"}
Truth table100%2/2
A
A= $self->get_definition->{"preserve"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not ref $selectors or builtin::reftype($selectors) ne "ARRAY" or not @{$selectors;}
not ref $selectors or builtin::reftype($selectors) ne "ARRAY"
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;}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | return $value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $selector or builtin::reftype($selector) ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 82 | ▶ | if ( !ref $step ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | return | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 80 | ▶ | if !ref $value || reftype($value) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $value or builtin::reftype($value) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | return | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 80 | ▶ | if !exists $value->{$step}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
builtin::reftype($step) ne "HASH" or not exists $step->{"index"} or keys %{$step;} != 1
builtin::reftype($step) ne "HASH" or not exists $step->{"index"}
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
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | return | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | ▶ | if !ref $value || reftype($value) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $value or builtin::reftype($value) ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | my $index = $step->{index}; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | ▶ | $index += @{$value} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | if $index < 0; | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | return | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | if $index < 0 || $index > $#{$value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index < 0 or $index > $#{$value;}
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;}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $target or builtin::reftype($target) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not ref $selector or builtin::reftype($selector) ne "ARRAY" or not @{$selector;}
not ref $selector or builtin::reftype($selector) ne "ARRAY"
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;}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | if ref $step; | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 18 | ▶ | if ( $idx == $#{$selector} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 16 | $current->{$step} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 16 | last; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | ▶ | $current->{$step} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$current->{$step} //= {}
MC/DC0%0/1
$current->{$step} //= {}
$current->{$step}
Truth table50%1/2
A
A= $current->{$step}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $current->{$step} or builtin::reftype($current->{$step}) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $value and builtin::reftype($value) eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | ▶ | if ( !exists $target->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not ref $target->{$key} or builtin::reftype($target->{$key}) ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 33 | ▶ | if ( !ref $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 24 | ▶ | return length "$value" ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 9 | ▶ | if ( blessed($value) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 5 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | ▶ | my $type = reftype($value) // q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($value) // ""
MC/DC0%0/1
builtin::reftype($value) // ""
builtin::reftype($value)
Truth table50%1/2
A
A= builtin::reftype($value)
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | return @{$value} ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | if $type eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | ▶ | return keys %{$value} ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | if $type eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $left or defined $right
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
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | if !defined $left && !defined $right; | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 6 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $left and defined $right
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
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | if !defined $left || !defined $right; | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 6 | ▶ | my $left_type = ref $left ? reftype($left) : q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 6 | ▶ | my $right_type = ref $right ? reftype($right) : q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 6 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | if $left_type ne $right_type; | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 6 | ▶ | return "$left" eq "$right" ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | if !$left_type; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 4 | ▶ | if ( $left_type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | return 0 | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if @{$left} != @{$right}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | foreach my $idx ( 0 .. $#{$left} ) { | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | return 0 | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | ▶ | if keys %{$left} != keys %{$right}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $right->{$key} and $self->_same_value($left->{$key}, $right->{$key})
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})
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||