API/RequestArguments.pm

filter: Statementstmt 88.6% 172 / 194 Branchbran 78.1% 86 / 110 Conditioncond 72.3% 55 / 76 MC/DCmcdc 43.9% 18 / 41 Subroutinesub 100% 31 / 31 Podpod n/a totaltotal 80.0% 362 / 452 CC 124 SCAR 29.2
CC
124
Cov
82%
__ANON__
31.6
_build_search_attributes
31.6
__ANON__
24.8
CRAP 18.6
↑ Summary API.pm »
1 package Catalyst::Controller::DBIC::API::RequestArguments;
2 16 $Catalyst::Controller::DBIC::API::RequestArguments::VERSION = '2.009000';
3 #ABSTRACT: Provides Request argument validation
4 16 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use Catalyst::Controller::DBIC::API::Types(':all');
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use MooseX::Types::Moose(':all');
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Scalar::Util('reftype');
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Catalyst::Controller::DBIC::API::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 16 ▶use Catalyst::Controller::DBIC::API::JoinBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16  
17 16 has [qw( search_validator select_validator )] => (
18 is => 'ro',
19 isa => 'Catalyst::Controller::DBIC::API::Validator',
20 lazy => 1,
21 builder => '_build_validator',
22 );
23  
24 135 ▶sub _build_validator {
Subroutine _build_validator: called CC=1 SCAR=0.0
25 135 return Catalyst::Controller::DBIC::API::Validator->new;
26 }
27  
28 16 parameter static => ( isa => Bool, default => 0 );
29  
30 32 ▶role {
Subroutine __ANON__: called CC=2 SCAR=7.1
31 32 my $p = shift;
32  
33 32 ▶ if ( $p->static ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->static) { } 16 16 32
34 16 requires
35 qw( check_has_relation check_column_relation prefetch_allows );
36 }
37 else {
38 16 requires qw( _controller check_has_relation check_column_relation );
39 }
40  
41  
42 32 has 'count' => (
43 is => 'ro',
44 writer => '_set_count',
45 isa => Int,
46 predicate => 'has_count',
47 );
48  
49  
50 32 has 'page' => (
51 is => 'ro',
52 writer => '_set_page',
53 isa => Int,
54 predicate => 'has_page',
55 );
56  
57  
58 32 has 'offset' => (
59 is => 'ro',
60 writer => '_set_offset',
61 isa => Int,
62 predicate => 'has_offset',
63 );
64  
65  
66 has 'ordered_by' => (
67 is => 'ro',
68 writer => '_set_ordered_by',
69 isa => OrderedBy,
70 predicate => 'has_ordered_by',
71 coerce => 1,
72 257 ▶ default => sub { $p->static ? [] : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$p->static ? : 151 106 257
73 32 );
74  
75  
76 has 'grouped_by' => (
77 is => 'ro',
78 writer => '_set_grouped_by',
79 isa => GroupedBy,
80 predicate => 'has_grouped_by',
81 coerce => 1,
82 287 ▶ default => sub { $p->static ? [] : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$p->static ? : 181 106 287
83 32 );
84  
85  
86 has prefetch => (
87 is => 'ro',
88 writer => '_set_prefetch',
89 isa => Prefetch,
90 302 ▶ default => sub { $p->static ? [] : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$p->static ? : 196 106 302
91 coerce => 1,
92 7 ▶ trigger => sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
93 7 my ( $self, $new ) = @_;
94  
95 7 foreach my $pf (@$new) {
96 7 ▶ if ( HashRef->check($pf) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (HashRef()->check($pf)) { } 2 5 7
97 2 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
unless $self->prefetch_validator->validate($pf)->[0] 0 2 2
98 0 qq|'${\Dumper($pf)}' is not an allowed prefetch in: ${\join("\n", @{$self->prefetch_validator->templates})}|
99 unless $self->prefetch_validator->validate($pf)->[0];
100 }
101 else {
102 5 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
unless $self->prefetch_validator->validate({$pf, 1})->[0] 2 3 5
103 2 qq|'$pf' is not an allowed prefetch in: ${\join("\n", @{$self->prefetch_validator->templates})}|
104 unless $self->prefetch_validator->validate(
105 { $pf => 1 } )->[0];
106 }
107 }
108 },
109 32 );
110  
111  
112 has 'search_exposes' => (
113 is => 'ro',
114 writer => '_set_search_exposes',
115 isa => ArrayRef [ Str | HashRef ],
116 predicate => 'has_search_exposes',
117 272 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
118 136 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
119 136 my ( $self, $new ) = @_;
120 136 $self->search_validator->load($_) for @$new;
121 },
122 32 );
123  
124  
125 has 'search' => (
126 is => 'ro',
127 writer => '_set_search',
128 isa => SearchParameters,
129 predicate => 'has_search',
130 coerce => 1,
131 35 ▶ trigger => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
132 35 my ( $self, $new ) = @_;
133  
134 35 ▶ if ( $self->has_search_exposes and @{ $self->search_exposes } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_search_exposes and @{$self->search_exposes;}) { } 7 28 35
Condition66%2/3
$self->has_search_exposes and @{$self->search_exposes;}
!ll&&!rl&&r
0287
MC/DC50%1/2
$self->has_search_exposes and @{$self->search_exposes;}
$self->has_search_exposes @{$self->search_exposes;}
Truth table66%2/3
A and B
A= $self->has_search_exposesB= @{$self->search_exposes;}
ABresult
0X0
100
111
135 7 foreach my $foo (@$new) {
136 7 ▶ while ( my ( $k, $v ) = each %$foo ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$foo) 7 4 11
137 7 local $Data::Dumper::Terse = 1;
138 7 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
unless $self->search_validator->validate({$k, $v})->[0] 3 4 7
139 3 qq|{ $k => ${\Dumper($v)} } is not an allowed search term in: ${\join("\n", @{$self->search_validator->templates})}|
140 unless $self->search_validator->validate(
141 { $k => $v } )->[0];
142 }
143 }
144 }
145 else {
146 28 foreach my $foo (@$new) {
147 28 ▶ while ( my ( $k, $v ) = each %$foo ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$foo) 31 28 59
148 31 $self->check_column_relation( { $k => $v } );
149 }
150 }
151 }
152  
153 32 my ( $search_parameters, $search_attributes ) =
154 $self->generate_parameters_attributes($new);
155 31 $self->_set_search_parameters($search_parameters);
156 31 $self->_set_search_attributes($search_attributes);
157  
158 },
159 32 );
160  
161  
162 has search_parameters => (
163 is => 'ro',
164 isa => SearchParameters,
165 writer => '_set_search_parameters',
166 predicate => 'has_search_parameters',
167 coerce => 1,
168 302 ▶ default => sub { [ {} ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
169 32 );
170  
171  
172 32 has search_attributes => (
173 is => 'ro',
174 isa => HashRef,
175 writer => '_set_search_attributes',
176 predicate => 'has_search_attributes',
177 lazy_build => 1,
178 );
179  
180  
181 32 has search_total_entries => (
182 is => 'ro',
183 isa => Int,
184 writer => '_set_search_total_entries',
185 predicate => 'has_search_total_entries',
186 );
187  
188  
189 has 'select_exposes' => (
190 is => 'ro',
191 writer => '_set_select_exposes',
192 isa => ArrayRef [ Str | HashRef ],
193 predicate => 'has_select_exposes',
194 302 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
195 106 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
196 106 my ( $self, $new ) = @_;
197 106 $self->select_validator->load($_) for @$new;
198 },
199 32 );
200  
201  
202 has select => (
203 is => 'ro',
204 writer => '_set_select',
205 isa => SelectColumns,
206 predicate => 'has_select',
207 227 ▶ default => sub { $p->static ? [] : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$p->static ? : 121 106 227
208 coerce => 1,
209 78 ▶ trigger => sub {
Subroutine __ANON__: called CC=5 SCAR=17.8
210 78 my ( $self, $new ) = @_;
211 78 ▶ if ( $self->has_select_exposes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_select_exposes) { } 78 0 78
212 78 foreach my $val (@$new) {
213 108 ▶ die "'$val' is not allowed in a select"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->select_validator->validate($val) 0 108 108
214 unless $self->select_validator->validate($val);
215 }
216 }
217 else {
218 0 $self->check_column_relation( $_, $p->static ) for @$new;
219 }
220 },
221 32 );
222  
223  
224 has as => (
225 is => 'ro',
226 writer => '_set_as',
227 isa => AsAliases,
228 302 ▶ default => sub { $p->static ? [] : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$p->static ? : 196 106 302
229 2 ▶ trigger => sub {
Subroutine __ANON__: called CC=6 SCAR=26.5
230 2 my ( $self, $new ) = @_;
231 2 ▶ if ( $self->has_select ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_select) { } 2 0 2
elsif (defined $new) { } 0 0 0
232 die
233 0 ▶ "'as' argument count (${\scalar(@$new)}) must match 'select' argument count (${\scalar(@{$self->select || []})})"
Condition0%0/2
$self->select || []
l!l
00
MC/DC0%0/1
$self->select || []
$self->select
Truth table0%0/2
A
A= $self->select
Aresult
11
00
234 2 ▶ unless @$new == @{ $self->select || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @$new == @{$self->select or [];} 0 2 2
Condition50%1/2
$self->select || []
l!l
20
MC/DC0%0/1
$self->select || []
$self->select
Truth table50%1/2
A
A= $self->select
Aresult
11
00
235 }
236 elsif ( defined $new ) {
237 0 die "'as' is only valid if 'select is also provided'";
238 }
239 }
240 32 );
241  
242  
243 32 has joins => (
244 is => 'ro',
245 isa => JoinBuilder,
246 lazy_build => 1,
247 handles => { build_joins => 'joins', }
248 );
249  
250  
251 has 'request_data' => (
252 is => 'ro',
253 isa => HashRef,
254 writer => '_set_request_data',
255 predicate => 'has_request_data',
256 106 ▶ trigger => sub {
Subroutine __ANON__: called CC=12 SCAR=24.9
257 106 my ( $self, $new ) = @_;
258 106 my $controller = $self->_controller;
259 106 ▶ return unless defined($new) && keys %$new;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new and keys %$new 24 82 106
Condition66%2/3
defined $new and keys %$new
!ll&&!rl&&r
02482
MC/DC50%1/2
defined $new and keys %$new
defined $new keys %$new
Truth table66%2/3
A and B
A= defined $newB= keys %$new
ABresult
0X0
100
111
260 $self->_set_prefetch( $new->{ $controller->prefetch_arg } )
261 82 ▶ if exists $new->{ $controller->prefetch_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->prefetch_arg} 7 75 82
262 $self->_set_select( $new->{ $controller->select_arg } )
263 80 ▶ if exists $new->{ $controller->select_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->select_arg} 3 77 80
264 $self->_set_as( $new->{ $controller->as_arg } )
265 80 ▶ if exists $new->{ $controller->as_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->as_arg} 2 78 80
266 $self->_set_grouped_by( $new->{ $controller->grouped_by_arg } )
267 80 ▶ if exists $new->{ $controller->grouped_by_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->grouped_by_arg} 1 79 80
268 $self->_set_ordered_by( $new->{ $controller->ordered_by_arg } )
269 80 ▶ if exists $new->{ $controller->ordered_by_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->ordered_by_arg} 10 70 80
270 $self->_set_count( $new->{ $controller->count_arg } )
271 80 ▶ if exists $new->{ $controller->count_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->count_arg} 6 74 80
272 $self->_set_page( $new->{ $controller->page_arg } )
273 79 ▶ if exists $new->{ $controller->page_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->page_arg} 5 74 79
274 $self->_set_offset( $new->{ $controller->offset_arg } )
275 78 ▶ if exists $new->{ $controller->offset_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->offset_arg} 0 78 78
276 $self->_set_search( $new->{ $controller->search_arg } )
277 78 ▶ if exists $new->{ $controller->search_arg };
Branch: 1 branch
BranchTrueFalseTotal
if exists $$new{$controller->search_arg} 36 42 78
278 }
279 32 );
280  
281 16 ▶ method _build_joins => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build_joins: called CC=1 SCAR=0.0
282 16 return Catalyst::Controller::DBIC::API::JoinBuilder->new(
283 name => 'TOP' );
284 32 };
285  
286  
287 25 ▶ method format_search_parameters => sub {
Subroutine format_search_parameters: called CC=2 SCAR=6.9
288 25 my ( $self, $params ) = @_;
289  
290 25 my $genparams = [];
291  
292 25 foreach my $param (@$params) {
293 25 push(
294 @$genparams,
295 $self->generate_column_parameters(
296 $self->stored_result_source,
297 $param, $self->joins
298 )
299 );
300 }
301  
302 24 return $genparams;
303 32 };
304  
305  
306 81 ▶ method generate_column_parameters => sub {
Subroutine generate_column_parameters: called CC=14 SCAR=32.1
307 0 my ( $self, $source, $param, $join, $base ) = @_;
308 0 ▶ $base ||= 'me';
Condition100%4/4
$base ||= "me"
l!l
5229
$base ||= "me"
l!l
13
MC/DC100%1/1
$base ||= "me"
$base
MC/DC100%1/1
$base ||= "me"
$base
Truth table100%2/2
A
A= $base
Aresult
11
00
Truth table100%2/2
A
A= $base
Aresult
11
00
309 81 my $search_params = {};
310  
311 # return non-hashref params unaltered
312 81 ▶ return $param
Branch: 2 branches
BranchTrueFalseTotal
unless ref $param eq "HASH" 30 51 81
unless ref $param eq "HASH" 0 4 4
313 unless ref $param eq 'HASH';
314  
315 # build up condition
316 51 foreach my $column ( keys %$param ) {
317 0 my $value = $param->{$column};
318 0 ▶ if ( $source->has_relationship($column) ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($source->has_relationship($column)) { } 18 38 56
elsif ($source->has_column($column)) { } 24 14 38
elsif ($column eq '-or' or $column eq '-and' or $column eq '-not') { } 11 3 14
if ($source->has_relationship($column)) { } 1 3 4
elsif ($source->has_column($column)) { } 3 0 3
elsif ($column eq '-or' or $column eq '-and' or $column eq '-not') { } 0 0 0
319  
320 # check if the value isn't a hashref
321 0 ▶ unless ( ref $value eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
unless (ref $value eq "HASH") 2 16 18
unless (ref $value eq "HASH") 0 1 1
322 {
323 0 $search_params->{ join( '.', $base, $column ) } =
324 $value;
325 0 next;
326 }
327  
328 $search_params = {
329 %$search_params,
330 0 %{ $self->generate_column_parameters(
331 $source->related_source($column),
332 $value,
333 Catalyst::Controller::DBIC::API::JoinBuilder->new(
334 parent => $join,
335 name => $column
336 ),
337 $column
338 )
339 }
340 };
341 }
342 elsif ( $source->has_column($column) ) {
343 $search_params->{ join( '.', $base, $column ) } =
344 0 $param->{$column};
345 }
346 ▶ elsif ( $column eq '-or' || $column eq '-and' || $column eq '-not' ) {
Condition41%5/12
$column eq "-or" or $column eq "-and" or $column eq "-not"
l!l&&r!l&&!r
1103
$column eq "-or" or $column eq "-and"
l!l&&r!l&&!r
653
$column eq "-or" or $column eq "-and" or $column eq "-not"
l!l&&r!l&&!r
000
$column eq "-or" or $column eq "-and"
l!l&&r!l&&!r
000
MC/DC66%2/3
$column eq "-or" or $column eq "-and" or $column eq "-not"
$column eq "-or" $column eq "-and" $column eq "-not"
MC/DC0%0/3
$column eq "-or" or $column eq "-and" or $column eq "-not"
$column eq "-or" $column eq "-and" $column eq "-not"
Truth table75%3/4
A or B or C
A= $column eq "-or"B= $column eq "-and"C= $column eq "-not"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $column eq "-or"B= $column eq "-and"C= $column eq "-not"
ABCresult
1XX1
01X1
0011
0000
347 # either an arrayref or hashref
348 11 ▶ if ( ref $value eq 'HASH' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 0 11 11
elsif (ref $value eq 'ARRAY') { } 11 0 11
if (ref $value eq 'HASH') { } 0 0 0
elsif (ref $value eq 'ARRAY') { } 0 0 0
349 0 $search_params->{$column} = $self->generate_column_parameters(
350 $source,
351 $value,
352 $join,
353 $base,
354 );
355 }
356 elsif ( ref $value eq 'ARRAY' ) {
357 36 push @{$search_params->{$column}},
358 $self->generate_column_parameters(
359 $source,
360 $_,
361 $join,
362 $base,
363 )
364 11 for @$value;
365 }
366 else {
367 0 die "unsupported value '$value' for column '$column'\n";
368 }
369 }
370  
371 # might be a sql function instead of a column name
372 # e.g. {colname => {like => '%foo%'}}
373 else {
374 # but only if it's not a hashref
375 3 ▶ unless ( ref $value eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 1 2 3
if (ref $value eq 'HASH') { } 0 0 0
376 $search_params->{ join( '.', $base, $column ) } =
377 2 $param->{$column};
378 }
379 else {
380 1 die "unsupported value '$value' for column '$column'\n";
381 }
382 }
383 }
384  
385 49 return $search_params;
386 32 };
387  
388  
389 32 ▶ method generate_parameters_attributes => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
390 32 my ( $self, $args ) = @_;
391  
392 32 return ( $self->format_search_parameters($args),
393 $self->search_attributes );
394 32 };
395  
396 54 ▶ method _build_search_attributes => sub {
Subroutine _build_search_attributes: called CC=29 SCAR=34.5
397 54 my ( $self, $args ) = @_;
398 54 my $static = $self->_controller;
399 my $search_attributes = {
400 group_by => $self->grouped_by
401 || (
402 53 ▶ ( scalar( @{ $static->grouped_by } ) ) ? $static->grouped_by
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$static->ordered_by;} ? : 6 40 46
Condition100%3/3
$self->ordered_by || (scalar @{$static->ordered_by;} ? $static->ordered_by : undef)
l!l&&r!l&&!r
8640
MC/DC100%2/2
$self->ordered_by || (scalar @{$static->ordered_by;} ? $static->ordered_by : undef)
$self->ordered_by (scalar @{$static->ordered_by;} ? $static->ordered_by : undef)
Truth table100%3/3
A || B
A= $self->ordered_byB= (scalar @{$static->ordered_by;} ? $static->ordered_by : undef)
ABresult
1X1
011
000
403 : undef
404 ),
405 order_by => $self->ordered_by
406 || (
407 46 ▶ ( scalar( @{ $static->ordered_by } ) ) ? $static->ordered_by
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$static->select;} ? : 12 39 51
Condition100%3/3
$self->select || (scalar @{$static->select;} ? $static->select : undef)
l!l&&r!l&&!r
31239
MC/DC100%2/2
$self->select || (scalar @{$static->select;} ? $static->select : undef)
$self->select (scalar @{$static->select;} ? $static->select : undef)
Truth table100%3/3
A || B
A= $self->selectB= (scalar @{$static->select;} ? $static->select : undef)
ABresult
1X1
011
000
408 : undef
409 ),
410 select => $self->select
411 || (
412 51 ▶ ( scalar( @{ $static->select } ) ) ? $static->select
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$static->as;} ? : 0 52 52
Condition66%2/3
$self->as || (scalar @{$static->as;} ? $static->as : undef)
l!l&&r!l&&!r
2052
MC/DC50%1/2
$self->as || (scalar @{$static->as;} ? $static->as : undef)
$self->as (scalar @{$static->as;} ? $static->as : undef)
Truth table66%2/3
A || B
A= $self->asB= (scalar @{$static->as;} ? $static->as : undef)
ABresult
1X1
011
000
413 : undef
414 ),
415 as => $self->as
416 54 ▶ || ( ( scalar( @{ $static->as } ) ) ? $static->as : undef ),
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$static->grouped_by;} ? : 4 49 53
Condition81%9/11
$self->grouped_by || (scalar @{$static->grouped_by;} ? $static->grouped_by : undef)
l!l&&r!l&&!r
1449
$self->prefetch || $static->prefetch || undef
l!l
540
$self->prefetch or $static->prefetch
l!l&&r!l&&!r
5490
$self->count || $static->count
l!l&&r!l&&!r
41040
MC/DC100%2/2
$self->grouped_by || (scalar @{$static->grouped_by;} ? $static->grouped_by : undef)
$self->grouped_by (scalar @{$static->grouped_by;} ? $static->grouped_by : undef)
MC/DC0%0/2
$self->prefetch || $static->prefetch || undef
$self->prefetch $static->prefetch
MC/DC100%2/2
$self->count || $static->count
$self->count $static->count
Truth table100%3/3
A || B
A= $self->grouped_byB= (scalar @{$static->grouped_by;} ? $static->grouped_by : undef)
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $self->prefetchB= $static->prefetch
ABresult
1X1
011
000
Truth table100%3/3
A || B
A= $self->countB= $static->count
ABresult
1X1
011
000
417 prefetch => $self->prefetch || $static->prefetch || undef,
418 rows => $self->count || $static->count,
419 page => $static->page,
420 offset => $self->offset,
421 join => $self->build_joins,
422 };
423  
424 54 ▶ if ( $self->has_page ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_page) { } 4 50 54
elsif (not $self->has_page and defined $search_attributes->{'offset'} and defined $search_attributes->{'rows'}) { } 0 100 100
425 4 $search_attributes->{page} = $self->page;
426 }
427 ▶ elsif (!$self->has_page
Condition33%2/6
not $self->has_page and defined $search_attributes->{"offset"} and defined $search_attributes->{"rows"}
!ll&&!rl&&r
5000
not $self->has_page and defined $search_attributes->{"offset"}
!ll&&!rl&&r
0500
MC/DC0%0/3
not $self->has_page and defined $search_attributes->{"offset"} and defined $search_attributes->{"rows"}
not $self->has_page defined $search_attributes->{"offset"} defined $search_attributes->{"rows"}
Truth table25%1/4
not(A) and B and C
A= not $self->has_pageB= defined $search_attributes->{"offset"}C= defined $search_attributes->{"rows"}
ABCresult
0XX0
10X0
1100
1111
428 && defined( $search_attributes->{offset} )
429 && defined( $search_attributes->{rows} ) )
430 {
431 $search_attributes->{page} =
432 0 $search_attributes->{offset} / $search_attributes->{rows} + 1;
433 0 delete $search_attributes->{offset};
434 }
435  
436 $search_attributes = {
437 172 map {@$_}
438 grep {
439 defined( $_->[1] )
440 ? ( ref( $_->[1] )
441 && reftype( $_->[1] ) eq 'HASH'
442 54 ▶ && keys %{ $_->[1] } )
Condition100%6/6
ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];}
!ll&&!rl&&r
704941
ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY"
!ll&&!rl&&r
284290
MC/DC0%0/3
ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];}
ref $_->[1] builtin::reftype($_->[1]) eq "ARRAY" @{$_->[1];}
Truth table0%0/4
A and B and C
A= ref $_->[1]B= builtin::reftype($_->[1]) eq "ARRAY"C= @{$_->[1];}
ABCresult
0XX0
10X0
1100
1111
443 || ( ref( $_->[1] )
444 && reftype( $_->[1] ) eq 'ARRAY'
445 486 ▶ && @{ $_->[1] } )
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[1] ? : 172 314 486
Condition91%11/12
ref $_->[1] and builtin::reftype($_->[1]) eq "HASH" and keys %{$$_[1];} or ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];} or length $_->[1]
l!l&&r!l&&!r
531190
ref $_->[1] and builtin::reftype($_->[1]) eq "HASH" and keys %{$$_[1];} or ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];}
l!l&&r!l&&!r
1241119
ref $_->[1] and builtin::reftype($_->[1]) eq "HASH" and keys %{$$_[1];}
!ll&&!rl&&r
1184212
ref $_->[1] and builtin::reftype($_->[1]) eq "HASH"
!ll&&!rl&&r
289054
MC/DC0%0/5
ref $_->[1] and builtin::reftype($_->[1]) eq "HASH" and keys %{$$_[1];} or ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];} or length $_->[1]
ref $_->[1] builtin::reftype($_->[1]) eq "HASH" keys %{$$_[1];} ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];} length $_->[1]
Truth table10%1/10
A and B and C or D or E
A= ref $_->[1]B= builtin::reftype($_->[1]) eq "HASH"C= keys %{$$_[1];}D= ref $_->[1] and builtin::reftype($_->[1]) eq "ARRAY" and @{$_->[1];}E= length $_->[1]
ABCDEresult
111XX1
0XX1X1
10X1X1
1101X1
0XX011
10X011
110011
0XX000
10X000
110000
446 || length( $_->[1] )
447 : undef
448 }
449 54 map { [ $_, $search_attributes->{$_} ] }
450 keys %$search_attributes
451 };
452  
453 54 ▶ if ( $search_attributes->{page} && !$search_attributes->{rows} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_attributes->{"page"} and not $search_attributes->{"rows"}) 1 53 54
Condition100%3/3
$search_attributes->{"page"} and not $search_attributes->{"rows"}
!ll&&!rl&&r
40131
MC/DC100%2/2
$search_attributes->{"page"} and not $search_attributes->{"rows"}
$search_attributes->{"page"} not $search_attributes->{"rows"}
Truth table100%3/3
A and not(B)
A= $search_attributes->{"page"}B= not $search_attributes->{"rows"}
ABresult
0X0
100
111
454 1 die 'list_page can only be used with list_count';
455 }
456  
457 53 ▶ if ( $search_attributes->{select} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_attributes->{"select"}) 14 39 53
458  
459 # make sure all columns have an alias to avoid ambiguous issues
460 # but allow non strings (eg. hashrefs for db procs like 'count')
461 # to pass through unmolested
462 $search_attributes->{select} = [
463 20 ▶ map { ( Str->check($_) && $_ !~ m/\./ ) ? "me.$_" : $_ }
Branch: 2 branches
BranchTrueFalseTotal
Str()->check($_) && !($_ =~ /\./) ? : 18 2 20
ref $search_attributes->{'select'} ? : 14 0 14
Condition66%2/3
Str()->check($_) and not $_ =~ /\./
!ll&&!rl&&r
2018
MC/DC50%1/2
Str()->check($_) and not $_ =~ /\./
Str()->check($_) not $_ =~ /\./
Truth table66%2/3
A and not(B)
A= Str()->check($_)B= not $_ =~ /\./
ABresult
0X0
100
111
464 ( ref $search_attributes->{select} )
465 14 ? @{ $search_attributes->{select} }
466 : $search_attributes->{select}
467 14 ];
468 }
469  
470 53 return $search_attributes;
471  
472 32 };
473  
474 16 };
475  
476  
477 16 1;
478  
479 __END__
↑ Summary API.pm »