CPAN/Filter.pm

filter: Statementstmt 24.5% 42 / 171 Branchbran 14.0% 14 / 100 Conditioncond 11.1% 6 / 54 MC/DCmcdc 3.7% 1 / 27 Subroutinesub 36.6% 11 / 30 Podpod 94.4% 17 / 18 totaltotal 22.7% 91 / 400 CC 73 SCAR 48.0
CC
73
Cov
19%
as_hash
342.0
__ANON__
272.0
as_json
72.0
CRAP 121.7
« CPAN/Mock.pm ↑ Summary CPAN/Generic.pm »
1 ##----------------------------------------------------------------------------
2 ## Meta CPAN API - ~/lib/Net/API/CPAN/Filter.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/08/03
7 ## Modified 2023/08/03
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::Filter;
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( Module::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 our $VERSION = 'v0.1.0';
22 };
23  
24 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub init
28 2 ▶{
Subroutine init: called CC=13 SCAR=28.7
Pod documented
29 2 my $self = shift( @_ );
30 2 ▶ $self->{aggs} = undef unless( CORE::exists( $self->{aggs} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"aggs"} 2 0 2
31 2 ▶ $self->{es} = undef unless( CORE::exists( $self->{es} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"es"} 2 0 2
32 2 ▶ $self->{fields} = undef unless( CORE::exists( $self->{fields} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"fields"} 2 0 2
33 2 ▶ $self->{filter} = undef unless( CORE::exists( $self->{filter} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"filter"} 2 0 2
34 2 ▶ $self->{from} = undef unless( CORE::exists( $self->{from} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"from"} 2 0 2
35 2 ▶ $self->{match_all} = 0 unless( CORE::exists( $self->{match_all} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"match_all"} 2 0 2
36 2 ▶ $self->{name} = undef unless( CORE::exists( $self->{name} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"name"} 2 0 2
37 2 ▶ $self->{query} = undef unless( CORE::exists( $self->{query} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"query"} 2 0 2
38 2 ▶ $self->{size} = undef unless( CORE::exists( $self->{size} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"size"} 2 0 2
39 2 ▶ $self->{sort} = undef unless( CORE::exists( $self->{sort} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"sort"} 2 0 2
40 2 ▶ $self->{source} = undef unless( CORE::exists( $self->{source} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"source"} 2 0 2
41 2 $self->{_init_strict_use_sub} = 1;
42 2 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 2 0 2
43 2 $self->{_data} = {};
44 2 return( $self );
45 }
46  
47 0 ▶sub aggregations { return( shift->aggs( @_ ) ); }
Subroutine aggregations: not called CC=1 SCAR=6.9
Pod documented
48  
49 0 ▶sub aggs { return( shift->reset(@_)->_set_get_hash_as_mix_object( 'aggs', @_ ) ); }
Subroutine aggs: not called CC=1 SCAR=6.9
Pod documented
50  
51 sub apply
52 0 ▶{
Subroutine apply: not called CC=6 SCAR=37.4
Pod documented
53 0 my $self = shift( @_ );
54 0 my $hash = $self->_get_args_as_hash( @_ );
55 0 ▶ return( $self ) if( !scalar( keys( %$hash ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$hash 0 0 0
56
57 0 foreach my $k ( keys( %$hash ) )
58 {
59 0 my $code;
60 # if( !CORE::exists( $dict->{ $k } ) )
61 0 ▶ if( !( $code = $self->can( $k ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($code = $self->can($k)) 0 0 0
62 {
63 0 ▶ warn( "No method \"$k\" found in class ", ( ref( $self ) || $self ), " when applying data to this object. Skipping it." ) if( $self->_is_warnings_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled 0 0 0
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
64 0 next;
65 }
66 0 $code->( $self, $hash->{ $_ } );
67 }
68 0 return( $self );
69 }
70  
71 sub as_hash
72 0 ▶{
Subroutine as_hash: not called CC=18 SCAR=58.3
Pod documented
73 0 my $self = shift( @_ );
74 0 ▶ return( $self->{_data_cache} ) if( $self->{_data_cache} && !CORE::length( $self->{_reset} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_data_cache"} and not length $self->{"_reset"} 0 0 0
Condition0%0/3
$self->{"_data_cache"} and not length $self->{"_reset"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_data_cache"} and not length $self->{"_reset"}
$self->{"_data_cache"} not length $self->{"_reset"}
Truth table0%0/3
A and not(B)
A= $self->{"_data_cache"}B= not length $self->{"_reset"}
ABresult
0X0
100
111
75 0 my $data = {};
76 0 my $es = $self->es;
77 0 ▶ if( defined( $es ) && $es->length )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $es and $es->length) { } 0 0 0
Condition0%0/3
defined $es and $es->length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $es and $es->length
defined $es $es->length
Truth table0%0/3
A and B
A= defined $esB= $es->length
ABresult
0X0
100
111
78 {
79 0 $data = $es->as_hash;
80 }
81 else
82 {
83 0 $data->{query} = $self->query;
84 0 ▶ if( my $aggs = $self->aggs )
Branch: 1 branch
BranchTrueFalseTotal
if (my $aggs = $self->aggs) 0 0 0
85 {
86 0 $data->{aggs} = $aggs;
87 }
88 0 ▶ if( my $fields = $self->fields )
Branch: 1 branch
BranchTrueFalseTotal
if (my $fields = $self->fields) 0 0 0
89 {
90 0 ▶ $data->{fields} = [@$fields] if( !$fields->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $fields->is_empty 0 0 0
91 }
92 0 ▶ if( my $filter = $self->filter )
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = $self->filter) 0 0 0
93 {
94 0 $data->{filter} = $filter;
95 }
96 0 ▶ if( my $sort = $self->sort )
Branch: 1 branch
BranchTrueFalseTotal
if (my $sort = $self->sort) 0 0 0
97 {
98 0 ▶ $data->{sort} = [@$sort] if( !$sort->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $sort->is_empty 0 0 0
99 }
100 0 ▶ if( my $source = $self->source )
Branch: 1 branch
BranchTrueFalseTotal
if (my $source = $self->source) 0 0 0
101 {
102 0 $data->{_source} = $source;
103 }
104 0 ▶ if( my $name = $self->name )
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->name) 0 0 0
105 {
106 0 ▶ if( exists( $data->{filter} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"filter"} and exists $data->{"filter"}{"terms"} and ref $data->{"filter"}{"terms"} eq "HASH") 0 0 0
Condition0%0/6
exists $data->{"filter"} and exists $data->{"filter"}{"terms"} and ref $data->{"filter"}{"terms"} eq "HASH"
!ll&&!rl&&r
000
exists $data->{"filter"} and exists $data->{"filter"}{"terms"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $data->{"filter"} and exists $data->{"filter"}{"terms"} and ref $data->{"filter"}{"terms"} eq "HASH"
exists $data->{"filter"} exists $data->{"filter"}{"terms"} ref $data->{"filter"}{"terms"} eq "HASH"
Truth table0%0/4
A and B and C
A= exists $data->{"filter"}B= exists $data->{"filter"}{"terms"}C= ref $data->{"filter"}{"terms"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
107 exists( $data->{filter}->{terms} ) &&
108 ref( $data->{filter}->{terms} ) eq 'HASH' )
109 {
110 0 $data->{filter}->{terms}->{_name} = $name;
111 }
112 }
113 0 ▶ if( defined( my $from = $self->from ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $from = $self->from)) 0 0 0
114 {
115 0 $data->{from} = $from;
116 }
117 0 ▶ if( defined( my $size = $self->size ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $size = $self->size)) 0 0 0
118 {
119 0 $data->{size} = $size;
120 }
121 }
122 0 $self->{_data_cache} = $data;
123 0 CORE::delete( $self->{_reset} );
124 0 return( $data );
125 }
126  
127 sub as_json
128 0 ▶{
Subroutine as_json: not called CC=8 SCAR=42.8
Pod documented
129 0 my $self = shift( @_ );
130 0 my $opts = $self->_get_args_as_hash( @_ );
131 0 my $data = $self->as_hash;
132 0 my $j = $self->new_json;
133 0 ▶ $j = $j->pretty if( $opts->{pretty} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"pretty"} 0 0 0
134 0 ▶ $j = $j->canonical if( $opts->{sort} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"sort"} 0 0 0
135 0 my $json;
136 0 local $@;
137 # try-catch
138 eval
139 0 {
140 0 ▶ if( exists( $opts->{encoding} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'encoding'} and defined $opts->{'encoding'} and lc $opts->{'encoding'} eq 'utf-8' || lc $opts->{'encoding'} eq 'utf8') { } 0 0 0
Condition0%0/9
exists $opts->{"encoding"} and defined $opts->{"encoding"} and lc $opts->{"encoding"} eq "utf-8" || lc $opts->{"encoding"} eq "utf8"
!ll&&!rl&&r
000
exists $opts->{"encoding"} and defined $opts->{"encoding"}
!ll&&!rl&&r
000
lc $opts->{"encoding"} eq "utf-8" or lc $opts->{"encoding"} eq "utf8"
l!l&&r!l&&!r
000
MC/DC0%0/4
exists $opts->{"encoding"} and defined $opts->{"encoding"} and lc $opts->{"encoding"} eq "utf-8" || lc $opts->{"encoding"} eq "utf8"
exists $opts->{"encoding"} defined $opts->{"encoding"} lc $opts->{"encoding"} eq "utf-8" lc $opts->{"encoding"} eq "utf8"
Truth table0%0/5
A and B and C or D
A= exists $opts->{"encoding"}B= defined $opts->{"encoding"}C= lc $opts->{"encoding"} eq "utf-8"D= lc $opts->{"encoding"} eq "utf8"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
141 defined( $opts->{encoding} ) &&
142 ( lc( $opts->{encoding} ) eq 'utf-8' || lc( $opts->{encoding} ) eq 'utf8' ) )
143 {
144 0 $json = $j->utf8->encode( $data );
145 }
146 else
147 {
148 0 $json = $j->encode( $data );
149 }
150 };
151 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
152 {
153 0 return( $self->error( "Error encoding to JSON: $@" ) );
154 }
155 0 return( $json );
156 }
157  
158 0 ▶sub es { return( shift->reset(@_)->_set_get_hash_as_mix_object( 'es', @_ ) ); }
Subroutine es: not called CC=1 SCAR=6.9
Pod documented
159  
160 0 ▶sub fields { return( shift->reset(@_)->_set_get_array_as_object( 'fields', @_ ) ); }
Subroutine fields: not called CC=1 SCAR=6.9
Pod documented
161  
162 0 ▶sub filter { return( shift->reset(@_)->_set_get_hash_as_mix_object( 'filter', @_ ) ); }
Subroutine filter: not called CC=1 SCAR=6.9
Pod documented
163  
164 0 ▶sub from { return( shift->reset(@_)->_set_get_number( 'from', @_ ) ); }
Subroutine from: not called CC=1 SCAR=6.9
Pod documented
165  
166 1 ▶sub match_all { return( shift->reset(@_)->_set_get_number( 'match_all', @_ ) ); }
Subroutine match_all: called CC=1 SCAR=0.0
Pod documented
167  
168 0 ▶sub name { return( shift->reset(@_)->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
169  
170 sub query
171 0 ▶{
Subroutine query: not called CC=7 SCAR=40.3
Pod documented
172 0 my $self = shift( @_ );
173 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
174 {
175 0 my $query;
176 0 my $this = shift( @_ );
177 0 my $opts = $self->_get_args_as_hash( @_ );
178 0 ▶ return( $self->error( "Argument to query must be an hash reference." ) ) if( ref( $this ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $this ne "HASH" 0 0 0
179 0 ▶ $self->message( 5, "Query provided is -> ", sub{ $self->Module::Generic::dump( $this ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 0 $self->reset(1);
181 0 my @es_ops = qw( bool should );
182 0 my $es_ops = {};
183 0 @$es_ops{ @es_ops } = (1) x scalar( @es_ops );
184 0 my @operators = ( 'all', 'bool', 'either', 'not', 'must', 'shall', 'shall not', 'should' );
185 0 my $op_re = join( '|', @operators );
186 0 my $equi =
187 {
188 all => 'must',
189 either => 'should',
190 not => 'must_not',
191 };
192 0 my $build;
193 $build = sub
194 0 ▶ {
Subroutine __ANON__: not called CC=16 SCAR=56.1
195 0 my $ref = shift( @_ );
196 0 ▶ $self->message( 5, "Top properties are: ", sub{ join( ', ', sort( keys( %$ref ) ) ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
197 0 my $q = {};
198 0 ▶ if( scalar( grep( /^($op_re)$/, keys( %$ref ) ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep(/^($op_re)$/, keys %$ref)) { } 0 0 0
199 {
200 0 foreach my $op ( @operators )
201 {
202 0 ▶ next unless( exists( $ref->{ $op } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ref->{$op} 0 0 0
203 0 my $def = delete( $ref->{ $op } );
204 # No need for transformation
205 0 ▶ if( exists( $es_ops->{ $op } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $es_ops->{$op}) 0 0 0
206 {
207 0 $q->{ $op } = $def;
208 0 next;
209 }
210 0 ▶ $def = [$def] if( ref( $def ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $def eq "HASH" 0 0 0
211 0 ▶ if( !$self->_is_array( $def ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_array($def)) 0 0 0
212 {
213 0 return( $self->error( "Invalid parameter \"$op\" value provided (", overload::StrVal( $def ), "). I was expecting an hash or an array reference." ) );
214 }
215
216 0 my $sub_q = [];
217 0 foreach my $sub_def ( @$def )
218 {
219 0 ▶ my $this_q = $build->( $sub_def ) || return( $self->pass_error );
Condition0%0/2
&$build($sub_def) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$build($sub_def) || (return $self->pass_error)
&$build($sub_def)
Truth table0%0/2
A
A= &$build($sub_def)
Aresult
11
00
220 0 push( @$sub_q, $this_q );
221 }
222
223 0 $q->{bool} = {};
224 0 ▶ $q->{bool}->{ $equi->{ $op } // $op } = $sub_q;
Condition0%0/3
$equi->{$op} // $op
l!l&&r!l&&!r
000
MC/DC0%0/2
$equi->{$op} // $op
$equi->{$op} $op
Truth table0%0/3
A // B
A= $equi->{$op}B= $op
ABresult
1X1
011
000
225 }
226 }
227 else
228 {
229 0 ▶ $self->message( 5, "Top properties do not contain either of ", sub{ join( ', ', @operators ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
230 0 my $n = scalar( keys( %$ref ) );
231 0 ▶ return( $self->error( "Wrong number of keys (${n}). Query element should have only 1 key. Insted I got: ", sub{ $self->Module::Generic::dump( $ref ) } ) ) if( $n > 1 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1 0 0 0
232 0 my $key = [keys( %$ref )]->[0];
233 0 my $val = $ref->{ $key };
234 # Example:
235 # $ref =
236 # {
237 # status =>
238 # {
239 # value => "latest",
240 # boost => 2.0
241 # }
242 # }
243 0 ▶ if( ref( $val ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'HASH') { } 0 0 0
elsif (!ref($val) || $self->_can_overload($val, '""') and "$val" =~ /[\w\*]/) { } 0 0 0
244 {
245 0 $q->{term} = $ref;
246 }
247 # or, just:
248 # $ref = { status => "latest" }
249 # or, maybe:
250 # $ref = { name => "Some*" }
251 ▶ elsif( ( !ref( $val ) || $self->_can_overload( $val => '""' ) ) && "$val" =~ /[\w\*]/ )
Condition0%0/6
!ref($val) || $self->_can_overload($val, "\"\"") and "$val" =~ /[\w\*]/
!ll&&!rl&&r
000
not ref $val or $self->_can_overload($val, "\"\"")
l!l&&r!l&&!r
000
MC/DC0%0/3
!ref($val) || $self->_can_overload($val, "\"\"") and "$val" =~ /[\w\*]/
not ref $val $self->_can_overload($val, "\"\"") "$val" =~ /[\w\*]/
Truth table0%0/5
not(A) or B and C
A= not ref $valB= $self->_can_overload($val, "\"\"")C= "$val" =~ /[\w\*]/
ABCresult
00X0
1X00
0100
1X11
0111
252 {
253 0 ▶ my $type = ( "$val" =~ /[*?]/ ? 'wildcard' : 'term' );
Branch: 1 branch
BranchTrueFalseTotal
"$val" =~ /[*?]/ ? : 0 0 0
254 0 $q->{ $type } = $ref;
255 }
256 else
257 {
258 0 return( $self->error( "Wrong value for \"$key\". I do not know what to do with '", overload::StrVal( $val ), "'" ) );
259 }
260 }
261 0 return( $q );
262 0 };
263 0 ▶ $query = $build->( $this ) || return( $self->pass_error );
Condition0%0/2
&$build($this) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$build($this) || (return $self->pass_error)
&$build($this)
Truth table0%0/2
A
A= &$build($this)
Aresult
11
00
264 0 $self->{query} = $query;
265 }
266
267 0 ▶ unless( $self->{query} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"query"}) 0 0 0
268 {
269 0 my $match_all = $self->match_all;
270 0 ▶ if( $match_all )
Branch: 1 branch
BranchTrueFalseTotal
if ($match_all) 0 0 0
271 {
272 0 ▶ if( $match_all == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($match_all == 1) { } 0 0 0
273 {
274 0 $self->{query} = { match_all => {} };
275 }
276 else
277 {
278 0 $self->{query} = { match_all => { boost => $match_all } };
279 }
280 }
281 }
282 0 return( $self->{query} );
283 }
284  
285 sub reset
286 5 ▶{
Subroutine reset: called CC=5 SCAR=16.2
Pod documented
287 5 my $self = shift( @_ );
288 5 ▶ if( (
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_) 1 4 5
Condition75%6/8
not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_
!ll
41
exists $self->{'_reset'} && defined $self->{'_reset'} && length $self->{'_reset'}
!ll&&!rl&&r
104
exists $self->{"_reset"} and defined $self->{"_reset"}
!ll&&!rl&&r
104
MC/DC33%1/3
not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_
exists $self->{"_reset"} defined $self->{"_reset"} length $self->{'_reset'}
Truth table50%2/4
not(A and B && C)
A= exists $self->{"_reset"}B= defined $self->{"_reset"}C= length $self->{'_reset'}
ABCresult
1110
0XX1
10X1
1101
289 !exists( $self->{_reset} ) ||
290 !defined( $self->{_reset} ) ||
291 !CORE::length( $self->{_reset} )
292 ) && scalar( @_ ) )
293 {
294 1 $self->{_reset} = scalar( @_ );
295 }
296 5 return( $self );
297 }
298  
299 4 ▶sub size { return( shift->reset(@_)->_set_get_number( 'size', @_ ) ); }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
300  
301 0 ▶sub sort { return( shift->reset(@_)->_set_get_array_as_object( 'sort', @_ ) ); }
Subroutine sort: not called CC=1 SCAR=6.9
Pod documented
302  
303 sub source
304 0 ▶{
Subroutine source: not called CC=7 SCAR=40.3
Pod documented
305 0 my $self = shift( @_ );
306 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
307 {
308 0 ▶ if( !defined( $_[0] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_[0]) { } 0 0 0
elsif ($self->_is_array($_[0]) or not ref $_[0] or ref $_[0] and $self->_can_overload($_[0], '""')) { } 0 0 0
309 {
310 0 $self->{source} = undef;
311 0 $self->reset(1);
312 }
313 ▶ elsif( $self->_is_array( $_[0] ) ||
Condition0%0/9
$self->_is_array($_[0]) or not ref $_[0] or ref $_[0] and $self->_can_overload($_[0], "\"\"")
l!l&&r!l&&!r
000
$self->_is_array($_[0]) or not ref $_[0]
l!l&&r!l&&!r
000
ref $_[0] and $self->_can_overload($_[0], "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/4
$self->_is_array($_[0]) or not ref $_[0] or ref $_[0] and $self->_can_overload($_[0], "\"\"")
$self->_is_array($_[0]) not ref $_[0] ref $_[0] $self->_can_overload($_[0], "\"\"")
Truth table0%0/5
A or not(B) or C and D
A= $self->_is_array($_[0])B= not ref $_[0]C= ref $_[0]D= $self->_can_overload($_[0], "\"\"")
ABCDresult
1XXX1
01XX1
00111
000X0
00100
314 !ref( $_[0] ) ||
315 ( ref( $_[0] ) && $self->_can_overload( $_[0] => '""' ) ) )
316 {
317 0 $self->{source} = shift( @_ );
318 0 $self->reset(1);
319 }
320 else
321 {
322 0 return( $self->error( "A source can only be either a string or an array reference." ) );
323 }
324 }
325 0 return( $self->{source} );
326 }
327  
328 0 ▶sub TO_JSON { return( shift->as_hash ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
329  
330 3 1;
331 # NOTE: POD
332 __END__
« CPAN/Mock.pm ↑ Summary CPAN/Generic.pm »