CPAN/List.pm

filter: Statementstmt 50.4% 188 / 373 Branchbran 27.1% 57 / 210 Conditioncond 21.2% 56 / 264 MC/DCmcdc 0.7% 1 / 131 Subroutinesub 77.0% 37 / 48 Podpod 100% 32 / 32 totaltotal 35.0% 371 / 1058 CC 209 SCAR 60.8
CC
209
Cov
36%
load_data
1134.9
next
691.9
prev
478.9
CRAP 436.2
« CPAN.pm ↑ Summary CPAN/Mock.pm »
1 ##----------------------------------------------------------------------------
2 ## Meta CPAN API - ~/lib/Net/API/CPAN/List.pm
3 ## Version v0.1.1
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/08/02
7 ## Modified 2023/09/26
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package Net::API::CPAN::List;
15 BEGIN
16 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶ use parent qw( Net::API::CPAN::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶ use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶ use HTTP::Promise;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 # Elastic Search default value.
26 # See <https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-from-size.html>
27 3 DEFAULT_PAGE_SIZE => 10,
28 3 };
29 3 our $VERSION = 'v0.1.1';
30 };
31  
32 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 sub init
36 1 ▶{
Subroutine init: called CC=21 SCAR=35.6
Pod documented
37 1 my $self = CORE::shift( @_ );
38 1 ▶ $self->{api} = undef unless( CORE::exists( $self->{api} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"api"} 1 0 1
39 # The name of the JSON property containing the array reference of data
40 # This is used for data in format other than search results such as hits->hits
41 1 ▶ $self->{container} = undef unless( CORE::exists( $self->{container} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"container"} 1 0 1
42 # The full URI to the endpoint used for loading data
43 # $self->{endpoint} = undef unless( CORE::exists( $self->{endpoint} ) );
44 1 ▶ $self->{filter} = undef unless( CORE::exists( $self->{filter} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"filter"} 1 0 1
45 # Is this list a list that can load more data or is this set of data the only one available?
46 1 ▶ $self->{pageable} = 1 unless( CORE::exists( $self->{pageable} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"pageable"} 1 0 1
47 1 ▶ $self->{page} = 1 unless( CORE::exists( $self->{page} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"page"} 1 0 1
48 # Either 'from' or 'page' is used to navigate through pages of data
49 1 ▶ $self->{page_type} = 'from' unless( CORE::exists( $self->{page_type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"page_type"} 1 0 1
50 1 ▶ $self->{postprocess} = sub{$_[0]} unless( CORE::exists( $self->{postprocess} ) );
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"postprocess"} 1 0 1
51 # $self->{preprocess} = sub{$_[0]} unless( CORE::exists( $self->{preprocess} ) );
52 1 ▶ $self->{preprocess} = undef unless( CORE::exists( $self->{preprocess} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"preprocess"} 1 0 1
53 1 ▶ $self->{request} = undef unless( CORE::exists( $self->{request} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"request"} 1 0 1
54 # We use this if we are not using filters
55 1 ▶ $self->{size} = undef unless( CORE::exists( $self->{size} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"size"} 1 0 1
56 # Usually this is 'size', but sometimes it is 'page_size'
57 1 ▶ $self->{size_prop} = 'size' unless( CORE::exists( $self->{size_prop} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"size_prop"} 1 0 1
58 1 ▶ $self->{timed_out} = 0 unless( CORE::exists( $self->{timed_out} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"timed_out"} 1 0 1
59 1 ▶ $self->{took} = undef unless( CORE::exists( $self->{took} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"took"} 1 0 1
60 1 ▶ $self->{total} = undef unless( CORE::exists( $self->{total} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"total"} 1 0 1
61 1 ▶ $self->{type} = undef unless( CORE::exists( $self->{type} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"type"} 1 0 1
62 1 $self->{_init_strict_use_sub} = 1;
63 1 $self->{_init_params_order} = [qw( debug type api container preprocess postprocess total data )];
64 1 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 1 0 1
65 1 ▶ unless( CORE::exists( $self->{api} ) && $self->_is_a( $self->{api} => 'Net::API::CPAN' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"api"} and $self->_is_a($self->{"api"}, "Net::API::CPAN")) 1 0 1
Condition33%1/3
exists $self->{"api"} and $self->_is_a($self->{"api"}, "Net::API::CPAN")
!ll&&!rl&&r
010
MC/DC0%0/2
exists $self->{"api"} and $self->_is_a($self->{"api"}, "Net::API::CPAN")
exists $self->{"api"} $self->_is_a($self->{"api"}, "Net::API::CPAN")
Truth table33%1/3
A and B
A= exists $self->{"api"}B= $self->_is_a($self->{"api"}, "Net::API::CPAN")
ABresult
0X0
100
111
66 {
67 1 ▶ $self->_load_class( 'Net::API::CPAN' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Net::API::CPAN") or return $self->pass_error 1 0 1
68 1 ▶ $self->{api} = Net::API::CPAN->new( debug => $self->debug ) ||
Condition50%1/2
'Net::API::CPAN'->new('debug', $self->debug) || (return $self->pass_error('Net::API::CPAN'->error))
l!l
10
MC/DC0%0/1
'Net::API::CPAN'->new('debug', $self->debug) || (return $self->pass_error('Net::API::CPAN'->error))
'Net::API::CPAN'->new('debug', $self->debug)
Truth table50%1/2
A
A= 'Net::API::CPAN'->new('debug', $self->debug)
Aresult
11
00
69 return( $self->pass_error( Net::API::CPAN->error ) );
70 }
71 # Simple initialisation
72 1 $self->{_raw_items} = $self->new_array;
73 1 return( $self );
74 }
75  
76 3 ▶sub api { return( CORE::shift->_set_get_object( 'api', 'Net::API::CPAN', @_ ) ); }
Subroutine api: called CC=1 SCAR=0.0
Pod documented
77  
78 3 ▶sub container { return( CORE::shift->_set_get_scalar( 'container', @_ ) ); }
Subroutine container: called CC=1 SCAR=0.0
Pod documented
79  
80 sub data
81 0 ▶{
Subroutine data: not called CC=3 SCAR=24.8
Pod documented
82 0 my $self = CORE::shift( @_ );
83 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
84 {
85 0 ▶ $self->load_data( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->load_data(@_) or return $self->pass_error 0 0 0
86 }
87 0 return( $self->items );
88 }
89  
90 # sub endpoint { return( CORE::shift->_set_get_uri( 'endpoint', @_ ) ); }
91  
92 7 ▶sub filter { return( CORE::shift->_set_get_object_without_init( 'filter', 'Net::API::CPAN::Filter', @_ ) ); }
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
93  
94 sub get
95 1 ▶{
Subroutine get: called CC=6 SCAR=26.2
Pod documented
96 1 my $self = CORE::shift( @_ );
97 1 ▶ my $pos = @_ ? int( CORE::shift( @_ ) ) : ( $self->{_pos} || 0 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
Condition0%0/2
$self->{"_pos"} or 0
l!l
00
MC/DC0%0/1
$self->{"_pos"} or 0
$self->{"_pos"}
Truth table0%0/2
A
A= $self->{"_pos"}
Aresult
11
00
98 1 my $data = $self->items;
99 1 my $what = lc( Wanted::wantref );
100 1 ▶ if( !defined( $data->[ $pos ] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->[$pos]) 0 1 1
101 {
102 0 ▶ if( $what eq 'object' || $what eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "object" or $what eq "hash") 0 0 0
Condition0%0/3
$what eq "object" or $what eq "hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$what eq "object" or $what eq "hash"
$what eq "object" $what eq "hash"
Truth table0%0/3
A or B
A= $what eq "object"B= $what eq "hash"
ABresult
1X1
011
000
103 {
104 0 return( $self->new_null( type => $what ) );
105 }
106 0 return;
107 }
108 1 return( $data->[ $pos ] );
109 }
110  
111 sub has_more
112 1 ▶{
Subroutine has_more: called CC=12 SCAR=32.1
Pod documented
113 1 my $self = CORE::shift( @_ );
114 1 ▶ my $total = $self->total // 0;
Condition50%1/2
$self->total // 0
l!l
10
MC/DC0%0/1
$self->total // 0
$self->total
Truth table50%1/2
A
A= $self->total
Aresult
11
00
115 1 my( $filter, $size );
116 1 ▶ if( $filter = $self->filter )
Branch: 1 branch
BranchTrueFalseTotal
if ($filter = $self->filter) 1 0 1
117 {
118 1 $size = $filter->size;
119 }
120 # This is the default Elastic Search value
121 1 ▶ $size //= $self->size // DEFAULT_PAGE_SIZE;
Condition50%2/4
$size //= $self->size // 10
l!l
01
$self->size // 10
l!l
01
MC/DC0%0/1
$size //= $self->size // 10
$size
Truth table50%1/2
A
A= $size
Aresult
11
00
122 1 ▶ my $offset = $self->offset // 0;
Condition50%1/2
$self->offset // 0
l!l
10
MC/DC0%0/1
$self->offset // 0
$self->offset
Truth table50%1/2
A
A= $self->offset
Aresult
11
00
123 1 $self->message( 4, "\$total = $total, \$offset = $offset, \$size = $size" );
124 1 ▶ $self->message( 4, "Returning true. There is more." ) if( $total && $total > $size && ( $total - ( $offset + 1 ) > 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $total and $total > $size and $total - ($offset + 1) > 0 1 0 1
Condition33%2/6
$total and $total > $size and $total - ($offset + 1) > 0
!ll&&!rl&&r
001
$total and $total > $size
!ll&&!rl&&r
001
MC/DC0%0/3
$total and $total > $size and $total - ($offset + 1) > 0
$total $total > $size $total - ($offset + 1) > 0
Truth table25%1/4
A and B and C
A= $totalB= $total > $sizeC= $total - ($offset + 1) > 0
ABCresult
0XX0
10X0
1100
1111
125 # Do we have data and is it bigger than the page size and we are not on the last page
126 1 ▶ return(1) if( $total && $total > $size && ( $total - ( $offset + 1 ) > 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $total and $total > $size and $total - ($offset + 1) > 0 1 0 1
Condition33%2/6
$total and $total > $size and $total - ($offset + 1) > 0
!ll&&!rl&&r
001
$total and $total > $size
!ll&&!rl&&r
001
MC/DC0%0/3
$total and $total > $size and $total - ($offset + 1) > 0
$total $total > $size $total - ($offset + 1) > 0
Truth table25%1/4
A and B and C
A= $totalB= $total > $sizeC= $total - ($offset + 1) > 0
ABCresult
0XX0
10X0
1100
1111
127 0 $self->message( 4, "Returning false. There is no more data to fetch." );
128 0 return(0);
129 }
130  
131 sub items
132 8 ▶{
Subroutine items: called CC=19 SCAR=33.4
Pod documented
133 8 my $self = CORE::shift( @_ );
134 8 ▶ @_ = () if( @_ == 1 && !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and not defined $_[0] 0 8 8
Condition66%2/3
@_ == 1 and not defined $_[0]
!ll&&!rl&&r
710
MC/DC0%0/2
@_ == 1 and not defined $_[0]
@_ == 1 not defined $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
135 8 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 7 8
136 {
137 1 my $ref = CORE::shift( @_ );
138 1 my $opts = $self->_get_args_as_hash( @_ );
139 1 ▶ return( $self->error( "I was expecting an array reference, but instead got '", overload::StrVal( $ref ), "'." ) ) if( !$self->_is_array( $ref ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($ref) 0 1 1
140 1 my $cache = {};
141 1 my $api = $self->api;
142 1 my $arr = $self->new_array;
143 1 my $def_type = $self->type->scalar;
144 1 $self->message( 4, "Processing ", scalar( @$ref ), " elements with type '$def_type'" );
145 1 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 10 1 11
146 {
147 10 ▶ return( $self->error( "I was expecting an array of hash reference, but instead of an hash I found '", overload::StrVal( $ref->[$i] ), "'" ) ) if( ref( $ref->[$i] ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref->[$i] ne "HASH" 0 10 10
148 10 my $hash = $ref->[$i];
149 10 ▶ my $type = $opts->{type} || $hash->{_type} || $def_type ||
Condition37%3/8
$opts->{'type'} || $hash->{'_type'} || $def_type || (return $self->error("No object type was specified nor any could be found in the hash reference at offset $i"))
l!l
100
$opts->{"type"} or $hash->{"_type"} or $def_type
l!l&&r!l&&!r
1000
$opts->{"type"} or $hash->{"_type"}
l!l&&r!l&&!r
0100
MC/DC0%0/3
$opts->{'type'} || $hash->{'_type'} || $def_type || (return $self->error("No object type was specified nor any could be found in the hash reference at offset $i"))
$opts->{"type"} $hash->{"_type"} $def_type
Truth table25%1/4
A or B or C
A= $opts->{"type"}B= $hash->{"_type"}C= $def_type
ABCresult
1XX1
01X1
0011
0000
150 return( $self->error( "No object type was specified nor any could be found in the hash reference at offset $i" ) );
151 10 my $class;
152 10 ▶ unless( $class = $cache->{ $type } )
Branch: 1 branch
BranchTrueFalseTotal
unless ($class = $cache->{$type}) 1 9 10
153 {
154 1 ▶ $class = $self->_object_type_to_class( $type ) || return( $self->error( "Could not find corresponding class for ojbect type \"$type\"." ) );
Condition50%1/2
$self->_object_type_to_class($type) || (return $self->error(qq[Could not find corresponding class for ojbect type "$type".]))
l!l
10
MC/DC0%0/1
$self->_object_type_to_class($type) || (return $self->error(qq[Could not find corresponding class for ojbect type "$type".]))
$self->_object_type_to_class($type)
Truth table50%1/2
A
A= $self->_object_type_to_class($type)
Aresult
11
00
155 1 $self->message( 4, "Loading class $class (", overload::StrVal( $class ), ") for object type $type" );
156 1 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 1 0 1
157 1 $cache->{ $type } = $class;
158 # XXX
159 # if( $class eq 'Net::API::CPAN::List::Web::Element' )
160 # {
161 # my @symbols = $self->_list_symbols( 'Net::API::CPAN::List::Web::Element' );
162 # $self->message( 4, "Symbols found for class Net::API::CPAN::List::Web::Element are -> ", sub{ $self->Module::Generic::dump( \@symbols ) } );
163 # }
164 }
165 10 ▶ $hash = $hash->{_source} if( exists( $hash->{_source} ) && ref( $hash->{_source} ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{"_source"} and ref $hash->{"_source"} eq "HASH" 10 0 10
Condition33%1/3
exists $hash->{"_source"} and ref $hash->{"_source"} eq "HASH"
!ll&&!rl&&r
0010
MC/DC0%0/2
exists $hash->{"_source"} and ref $hash->{"_source"} eq "HASH"
exists $hash->{"_source"} ref $hash->{"_source"} eq "HASH"
Truth table33%1/3
A and B
A= exists $hash->{"_source"}B= ref $hash->{"_source"} eq "HASH"
ABresult
0X0
100
111
166 # $self->message( 4, "Instantiating a $class object at offset $i for object type $type with data: ", sub{ $self->Module::Generic::dump( $hash ) } );
167 10 $hash->{debug} = $self->debug;
168 10 ▶ my $o = $class->new( %$hash, api => $api ) || return( $self->pass_error( $class->error ) );
Condition50%1/2
$class->new(%$hash, 'api', $api) || (return $self->pass_error($class->error))
l!l
100
MC/DC0%0/1
$class->new(%$hash, 'api', $api) || (return $self->pass_error($class->error))
$class->new(%$hash, 'api', $api)
Truth table50%1/2
A
A= $class->new(%$hash, 'api', $api)
Aresult
11
00
169 10 $self->message( 4, "Adding new $class object $o (", overload::StrVal( $o ), ") to the stack." );
170 10 $arr->push( $o );
171 }
172 1 $self->{items} = $arr;
173 }
174 8 ▶ if( !$self->{items} || !$self->_is_a( $self->{items} => 'Module::Generic::Array' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"items"} and $self->_is_a($self->{"items"}, "Module::Generic::Array")) 0 8 8
Condition33%1/3
$self->{"items"} and $self->_is_a($self->{"items"}, "Module::Generic::Array")
!ll&&!rl&&r
008
MC/DC0%0/2
$self->{"items"} and $self->_is_a($self->{"items"}, "Module::Generic::Array")
$self->{"items"} $self->_is_a($self->{"items"}, "Module::Generic::Array")
Truth table33%1/3
A and B
A= $self->{"items"}B= $self->_is_a($self->{"items"}, "Module::Generic::Array")
ABresult
0X0
100
111
175 {
176 0 ▶ $self->{items} = $self->new_array( defined( $self->{items} ) ? $self->{items} : [] );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'items'} ? : 0 0 0
177 }
178 8 return( $self->{items} );
179 }
180  
181 1 ▶sub length { return( CORE::shift->items->length ); }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
182  
183 sub load
184 0 ▶{
Subroutine load: not called CC=9 SCAR=45.0
Pod documented
185 0 my $self = CORE::shift( @_ );
186 0 my $opts = $self->_get_args_as_hash( @_ );
187 my $req = $opts->{request} ||
188 0 ▶ return( $self->error( "No HTTP request was provided to load data." ) );
Condition0%0/2
$opts->{'request'} || (return $self->error('No HTTP request was provided to load data.'))
l!l
00
MC/DC0%0/1
$opts->{'request'} || (return $self->error('No HTTP request was provided to load data.'))
$opts->{'request'}
Truth table0%0/2
A
A= $opts->{'request'}
Aresult
11
00
189 0 ▶ my $api = $self->api ||
Condition0%0/2
$self->api || (return $self->error('No Net::API::CPAN obejct is currently set. This should not happen.'))
l!l
00
MC/DC0%0/1
$self->api || (return $self->error('No Net::API::CPAN obejct is currently set. This should not happen.'))
$self->api
Truth table0%0/2
A
A= $self->api
Aresult
11
00
190 return( $self->error( "No Net::API::CPAN obejct is currently set. This should not happen." ) );
191 0 ▶ my $type = $self->type ||
Condition0%0/2
$self->type || (return $self->error('No object type set for this list.'))
l!l
00
MC/DC0%0/1
$self->type || (return $self->error('No object type set for this list.'))
$self->type
Truth table0%0/2
A
A= $self->type
Aresult
11
00
192 return( $self->error( "No object type set for this list." ) );
193 0 my $filter = $self->filter;
194 0 ▶ if( $filter )
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) { } 0 0 0
195 {
196 0 ▶ return( $self->error( "No search query set." ) ) if( !$filter->query );
Branch: 1 branch
BranchTrueFalseTotal
unless $filter->query 0 0 0
197 0 ▶ my $json = $filter->as_json ||
Condition0%0/2
$filter->as_json || (return $self->pass_error($filter->error))
l!l
00
MC/DC0%0/1
$filter->as_json || (return $self->pass_error($filter->error))
$filter->as_json
Truth table0%0/2
A
A= $filter->as_json
Aresult
11
00
198 return( $self->pass_error( $filter->error ) );
199 0 $req->method( 'POST' );
200 }
201 else
202 {
203 0 $req->method( 'GET' );
204 }
205 0 $req->headers->header( Accept => 'application/json' );
206 my $data = $api->fetch( $type => {
207 request => $req,
208 # We simply want the raw data back
209 0 ▶ class => sub{ $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
210 0 ▶ }) || return( $self->pass_error( $api->error ) );
Condition0%0/2
$api->fetch($type, {'request', $req, 'class', sub { $_[0]; } }) || (return $self->pass_error($api->error))
l!l
00
MC/DC0%0/1
$api->fetch($type, {'request', $req, 'class', sub { $_[0]; } }) || (return $self->pass_error($api->error))
$api->fetch($type, {'request', $req, 'class', sub { $_[0]; } })
Truth table0%0/2
A
A= $api->fetch($type, {'request', $req, 'class', sub { $_[0]; } })
Aresult
11
00
211
212 0 ▶ $self->load_data( $data ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->load_data($data) or return $self->pass_error 0 0 0
213 0 return( $self );
214 }
215  
216 sub load_data
217 1 ▶{
Subroutine load_data: called CC=65 SCAR=70.3
Pod documented
218 1 my $self = CORE::shift( @_ );
219 1 ▶ my $data = CORE::shift( @_ ) ||
Condition50%1/2
CORE::shift @_ || (return $self->error('No data was provided to load.'))
l!l
10
MC/DC0%0/1
CORE::shift @_ || (return $self->error('No data was provided to load.'))
CORE::shift @_
Truth table50%1/2
A
A= CORE::shift @_
Aresult
11
00
220 return( $self->error( "No data was provided to load." ) );
221 1 ▶ return( $self->error( "Data provided is not an hash reference." ) ) if( ref( $data ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 1 1
222 1 $self->message( 4, "Loading data received with ", scalar( keys( %$data ) ), " properties: ", join( ', ', sort( keys( %$data ) ) ) );
223 1 my $filter = $self->filter;
224 1 my $container = $self->container;
225 1 ▶ $self->message( 4, "Container to use is '", ( $container // 'undef', ), "'" );
Condition50%1/2
$container // "undef"
l!l
01
MC/DC0%0/1
$container // "undef"
$container
Truth table50%1/2
A
A= $container
Aresult
11
00
226  
227 1 ▶ if( my $code = $self->preprocess )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->preprocess) 0 1 1
228 {
229 0 $self->message( 4, "Executing preprocess." );
230 # try-catch
231 0 local $@;
232 $data = eval
233 0 {
234 0 $code->( $data );
235 };
236 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
237 {
238 0 return( $self->error( $@ ) );
239 }
240 # $self->message( 5, "After preprocess, data now is: ", sub{ $self->Module::Generic::dump( $data ) } );
241 }
242  
243 # $ref is the variable containing the array reference of data
244 1 my( $ref, $total );
245 1 ▶ if( ( $container &&
Branch: 1 branch
BranchTrueFalseTotal
if ($container and $container eq 'hits' and exists $data->{$container} and ref $data->{$container} eq 'HASH' and exists $data->{$container}{'hits'} and ref $data->{$container}{'hits'} eq 'ARRAY' or not defined $container and exists $data->{'hits'} and ref $data->{'hits'} eq 'HASH' and exists $data->{'hits'}{'hits'} and ref $data->{'hits'}{'hits'} eq 'ARRAY') { } 1 0 1
Condition33%10/30
$container and $container eq "hits" and exists $data->{$container} and ref $data->{$container} eq "HASH" and exists $data->{$container}{"hits"} and ref $data->{$container}{"hits"} eq "ARRAY" or not defined $container and exists $data->{"hits"} and ref $data->{"hits"} eq "HASH" and exists $data->{"hits"}{"hits"} and ref $data->{"hits"}{"hits"} eq "ARRAY"
l!l&&r!l&&!r
010
$container and $container eq "hits" and exists $data->{$container} and ref $data->{$container} eq "HASH" and exists $data->{$container}{"hits"} and ref $data->{$container}{"hits"} eq "ARRAY"
!ll&&!rl&&r
100
$container and $container eq "hits" and exists $data->{$container} and ref $data->{$container} eq "HASH" and exists $data->{$container}{"hits"}
!ll&&!rl&&r
100
$container and $container eq "hits" and exists $data->{$container} and ref $data->{$container} eq "HASH"
!ll&&!rl&&r
100
$container and $container eq "hits" and exists $data->{$container}
!ll&&!rl&&r
100
$container and $container eq "hits"
!ll&&!rl&&r
100
not defined $container and exists $data->{"hits"} and ref $data->{"hits"} eq "HASH" and exists $data->{"hits"}{"hits"} and ref $data->{"hits"}{"hits"} eq "ARRAY"
!ll&&!rl&&r
001
not defined $container and exists $data->{"hits"} and ref $data->{"hits"} eq "HASH" and exists $data->{"hits"}{"hits"}
!ll&&!rl&&r
001
not defined $container and exists $data->{"hits"} and ref $data->{"hits"} eq "HASH"
!ll&&!rl&&r
001
not defined $container and exists $data->{"hits"}
!ll&&!rl&&r
001
MC/DC0%0/11
$container and $container eq "hits" and exists $data->{$container} and ref $data->{$container} eq "HASH" and exists $data->{$container}{"hits"} and ref $data->{$container}{"hits"} eq "ARRAY" or not defined $container and exists $data->{"hits"} and ref $data->{"hits"} eq "HASH" and exists $data->{"hits"}{"hits"} and ref $data->{"hits"}{"hits"} eq "ARRAY"
$container $container eq "hits" exists $data->{$container} ref $data->{$container} eq "HASH" exists $data->{$container}{"hits"} ref $data->{$container}{"hits"} eq "ARRAY" not defined $container exists $data->{"hits"} ref $data->{"hits"} eq "HASH" exists $data->{"hits"}{"hits"} ref $data->{"hits"}{"hits"} eq "ARRAY"
Truth table2%1/37
A and B and C and D and E and F or not(G) and H and I and J and K
A= $containerB= $container eq "hits"C= exists $data->{$container}D= ref $data->{$container} eq "HASH"E= exists $data->{$container}{"hits"}F= ref $data->{$container}{"hits"} eq "ARRAY"G= not defined $containerH= exists $data->{"hits"}I= ref $data->{"hits"} eq "HASH"J= exists $data->{"hits"}{"hits"}K= ref $data->{"hits"}{"hits"} eq "ARRAY"
ABCDEFGHIJKresult
111111XXXXX1
0XXXXX111111
10XXXX111111
110XXX111111
1110XX111111
11110X111111
111110111111
0XXXXX0XXXX0
0XXXXX10XXX0
0XXXXX110XX0
0XXXXX1110X0
0XXXXX111100
10XXXX0XXXX0
10XXXX10XXX0
10XXXX110XX0
10XXXX1110X0
10XXXX111100
110XXX0XXXX0
110XXX10XXX0
110XXX110XX0
110XXX1110X0
110XXX111100
1110XX0XXXX0
1110XX10XXX0
1110XX110XX0
1110XX1110X0
1110XX111100
11110X0XXXX0
11110X10XXX0
11110X110XX0
11110X1110X0
11110X111100
1111100XXXX0
11111010XXX0
111110110XX0
1111101110X0
111110111100
246 $container eq 'hits' &&
247 exists( $data->{ $container } ) &&
248 ref( $data->{ $container } ) eq 'HASH' &&
249 exists( $data->{ $container }->{hits} ) &&
250 ref( $data->{ $container }->{hits} ) eq 'ARRAY'
251 ) ||
252 ( !defined( $container ) &&
253 exists( $data->{hits} ) &&
254 ref( $data->{hits} ) eq 'HASH' &&
255 exists( $data->{hits}->{hits} ) &&
256 ref( $data->{hits}->{hits} ) eq 'ARRAY'
257 ) )
258 {
259 1 $self->message( 4, "Guessed container to be 'hits->hits'" );
260 1 ▶ unless( defined( $container ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $container) 1 0 1
261 {
262 1 $self->container( $container = 'hits' );
263 }
264 1 ▶ if( !exists( $data->{hits} ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $data->{'hits'} && defined $data->{'hits'} or ref $data->{'hits'} ne 'HASH') { } 0 1 1
elsif (not exists $data->{'hits'}{'hits'} && defined $data->{'hits'}{'hits'} or ref $data->{'hits'}{'hits'} ne 'ARRAY') { } 0 1 1
Condition33%2/6
not exists $data->{"hits"} && defined $data->{"hits"} or ref $data->{"hits"} ne "HASH"
l!l&&r!l&&!r
001
exists $data->{'hits'} && defined $data->{'hits'}
!ll&&!rl&&r
001
MC/DC0%0/3
not exists $data->{"hits"} && defined $data->{"hits"} or ref $data->{"hits"} ne "HASH"
exists $data->{'hits'} defined $data->{'hits'} ref $data->{"hits"} ne "HASH"
Truth table25%1/4
not(A && B) or C
A= exists $data->{'hits'}B= defined $data->{'hits'}C= ref $data->{"hits"} ne "HASH"
ABCresult
0XX1
10X1
1111
1100
265 !defined( $data->{hits} ) ||
266 ref( $data->{hits} ) ne 'HASH' )
267 {
268 # return( $self->error( "Malformed data received. I was expecting a top property 'hits' to be an hash reference." ) );
269 # Actually not necessarily an error, but simply no more data
270 0 $self->items->reset;
271 }
272 ▶ elsif( !exists( $data->{hits}->{hits} ) ||
Condition33%2/6
not exists $data->{"hits"}{"hits"} && defined $data->{"hits"}{"hits"} or ref $data->{"hits"}{"hits"} ne "ARRAY"
l!l&&r!l&&!r
001
exists $data->{'hits'}{'hits'} && defined $data->{'hits'}{'hits'}
!ll&&!rl&&r
001
MC/DC0%0/3
not exists $data->{"hits"}{"hits"} && defined $data->{"hits"}{"hits"} or ref $data->{"hits"}{"hits"} ne "ARRAY"
exists $data->{'hits'}{'hits'} defined $data->{'hits'}{'hits'} ref $data->{"hits"}{"hits"} ne "ARRAY"
Truth table25%1/4
not(A && B) or C
A= exists $data->{'hits'}{'hits'}B= defined $data->{'hits'}{'hits'}C= ref $data->{"hits"}{"hits"} ne "ARRAY"
ABCresult
0XX1
10X1
1111
1100
273 !defined( $data->{hits}->{hits} ) ||
274 ref( $data->{hits}->{hits} ) ne 'ARRAY' )
275 {
276 # return( $self->error( "Malformed data received. I was expecting the property 'hits' within the top property 'hits' to be an array reference." ) );
277 # Actually not necessarily an error, but simply no more data
278 0 $self->items->reset;
279 }
280 else
281 {
282 1 $ref = $data->{hits}->{hits};
283 # The overall number of hits
284 1 ▶ if( exists( $data->{hits}->{total} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'hits'}{'total'} and defined $data->{'hits'}{'total'} and CORE::length $data->{'hits'}{'total'}) { } 1 0 1
Condition33%2/6
exists $data->{"hits"}{"total"} and defined $data->{"hits"}{"total"} and CORE::length $data->{"hits"}{"total"}
!ll&&!rl&&r
001
exists $data->{"hits"}{"total"} and defined $data->{"hits"}{"total"}
!ll&&!rl&&r
001
MC/DC0%0/3
exists $data->{"hits"}{"total"} and defined $data->{"hits"}{"total"} and CORE::length $data->{"hits"}{"total"}
exists $data->{"hits"}{"total"} defined $data->{"hits"}{"total"} CORE::length $data->{"hits"}{"total"}
Truth table25%1/4
A and B and C
A= exists $data->{"hits"}{"total"}B= defined $data->{"hits"}{"total"}C= CORE::length $data->{"hits"}{"total"}
ABCresult
0XX0
10X0
1100
1111
285 defined( $data->{hits}->{total} ) &&
286 CORE::length( $data->{hits}->{total} ) )
287 {
288 1 $self->message( 4, "Setting total value using hits->total (", $data->{hits}->{total}, ")" );
289 # $self->total( $data->{hits}->{total} );
290 1 $total = $data->{hits}->{total};
291 }
292 # If the information is not available somehow, use the size of the array
293 else
294 {
295 0 $self->message( 4, "Setting total value using items->length (", $self->items->length, ")" );
296 # $self->total( $self->items->length );
297 0 $total = $self->items->length;
298 }
299 }
300 }
301 else
302 {
303 0 $self->message( 4, "Container is not hits->hits, trying to find the first property with an array." );
304 0 ▶ unless( $container = $self->container )
Branch: 1 branch
BranchTrueFalseTotal
unless ($container = $self->container) 0 0 0
305 {
306 0 foreach my $prop ( keys( %$data ) )
307 {
308 0 ▶ if( defined( $data->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{$prop} and ref $data->{$prop} eq "ARRAY") 0 0 0
Condition0%0/3
defined $data->{$prop} and ref $data->{$prop} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data->{$prop} and ref $data->{$prop} eq "ARRAY"
defined $data->{$prop} ref $data->{$prop} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $data->{$prop}B= ref $data->{$prop} eq "ARRAY"
ABresult
0X0
100
111
309 ref( $data->{ $prop } ) eq 'ARRAY' )
310 {
311 0 $container = $prop;
312 0 $self->message( 4, "Found the container being the property '$prop'" );
313 # Save it for next time
314 0 $self->container( $container );
315 0 last;
316 }
317 }
318 }
319
320 0 ▶ if( !defined( $container ) )
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $container) { } 0 0 0
elsif (not exists $data->{$container}) { } 0 0 0
elsif (not defined $data->{$container}) { } 0 0 0
elsif (ref $data->{$container} ne 'ARRAY') { } 0 0 0
321 {
322 0 return( $self->error( "No data container name was specified and none could be found in the data provided." ) );
323 }
324 elsif( !exists( $data->{ $container } ) )
325 {
326 0 return( $self->error( "Data container specified '$container' does not exist in the data provided." ) );
327 }
328 # There is simply no data. Admittedly it would be better if it was defined and an empty array
329 elsif( !defined( $data->{ $container } ) )
330 {
331 0 $ref = [];
332 }
333 elsif( ref( $data->{ $container } ) ne 'ARRAY' )
334 {
335 0 ▶ return( $self->error( "Data container specified '$container' does not point to an array reference, but to a '", ( ref( $data->{ $container } ) // 'string' ), "'." ) );
Condition0%0/2
ref $data->{$container} // "string"
l!l
00
MC/DC0%0/1
ref $data->{$container} // "string"
ref $data->{$container}
Truth table0%0/2
A
A= ref $data->{$container}
Aresult
11
00
336 }
337 else
338 {
339 0 $ref = $data->{ $container };
340 }
341
342 # Like for some release data, such as /all_by_author
343 0 ▶ $total = $data->{total} if( exists( $data->{total} ) && CORE::length( $data->{total} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"total"} and CORE::length($data->{"total"} // "") 0 0 0
Condition0%0/5
exists $data->{"total"} and CORE::length($data->{"total"} // "")
!ll&&!rl&&r
000
$data->{"total"} // ""
l!l
00
MC/DC0%0/2
exists $data->{"total"} and CORE::length($data->{"total"} // "")
exists $data->{"total"} $data->{"total"}
Truth table0%0/3
A and B
A= exists $data->{"total"}B= $data->{"total"}
ABresult
0X0
100
111
344 }
345  
346 1 ▶ if( defined( $ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) { } 1 0 1
347 {
348 1 $self->message( 4, "Container contains ", scalar( @$ref ), " ", $self->type, " elements." );
349 # We take steps to ensure the data we received is not the same as the data we already have
350 1 my $new_items = $self->new_array( $ref );
351 1 ▶ my $old_items = $self->{_raw_items} // $self->new_array;
Condition33%1/3
$self->{"_raw_items"} // $self->new_array
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"_raw_items"} // $self->new_array
$self->{"_raw_items"} $self->new_array
Truth table33%1/3
A // B
A= $self->{"_raw_items"}B= $self->new_array
ABresult
1X1
011
000
352 0 ▶ $self->message( 5, "Old items are -> ", sub{ $self->Module::Generic::dump( $old_items ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
353 # Set the size of the number of elements per page, so we can rely on it, even if the array is modified afterwards
354 # unless( defined( $filter->size ) )
355 # {
356 # $filter->size( $new_items->length );
357 # }
358 # Set the value for 'type' for our object if it was not set already by the user.
359 # It should already have been set if there was an API call, but not necessarily if the data were simply and directly loaded here.
360 1 ▶ if( !$self->type &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->type and scalar @$new_items and ref $new_items->[0] eq "HASH" and exists $new_items->[0]{"_type"} and CORE::length($new_items->[0]{"_type"} // "")) 1 0 1
Condition38%5/13
not $self->type and scalar @$new_items and ref $new_items->[0] eq "HASH" and exists $new_items->[0]{"_type"} and CORE::length($new_items->[0]{"_type"} // "")
!ll&&!rl&&r
001
not $self->type and scalar @$new_items and ref $new_items->[0] eq "HASH" and exists $new_items->[0]{"_type"}
!ll&&!rl&&r
001
not $self->type and scalar @$new_items and ref $new_items->[0] eq "HASH"
!ll&&!rl&&r
001
not $self->type and scalar @$new_items
!ll
01
$new_items->[0]{"_type"} // ""
l!l
10
MC/DC0%0/4
not $self->type and scalar @$new_items and ref $new_items->[0] eq "HASH" and exists $new_items->[0]{"_type"} and CORE::length($new_items->[0]{"_type"} // "")
not $self->type ref $new_items->[0] eq "HASH" exists $new_items->[0]{"_type"} $new_items->[0]{"_type"}
Truth table20%1/5
not(A) and B and C and D
A= not $self->typeB= ref $new_items->[0] eq "HASH"C= exists $new_items->[0]{"_type"}D= $new_items->[0]{"_type"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
361 scalar( @$new_items ) &&
362 ref( $new_items->[0] ) eq 'HASH' &&
363 exists( $new_items->[0]->{_type} ) &&
364 CORE::length( $new_items->[0]->{_type} // '' ) )
365 {
366 1 $self->type( $new_items->[0]->{_type} );
367 }
368
369 1 ▶ if( !$new_items->is_empty &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $new_items->is_empty || $old_items->is_empty and ref $new_items->first eq 'HASH' and ref $old_items->first eq 'HASH') { } 0 1 1
Condition33%3/9
not $new_items->is_empty || $old_items->is_empty and ref $new_items->first eq "HASH" and ref $old_items->first eq "HASH"
!ll&&!rl&&r
100
not $new_items->is_empty || $old_items->is_empty and ref $new_items->first eq "HASH"
!ll&&!rl&&r
100
$new_items->is_empty || $old_items->is_empty
l!l&&r!l&&!r
010
MC/DC0%0/4
not $new_items->is_empty || $old_items->is_empty and ref $new_items->first eq "HASH" and ref $old_items->first eq "HASH"
$new_items->is_empty $old_items->is_empty ref $new_items->first eq "HASH" ref $old_items->first eq "HASH"
Truth table20%1/5
not(A || B) and C and D
A= $new_items->is_emptyB= $old_items->is_emptyC= ref $new_items->first eq "HASH"D= ref $old_items->first eq "HASH"
ABCDresult
1XXX0
01XX0
000X0
00100
00111
370 !$old_items->is_empty &&
371 ref( $new_items->first ) eq 'HASH' &&
372 ref( $old_items->first ) eq 'HASH' )
373 {
374 0 my $json = $self->new_json->canonical;
375 0 my $new_first = $new_items->first;
376 0 my $old_first = $old_items->first;
377 0 my( $new_serial, $old_serial );
378 0 local $@;
379 # try-catch
380 eval
381 0 {
382 0 $new_serial = $json->encode( $new_first );
383 0 $old_serial = $json->encode( $old_first );
384 };
385 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
386 {
387 0 return( $self->error( "Error serialising hash reference into JSON data: $@" ) );
388 }
389  
390 # old and new data are the same. We cannot have that,
391 # so we set an empty data pool
392 0 ▶ if( defined( $new_serial ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_serial and defined $old_serial and $new_serial eq $old_serial) { } 0 0 0
Condition0%0/6
defined $new_serial and defined $old_serial and $new_serial eq $old_serial
!ll&&!rl&&r
000
defined $new_serial and defined $old_serial
!ll&&!rl&&r
000
MC/DC0%0/3
defined $new_serial and defined $old_serial and $new_serial eq $old_serial
defined $new_serial defined $old_serial $new_serial eq $old_serial
Truth table0%0/4
A and B and C
A= defined $new_serialB= defined $old_serialC= $new_serial eq $old_serial
ABCresult
0XX0
10X0
1100
1111
393 defined( $old_serial ) &&
394 $new_serial eq $old_serial )
395 {
396 0 $self->items->reset;
397 }
398 else
399 {
400 0 $self->items( $ref );
401 0 $self->{_raw_items} = $self->new_array( Clone::clone( $ref ) );
402 }
403 }
404 # Ok, old and new data are not the same
405 else
406 {
407 1 $self->items( $ref );
408 1 $self->{_raw_items} = $self->new_array( Clone::clone( $ref ) );
409 }
410
411 # If the information is not available somehow, use the size of the array
412 1 ▶ $self->total( $total // $self->items->length );
Condition33%1/3
$total // $self->items->length
l!l&&r!l&&!r
100
MC/DC0%0/2
$total // $self->items->length
$total $self->items->length
Truth table33%1/3
A // B
A= $totalB= $self->items->length
ABresult
1X1
011
000
413 # If it was already set the first time, we do not overwrite it.
414 # This is used so we can compute next page offset
415 1 ▶ unless( $self->page_size )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->page_size) 1 0 1
416 {
417 1 $self->page_size( $self->items->length );
418 }
419 }
420 else
421 {
422 0 return( $self->error( "No data found for container '$container'" ) );
423 }
424
425 1 ▶ if( exists( $data->{timed_out} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'timed_out'} and defined $data->{'timed_out'} and CORE::length $data->{'timed_out'}) { } 1 0 1
Condition33%2/6
exists $data->{"timed_out"} and defined $data->{"timed_out"} and CORE::length $data->{"timed_out"}
!ll&&!rl&&r
001
exists $data->{"timed_out"} and defined $data->{"timed_out"}
!ll&&!rl&&r
001
MC/DC0%0/3
exists $data->{"timed_out"} and defined $data->{"timed_out"} and CORE::length $data->{"timed_out"}
exists $data->{"timed_out"} defined $data->{"timed_out"} CORE::length $data->{"timed_out"}
Truth table25%1/4
A and B and C
A= exists $data->{"timed_out"}B= defined $data->{"timed_out"}C= CORE::length $data->{"timed_out"}
ABCresult
0XX0
10X0
1100
1111
426 defined( $data->{timed_out} ) &&
427 CORE::length( $data->{timed_out} ) )
428 {
429 1 $self->timed_out( $data->{timed_out} );
430 }
431 else
432 {
433 0 $self->timed_out(0);
434 }
435
436 1 ▶ if( exists( $data->{took} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'took'} and defined $data->{'took'} and CORE::length $data->{'took'}) { } 1 0 1
Condition33%2/6
exists $data->{"took"} and defined $data->{"took"} and CORE::length $data->{"took"}
!ll&&!rl&&r
001
exists $data->{"took"} and defined $data->{"took"}
!ll&&!rl&&r
001
MC/DC0%0/3
exists $data->{"took"} and defined $data->{"took"} and CORE::length $data->{"took"}
exists $data->{"took"} defined $data->{"took"} CORE::length $data->{"took"}
Truth table25%1/4
A and B and C
A= exists $data->{"took"}B= defined $data->{"took"}C= CORE::length $data->{"took"}
ABCresult
0XX0
10X0
1100
1111
437 defined( $data->{took} ) &&
438 CORE::length( $data->{took} ) )
439 {
440 1 $self->took( $data->{took} );
441 }
442 else
443 {
444 0 $self->took(undef);
445 }
446 # Reset the array position
447 1 delete( $self->{_pos} );
448
449 1 ▶ if( my $code = $self->postprocess )
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->postprocess) 1 0 1
450 {
451 1 $self->message( 4, "Executing postprocess." );
452 # try-catch
453 1 local $@;
454 eval
455 1 {
456 1 $code->( $data );
457 };
458 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
459 {
460 0 return( $self->error( $@ ) );
461 }
462 }
463 1 return( $self );
464 }
465  
466 sub next
467 2 ▶{
Subroutine next: called CC=30 SCAR=65.4
Pod documented
468 2 my $self = CORE::shift( @_ );
469 2 ▶ $self->{_pos} = -1 if( !exists( $self->{_pos} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_pos"} 1 1 2
470 2 my $data = $self->items;
471 2 my $what = lc( Wanted::wantref );
472 2 my $val;
473 # if( $self->{_pos} + 1 < $data->length )
474 # {
475 2 $val = $data->[ ++$self->{_pos} ];
476 # }
477
478 2 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 2 2
479 {
480 # Our offset exceeds the size of our data pool and we have more data, so let's fetch some more
481 0 ▶ if( $self->{_pos} > $data->size && $self->has_more )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_pos"} > $data->size and $self->has_more) 0 0 0
Condition0%0/3
$self->{"_pos"} > $data->size and $self->has_more
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_pos"} > $data->size and $self->has_more
$self->{"_pos"} > $data->size $self->has_more
Truth table0%0/3
A and B
A= $self->{"_pos"} > $data->sizeB= $self->has_more
ABresult
0X0
100
111
482 {
483 0 ▶ my $req = $self->request ||
Condition0%0/2
$self->request || (return $self->error('No initial HTTP request was provided to load data.'))
l!l
00
MC/DC0%0/1
$self->request || (return $self->error('No initial HTTP request was provided to load data.'))
$self->request
Truth table0%0/2
A
A= $self->request
Aresult
11
00
484 return( $self->error( "No initial HTTP request was provided to load data." ) );
485 0 $req = $req->clone;
486 0 my $filter = $self->filter;
487 # Starting from 1
488 0 ▶ my $page = $self->page // 1;
Condition0%0/2
$self->page // 1
l!l
00
MC/DC0%0/1
$self->page // 1
$self->page
Truth table0%0/2
A
A= $self->page
Aresult
11
00
489 0 my $size;
490 0 ▶ if( $filter )
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) { } 0 0 0
491 {
492 0 ▶ return( $self->error( "No search query set." ) ) if( !$filter->query );
Branch: 1 branch
BranchTrueFalseTotal
unless $filter->query 0 0 0
493 # 10 is Elastic Search default size
494 0 $size = $filter->size;
495 0 ▶ if( defined( $size ) && !$size )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size and not $size) 0 0 0
Condition0%0/3
defined $size and not $size
!ll&&!rl&&r
000
MC/DC0%0/2
defined $size and not $size
defined $size not $size
Truth table0%0/3
A and not(B)
A= defined $sizeB= not $size
ABresult
0X0
100
111
496 {
497 0 ▶ $size = $self->size // DEFAULT_PAGE_SIZE;
Condition0%0/2
$self->size // 10
l!l
00
MC/DC0%0/1
$self->size // 10
$self->size
Truth table0%0/2
A
A= $self->size
Aresult
11
00
498 0 $filter->size( $size );
499 }
500 0 $filter->from( int( ( $page - 1 ) * $size ) );
501 }
502 else
503 {
504 0 $self->message( 5, "Original query URL is ", $req->uri );
505 0 my $query = $req->uri->query_form_hash;
506 0 ▶ if( !scalar( keys( %$query ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$query and exists $query->{"page"} || exists $query->{"from"} || exists $query->{"size"}) 0 0 0
Condition0%0/9
scalar keys %$query and exists $query->{"page"} || exists $query->{"from"} || exists $query->{"size"}
!ll&&!rl&&r
000
exists $query->{"page"} or exists $query->{"from"} or exists $query->{"size"}
l!l&&r!l&&!r
000
exists $query->{"page"} or exists $query->{"from"}
l!l&&r!l&&!r
000
MC/DC0%0/4
scalar keys %$query and exists $query->{"page"} || exists $query->{"from"} || exists $query->{"size"}
scalar keys %$query exists $query->{"page"} exists $query->{"from"} exists $query->{"size"}
Truth table0%0/5
A and B or C or D
A= scalar keys %$queryB= exists $query->{"page"}C= exists $query->{"from"}D= exists $query->{"size"}
ABCDresult
0XXX0
10000
11XX1
101X1
10011
507 ( !exists( $query->{page} ) && !exists( $query->{from} ) && !exists( $query->{size} ) ) )
508 {
509 # return( $self->error( "No search query set." ) );
510 }
511 0 $size = $self->size;
512 # If size option is set, otherwise we leave it out
513 0 ▶ if( defined( $size ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) 0 0 0
514 {
515 0 ▶ $size //= DEFAULT_PAGE_SIZE;
Condition0%0/2
$size //= 10
l!l
00
MC/DC0%0/1
$size //= 10
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
516 0 ▶ my $size_prop = $self->size_prop // 'size';
Condition0%0/2
$self->size_prop // "size"
l!l
00
MC/DC0%0/1
$self->size_prop // "size"
$self->size_prop
Truth table0%0/2
A
A= $self->size_prop
Aresult
11
00
517 0 $query->{ $size_prop } = $size;
518 }
519 0 ▶ my $page_type = $self->page_type || 'from';
Condition0%0/2
$self->page_type || 'from'
l!l
00
MC/DC0%0/1
$self->page_type || 'from'
$self->page_type
Truth table0%0/2
A
A= $self->page_type
Aresult
11
00
520 0 ▶ $self->message( 4, "Page is '", ( $page // 'undef' ), "' size is '", ( $size // 'undef' ), "', page_type is '", ( $page_type // 'undef' ), "'" );
Condition0%0/6
$page // "undef"
l!l
00
$size // "undef"
l!l
00
$page_type // "undef"
l!l
00
MC/DC0%0/1
$page // "undef"
$page
MC/DC0%0/1
$size // "undef"
$size
MC/DC0%0/1
$page_type // "undef"
$page_type
Truth table0%0/2
A
A= $page
Aresult
11
00
Truth table0%0/2
A
A= $size
Aresult
11
00
Truth table0%0/2
A
A= $page_type
Aresult
11
00
521 0 ▶ if( $page_type eq 'from' )
Branch: 2 branches
BranchTrueFalseTotal
if ($page_type eq 'from') { } 0 0 0
elsif ($page_type eq 'page') { } 0 0 0
522 {
523 0 ▶ my $page_size = $size // $self->page_size;
Condition0%0/3
$size // $self->page_size
l!l&&r!l&&!r
000
MC/DC0%0/2
$size // $self->page_size
$size $self->page_size
Truth table0%0/3
A // B
A= $sizeB= $self->page_size
ABresult
1X1
011
000
524 # 0..9 or 10..19
525 0 my $offset = int( ( $page - 1 ) * $page_size );
526 0 $self->message( 4, "Offset is '$offset'" );
527 0 $query->{from} = $offset;
528 }
529 elsif( $page_type eq 'page' )
530 {
531 0 $query->{page} = ( $page + 1 );
532 }
533 else
534 {
535 0 return( $self->error( "Unknown page type '$page_type'" ) );
536 }
537 0 ▶ $self->message( 4, "Setting new query with hash -> ", sub{ $self->dump( $query ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
538 0 $req->uri->query_form( $query );
539 0 $self->message( 4, "Using URI for next load of data -> ", $req->uri );
540 }
541
542 # User will need to check if there is an error if the user gets an undefined value in return,
543 # to distinguish between no more value vs a returned error
544 0 ▶ $self->load( request => $req ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->load("request", $req) or return $self->pass_error 0 0 0
545 # We set our current page to +1 if indeed we have data.
546 0 ▶ $self->page( $page + 1 ) if( !$self->items->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->items->is_empty 0 0 0
547 0 return( $self->next );
548 }
549
550 0 ▶ if( $what eq 'object' || $what eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "object" or $what eq "hash") 0 0 0
Condition0%0/3
$what eq "object" or $what eq "hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$what eq "object" or $what eq "hash"
$what eq "object" $what eq "hash"
Truth table0%0/3
A or B
A= $what eq "object"B= $what eq "hash"
ABresult
1X1
011
000
551 {
552 0 return( $self->new_null( type => $what ) );
553 }
554 0 return;
555 }
556 2 return( $val );
557 }
558  
559 sub offset
560 3 ▶{
Subroutine offset: called CC=6 SCAR=18.8
Pod documented
561 3 my $self = CORE::shift( @_ );
562 3 ▶ my $page = $self->page // 1;
Condition50%1/2
$self->page // 1
l!l
30
MC/DC0%0/1
$self->page // 1
$self->page
Truth table50%1/2
A
A= $self->page
Aresult
11
00
563 3 my( $size, $filter );
564 3 ▶ if( $filter = $self->filter )
Branch: 1 branch
BranchTrueFalseTotal
if ($filter = $self->filter) 3 0 3
565 {
566 3 $size = $filter->size;
567 }
568 # $size //= $self->page_size // DEFAULT_PAGE_SIZE;
569 3 ▶ $size ||= $self->page_size || DEFAULT_PAGE_SIZE;
Condition40%2/5
$size ||= $self->page_size || 10
l!l&&r!l&&!r
030
$self->page_size || 10
l!l
30
MC/DC0%0/2
$size ||= $self->page_size || 10
$size $self->page_size
Truth table33%1/3
A ||= B
A= $sizeB= $self->page_size
ABresult
1X1
011
000
570 3 ▶ my $pos = $self->pos // 0;
Condition100%2/2
$self->pos // 0
l!l
21
MC/DC100%1/1
$self->pos // 0
$self->pos
Truth table100%2/2
A
A= $self->pos
Aresult
11
00
571 3 $self->message( 4, "Calculating offset using page '$page', size '$size' and pos '$pos' -> ", ( $pos + ( $size * ( $page - 1 ) ) ) );
572 3 return( $self->new_number( $pos + ( $size * ( $page - 1 ) ) ) );
573 }
574  
575 4 ▶sub page { return( CORE::shift->_set_get_number( 'page', @_ ) ); }
Subroutine page: called CC=1 SCAR=0.0
Pod documented
576  
577 0 ▶sub pageable { return( CORE::shift->_set_get_number( 'pageable', @_ ) ); }
Subroutine pageable: not called CC=1 SCAR=6.9
Pod documented
578  
579 5 ▶sub page_size { return( CORE::shift->_set_get_number( 'page_size', @_ ) ); }
Subroutine page_size: called CC=1 SCAR=0.0
Pod documented
580  
581 1 ▶sub page_type { return( shift->_set_get_scalar_as_object( 'page_type', @_ ) ); }
Subroutine page_type: called CC=1 SCAR=0.0
Pod documented
582  
583 sub pop
584 0 ▶{
Subroutine pop: not called CC=4 SCAR=30.0
Pod documented
585 0 my $self = CORE::shift( @_ );
586 0 my $data = $self->items;
587 0 my $what = lc( Wanted::wantref );
588 0 my $val = $self->items->pop;
589  
590 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
591 {
592 0 ▶ if( $what eq 'object' || $what eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "object" or $what eq "hash") 0 0 0
Condition0%0/3
$what eq "object" or $what eq "hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$what eq "object" or $what eq "hash"
$what eq "object" $what eq "hash"
Truth table0%0/3
A or B
A= $what eq "object"B= $what eq "hash"
ABresult
1X1
011
000
593 {
594 0 return( $self->new_null( type => $what ) );
595 }
596 0 return;
597 }
598 0 return( $val );
599 }
600  
601 4 ▶sub pos { return( CORE::shift->{_pos} ); }
Subroutine pos: called CC=1 SCAR=0.0
Pod documented
602  
603 1 ▶sub preprocess { return( CORE::shift->_set_get_code( 'preprocess', @_ ) ); }
Subroutine preprocess: called CC=1 SCAR=0.0
Pod documented
604  
605 2 ▶sub postprocess { return( CORE::shift->_set_get_code( 'postprocess', @_ ) ); }
Subroutine postprocess: called CC=1 SCAR=0.0
Pod documented
606  
607 sub prev
608 1 ▶{
Subroutine prev: called CC=26 SCAR=61.7
Pod documented
609 1 my $self = CORE::shift( @_ );
610 1 ▶ $self->{_pos} = -1 if( !exists( $self->{_pos} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_pos"} 0 1 1
611 1 my $data = $self->items;
612 1 my $what = lc( Wanted::wantref );
613 1 my $val;
614 1 ▶ if( $self->{_pos} - 1 >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_pos"} - 1 >= 0) 1 0 1
615 {
616 1 $val = $data->[ --$self->{_pos} ];
617 }
618  
619 1 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 1 1
620 {
621 # Starting from 1
622 0 ▶ my $page = $self->page // 1;
Condition0%0/2
$self->page // 1
l!l
00
MC/DC0%0/1
$self->page // 1
$self->page
Truth table0%0/2
A
A= $self->page
Aresult
11
00
623 0 ▶ if( $self->{_pos} <= 0 && $page > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_pos"} <= 0 and $page > 1) 0 0 0
Condition0%0/3
$self->{"_pos"} <= 0 and $page > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_pos"} <= 0 and $page > 1
$self->{"_pos"} <= 0 $page > 1
Truth table0%0/3
A and B
A= $self->{"_pos"} <= 0B= $page > 1
ABresult
0X0
100
111
624 {
625 0 ▶ my $req = $self->request ||
Condition0%0/2
$self->request || (return $self->error('No initial HTTP request was provided to load data.'))
l!l
00
MC/DC0%0/1
$self->request || (return $self->error('No initial HTTP request was provided to load data.'))
$self->request
Truth table0%0/2
A
A= $self->request
Aresult
11
00
626 return( $self->error( "No initial HTTP request was provided to load data." ) );
627 0 $req = $req->clone;
628 0 my $filter = $self->filter;
629 # Next page
630 0 $page--;
631 0 my $size;
632 0 ▶ if( $filter )
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) { } 0 0 0
633 {
634 0 ▶ return( $self->error( "No search query set." ) ) if( !$filter->query );
Branch: 1 branch
BranchTrueFalseTotal
unless $filter->query 0 0 0
635 # 10 is Elastic Search default size
636 0 $size = $filter->size;
637 0 ▶ if( defined( $size ) && !$size )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size and not $size) 0 0 0
Condition0%0/3
defined $size and not $size
!ll&&!rl&&r
000
MC/DC0%0/2
defined $size and not $size
defined $size not $size
Truth table0%0/3
A and not(B)
A= defined $sizeB= not $size
ABresult
0X0
100
111
638 {
639 0 ▶ $size = $self->size // DEFAULT_PAGE_SIZE;
Condition0%0/2
$self->size // 10
l!l
00
MC/DC0%0/1
$self->size // 10
$self->size
Truth table0%0/2
A
A= $self->size
Aresult
11
00
640 0 $filter->size( $size );
641 }
642 0 $filter->from( int( ( $page - 1 ) * $size ) );
643 }
644 else
645 {
646 0 my $query = $req->uri->query_form_hash;
647 0 ▶ return( $self->error( "No search query set." ) ) if( !scalar( keys( %$query ) ) || !CORE::length( $query->{'q'} // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$query and CORE::length($query->{"q"} // "") 0 0 0
Condition0%0/5
scalar keys %$query and CORE::length($query->{"q"} // "")
!ll&&!rl&&r
000
$query->{"q"} // ""
l!l
00
MC/DC0%0/2
scalar keys %$query and CORE::length($query->{"q"} // "")
scalar keys %$query $query->{"q"}
Truth table0%0/3
A and B
A= scalar keys %$queryB= $query->{"q"}
ABresult
0X0
100
111
648 0 $size = $self->size;
649 # If size option is set, otherwise we leave it out
650 0 ▶ if( defined( $size ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size) 0 0 0
651 {
652 0 ▶ $size //= DEFAULT_PAGE_SIZE;
Condition0%0/2
$size //= 10
l!l
00
MC/DC0%0/1
$size //= 10
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
653 0 ▶ my $size_prop = $self->size_prop // 'size';
Condition0%0/2
$self->size_prop // "size"
l!l
00
MC/DC0%0/1
$self->size_prop // "size"
$self->size_prop
Truth table0%0/2
A
A= $self->size_prop
Aresult
11
00
654 0 $query->{ $size_prop } = $size;
655 }
656 0 ▶ my $page_type = $self->page_type || 'from';
Condition0%0/2
$self->page_type || 'from'
l!l
00
MC/DC0%0/1
$self->page_type || 'from'
$self->page_type
Truth table0%0/2
A
A= $self->page_type
Aresult
11
00
657 0 ▶ if( $page_type eq 'from' )
Branch: 2 branches
BranchTrueFalseTotal
if ($page_type eq 'from') { } 0 0 0
elsif ($page_type eq 'page') { } 0 0 0
658 {
659 # 0..9 or 10..19
660 0 my $offset = int( ( $page - 1 ) * $size );
661 0 $query->{from} = $offset;
662 }
663 elsif( $page_type eq 'page' )
664 {
665 0 $query->{page} = ( $page + 1 );
666 }
667 else
668 {
669 0 return( $self->error( "Unknown page type '$page_type'" ) );
670 }
671 0 $req->uri->query_form_hash( $query );
672 }
673
674 # User will need to check if there is an error if the user gets an undefined value in return,
675 # to distinguish between no more value vs a returned error
676 0 ▶ $self->load( request => $req ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->load("request", $req) or return $self->pass_error 0 0 0
677 # We set our current page to +1 if indeed we have data.
678 0 ▶ $self->page( $page ) if( !$self->items->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->items->is_empty 0 0 0
679 }
680
681 0 ▶ if( $what eq 'object' || $what eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "object" or $what eq "hash") 0 0 0
Condition0%0/3
$what eq "object" or $what eq "hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$what eq "object" or $what eq "hash"
$what eq "object" $what eq "hash"
Truth table0%0/3
A or B
A= $what eq "object"B= $what eq "hash"
ABresult
1X1
011
000
682 {
683 0 return( $self->new_null( type => $what ) );
684 }
685 0 return;
686 }
687 1 return( $val );
688 }
689  
690 sub push
691 0 ▶{
Subroutine push: not called CC=3 SCAR=24.8
Pod documented
692 0 my $self = CORE::shift( @_ );
693 0 ▶ my $this = CORE::shift( @_ ) || return( $self->error( "Nothing was provided to add to the list of object." ) );
Condition0%0/2
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
l!l
00
MC/DC0%0/1
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
Aresult
11
00
694 0 ▶ $self->_check( $this ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_check($this) or return $self->pass_error 0 0 0
695 0 $self->items->push( $this );
696 0 return( $self );
697 }
698  
699 1 ▶sub request { CORE::return( shift->_set_get_object_without_init( 'request', 'HTTP::Promise::Request', @_ ) ); }
Subroutine request: called CC=1 SCAR=0.0
Pod documented
700  
701 sub shift
702 0 ▶{
Subroutine shift: not called CC=4 SCAR=30.0
Pod documented
703 0 my $self = CORE::shift( @_ );
704 0 my $data = $self->items;
705 0 my $what = lc( Wanted::wantref );
706 0 my $val = $self->items->shift;
707  
708  
709 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
710 {
711 0 ▶ if( $what eq 'object' || $what eq 'hash' )
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "object" or $what eq "hash") 0 0 0
Condition0%0/3
$what eq "object" or $what eq "hash"
l!l&&r!l&&!r
000
MC/DC0%0/2
$what eq "object" or $what eq "hash"
$what eq "object" $what eq "hash"
Truth table0%0/3
A or B
A= $what eq "object"B= $what eq "hash"
ABresult
1X1
011
000
712 {
713 0 return( $self->new_null( type => $what ) );
714 }
715 0 return;
716 }
717 0 return( $val );
718 }
719  
720 1 ▶sub size { return( CORE::shift->_set_get_number( 'size', @_ ) ); }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
721  
722 1 ▶sub size_prop { return( CORE::shift->_set_get_scalar_as_object( 'size_prop', @_ ) ); }
Subroutine size_prop: called CC=1 SCAR=0.0
Pod documented
723  
724 # NOTE: timed_out is returned by MetaCPAN API (Elastic Search)
725 2 ▶sub timed_out { return( CORE::shift->_set_get_boolean( 'timed_out', @_ ) ); }
Subroutine timed_out: called CC=1 SCAR=0.0
Pod documented
726  
727 # NOTE: took is returned by MetaCPAN API (Elastic Search)
728 2 ▶sub took { return( CORE::shift->_set_get_number( { field => 'took', undef_ok => 1 }, @_ ) ); }
Subroutine took: called CC=1 SCAR=0.0
Pod documented
729  
730 # NOTE: total returns the number returned by MetaCPAN API, which represents the overal total number of hits across all pages
731 3 ▶sub total { return( CORE::shift->_set_get_number( 'total', @_ ) ); }
Subroutine total: called CC=1 SCAR=0.0
Pod documented
732  
733 5 ▶sub type { return( CORE::shift->_set_get_scalar_as_object( 'type', @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
734  
735 sub unshift
736 0 ▶{
Subroutine unshift: not called CC=3 SCAR=24.8
Pod documented
737 0 my $self = CORE::shift( @_ );
738 0 ▶ my $this = CORE::shift( @_ ) || return( $self->error( "Nothing was provided to add to the list of object." ) );
Condition0%0/2
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
l!l
00
MC/DC0%0/1
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
Aresult
11
00
739 0 ▶ $self->_check( $this ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_check($this) or return $self->pass_error 0 0 0
740 0 $self->items->unshift( $this );
741 0 return( $self );
742 }
743  
744 sub _check
745 0 ▶{
Subroutine _check: not called CC=12 SCAR=50.5
746 0 my $self = CORE::shift( @_ );
747 0 ▶ my $this = CORE::shift( @_ ) || return( $self->error( "No data was provided to check." ) );
Condition0%0/2
CORE::shift @_ || (return $self->error('No data was provided to check.'))
l!l
00
MC/DC0%0/1
CORE::shift @_ || (return $self->error('No data was provided to check.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
Aresult
11
00
748 0 ▶ return( $self->error( "Data provided is not an object." ) ) if( !$self->_is_object( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($this) 0 0 0
749 # Check if there is any data and if there is find out what kind of object we are holding so we can maintain consistency
750 0 my $data = $self->items;
751 0 my $obj_name;
752 0 ▶ if( !$data->is_empty && $self->_is_object( $data->[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->is_empty and $self->_is_object($data->[0])) 0 0 0
Condition0%0/3
not $data->is_empty and $self->_is_object($data->[0])
!ll&&!rl&&r
000
MC/DC0%0/2
not $data->is_empty and $self->_is_object($data->[0])
not $data->is_empty $self->_is_object($data->[0])
Truth table0%0/3
not(A) and B
A= not $data->is_emptyB= $self->_is_object($data->[0])
ABresult
0X0
100
111
753 {
754 0 ▶ $obj_name = $data->[0]->object if( $data->[0]->can( 'object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $data->[0]->can("object") 0 0 0
755 }
756 0 ▶ if( $this->can( 'object' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->can("object")) 0 0 0
757 {
758 0 my $this_object = $this->object;
759 0 ▶ $this_object = '' if( !defined( $this_object ) || !$this_object->defined );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this_object and $this_object->defined 0 0 0
Condition0%0/3
defined $this_object and $this_object->defined
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this_object and $this_object->defined
defined $this_object $this_object->defined
Truth table0%0/3
A and B
A= defined $this_objectB= $this_object->defined
ABresult
0X0
100
111
760 0 ▶ $obj_name = '' if( !defined( $obj_name ) || !$obj_name->defined );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj_name and $obj_name->defined 0 0 0
Condition0%0/3
defined $obj_name and $obj_name->defined
!ll&&!rl&&r
000
MC/DC0%0/2
defined $obj_name and $obj_name->defined
defined $obj_name $obj_name->defined
Truth table0%0/3
A and B
A= defined $obj_nameB= $obj_name->defined
ABresult
0X0
100
111
761 0 ▶ return( $self->error( "Object provided (", overload::StrVal( $this ), ") has an object type (${this_object}) different from the ones currently in our stack (${obj_name})." ) ) if( $this_object ne $obj_name );
Branch: 1 branch
BranchTrueFalseTotal
if $this_object ne $obj_name 0 0 0
762 }
763 0 return( $this );
764 }
765  
766 3 1;
767 # NOTE: POD
768 __END__
« CPAN.pm ↑ Summary CPAN/Mock.pm »