blib/lib/DNS/NIOS/Traits/AutoPager.pm

filter: Statementstmt 100% 39 / 39 Branchbran 70.0% 7 / 10 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 95.1% 59 / 62 SCAR 23.0
CC
10
Cov
94%
__ANON__
7.0
_is_max
4.0
BEGIN
1.0
CRAP 10.0
« blib/lib/DNS/NIOS.pm ↑ Summary blib/lib/DNS/NIOS/Response.pm »
1 #
2 # This file is part of DNS-NIOS
3 #
4 # This software is Copyright (c) 2021 by Christian Segundo.
5 #
6 # This is free software, licensed under:
7 #
8 # The Artistic License 2.0 (GPL Compatible)
9 #
10 ## no critic
11 package DNS::NIOS::Traits::AutoPager;
12 2 $DNS::NIOS::Traits::AutoPager::VERSION = '0.004';
13  
14 # ABSTRACT: Handle pagination automatically
15 # VERSION
16 # AUTHORITY
17  
18 ## use critic
19 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 requires qw( get );
24  
25 around 'get' => sub {
26 2 ▶ my ( $orig, $self, %args ) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.5
27  
28 2 my %params = (
29 _return_as_object => 1,
30 _max_results => 100,
31 _paging => 1
32 );
33  
34 2 my @responses;
35 2 ▶ my $max_results = $args{params}->{_max_results} // 0;
Condition100%2/2
$args{"params"}{"_max_results"} // 0
l!l
11
MC/DC100%1/1
$args{"params"}{"_max_results"} // 0
$args{"params"}{"_max_results"}
Truth table100%2/2
A
A= $args{"params"}{"_max_results"}
Aresult
11
00
36  
37 $args{params}
38 2 ? %{ $args{params} } =
39 2 ( %{ $args{params} }, %params )
40 2 ▶ : $args{params} = \%params;
Branch: 1 branch
BranchTrueFalseTotal
$args{'params'} ? : 2 0 2
41  
42 2 my $response = $orig->( $self, %args );
43 2 ▶ return [$response] if !$response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 2 2
44  
45 2 push( @responses, $response );
46 2 ▶ while ( $response->content->{next_page_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->content->{"next_page_id"}) 1199 1 1200
47 1199 ▶ last if $max_results and _is_max( $max_results, \@responses );
Branch: 1 branch
BranchTrueFalseTotal
if $max_results and _is_max($max_results, \@responses) 1 1198 1199
Condition100%3/3
$max_results and _is_max($max_results, \@responses)
!ll&&!rl&&r
9991991
MC/DC100%2/2
$max_results and _is_max($max_results, \@responses)
$max_results _is_max($max_results, \@responses)
Truth table100%3/3
A and B
A= $max_resultsB= _is_max($max_results, \@responses)
ABresult
0X0
100
111
48 1198 %{ $args{params} } =
49 1198 ( %{ $args{params} }, _page_id => $response->content->{next_page_id} );
50 1198 $response = $orig->( $self, %args );
51 1198 push( @responses, $response );
52 }
53  
54 2 return \@responses;
55 2 };
56  
57 sub _is_max {
58 200 ▶ my ( $max, $responses ) = @_;
Subroutine _is_max: called CC=4 SCAR=13.9
59  
60 200 my $i = 0;
61 200 foreach ( @{$responses} ) {
62 20100 foreach ( $_->{results} ) {
63 20100 ▶ last if $i >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $max 0 20100 20100
64 20100 $i++;
65 }
66 }
67 200 return $i >= $max;
68 }
69  
70 2 1;
71  
72 __END__
« blib/lib/DNS/NIOS.pm ↑ Summary blib/lib/DNS/NIOS/Response.pm »