blib/lib/Valiemon/Primitives.pm

filter: Statementstmt 100% 48 / 48 Branchbran 96.6% 29 / 30 Conditioncond 93.5% 58 / 62 MC/DCmcdc 81.8% 27 / 33 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 11 totaltotal 89.0% 179 / 201 CC 37 SCAR 17.8
CC
37
Cov
96%
is_equal
13.0
is_boolean_json
7.2
is_boolean_perl
5.0
CRAP 5.9
« blib/lib/Valiemon/Attributes/Dependencies.pm ↑ Summary blib/lib/Valiemon/Attributes/Properties.pm »
1 package Valiemon::Primitives;
2 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Types::Serialiser;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use Test::Deep qw(eq_deeply);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 217 ▶ my ($class, $options) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
12 217 ▶ return bless {
Condition100%2/2
$options || {}
l!l
2089
MC/DC100%1/1
$options || {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
13 options => $options || +{},
14 }, $class;
15 }
16  
17 sub is_object {
18 93 ▶ my ($self, $obj) = @_;
Subroutine is_object: called CC=3 SCAR=11.0
Pod undocumented
19 93 ▶ (defined $obj && ref $obj eq 'HASH') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj && ref $obj eq 'HASH' ? : 66 27 93
Condition100%3/3
defined $obj and ref $obj eq "HASH"
!ll&&!rl&&r
42366
MC/DC100%2/2
defined $obj and ref $obj eq "HASH"
defined $obj ref $obj eq "HASH"
Truth table100%3/3
A and B
A= defined $objB= ref $obj eq "HASH"
ABresult
0X0
100
111
20 }
21  
22 sub is_array {
23 53 ▶ my ($self, $obj) = @_;
Subroutine is_array: called CC=3 SCAR=11.0
Pod undocumented
24 53 ▶ (defined $obj && ref $obj eq 'ARRAY') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj && ref $obj eq 'ARRAY' ? : 29 24 53
Condition100%3/3
defined $obj and ref $obj eq "ARRAY"
!ll&&!rl&&r
42029
MC/DC100%2/2
defined $obj and ref $obj eq "ARRAY"
defined $obj ref $obj eq "ARRAY"
Truth table100%3/3
A and B
A= defined $objB= ref $obj eq "ARRAY"
ABresult
0X0
100
111
25 }
26  
27 sub is_string {
28 524 ▶ my ($self, $obj) = @_;
Subroutine is_string: called CC=3 SCAR=11.0
Pod undocumented
29 524 ▶ (defined $obj && ref $obj eq '') ? 1 : 0; # really?
Branch: 1 branch
BranchTrueFalseTotal
defined $obj && ref $obj eq '' ? : 355 169 524
Condition100%3/3
defined $obj and ref $obj eq ""
!ll&&!rl&&r
28141355
MC/DC100%2/2
defined $obj and ref $obj eq ""
defined $obj ref $obj eq ""
Truth table100%3/3
A and B
A= defined $objB= ref $obj eq ""
ABresult
0X0
100
111
30 }
31  
32 sub is_number {
33 535 ▶ my ($self, $obj) = @_;
Subroutine is_number: called CC=4 SCAR=13.9
Pod undocumented
34 # avoid from JSON::Boolean treated as number.
35 535 ▶ (defined $obj && ref $obj eq '' && looks_like_number($obj)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj && ref $obj eq '' && &looks_like_number($obj) ? : 288 247 535
Condition100%6/6
defined $obj and ref $obj eq "" and &looks_like_number($obj)
!ll&&!rl&&r
18067288
defined $obj and ref $obj eq ""
!ll&&!rl&&r
29151355
MC/DC100%3/3
defined $obj and ref $obj eq "" and &looks_like_number($obj)
defined $obj ref $obj eq "" &looks_like_number($obj)
Truth table100%4/4
A and B and C
A= defined $objB= ref $obj eq ""C= &looks_like_number($obj)
ABCresult
0XX0
10X0
1100
1111
36 }
37  
38 sub is_integer {
39 260 ▶ my ($self, $obj) = @_;
Subroutine is_integer: called CC=3 SCAR=11.0
Pod undocumented
40 260 ▶ $self->is_number($obj) && $obj =~ qr/^-?\d+$/ ? 1 : 0; # TODO find more better way
Branch: 1 branch
BranchTrueFalseTotal
$self->is_number($obj) && $obj =~ qr/^-?\d+$/ ? : 183 77 260
Condition100%3/3
$self->is_number($obj) and $obj =~ qr/^-?\d+$/
!ll&&!rl&&r
5918183
MC/DC100%2/2
$self->is_number($obj) and $obj =~ qr/^-?\d+$/
$self->is_number($obj) $obj =~ qr/^-?\d+$/
Truth table100%3/3
A and B
A= $self->is_number($obj)B= $obj =~ qr/^-?\d+$/
ABresult
0X0
100
111
41 }
42  
43 sub is_boolean {
44 270 ▶ my ($self, $obj) = @_;
Subroutine is_boolean: called CC=2 SCAR=6.9
Pod undocumented
45 return $self->{options}->{use_json_boolean}
46 270 ▶ ? $self->is_boolean_json($obj)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'options'}{'use_json_boolean'} ? : 146 124 270
47 : $self->is_boolean_perl($obj)
48 }
49  
50 sub is_boolean_perl { # 1 or 0
51 140 ▶ my ($self, $obj) = @_;
Subroutine is_boolean_perl: called CC=5 SCAR=16.1
Pod undocumented
52 140 ▶ (defined $obj && looks_like_number($obj) && ($obj == 1 || $obj == 0)) ? 1 : 0; # TODO invalidate 0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $obj && &looks_like_number($obj) && ($obj == 1 || $obj == 0) ? : 36 104 140
Condition100%9/9
defined $obj and &looks_like_number($obj) and $obj == 1 || $obj == 0
!ll&&!rl&&r
96836
defined $obj and &looks_like_number($obj)
!ll&&!rl&&r
98744
$obj == 1 or $obj == 0
l!l&&r!l&&!r
10268
MC/DC100%4/4
defined $obj and &looks_like_number($obj) and $obj == 1 || $obj == 0
defined $obj &looks_like_number($obj) $obj == 1 $obj == 0
Truth table100%5/5
A and B and C or D
A= defined $objB= &looks_like_number($obj)C= $obj == 1D= $obj == 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
53 }
54  
55 sub is_boolean_json {
56 162 ▶ my ($self, $obj) = @_;
Subroutine is_boolean_json: called CC=7 SCAR=19.7
Pod undocumented
57 162 ▶ return 1 if defined $obj && Types::Serialiser::is_bool($obj);
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj and &Types::Serialiser::is_bool($obj) 22 140 162
Condition100%3/3
defined $obj and &Types::Serialiser::is_bool($obj)
!ll&&!rl&&r
1912122
MC/DC100%2/2
defined $obj and &Types::Serialiser::is_bool($obj)
defined $obj &Types::Serialiser::is_bool($obj)
Truth table100%3/3
A and B
A= defined $objB= &Types::Serialiser::is_bool($obj)
ABresult
0X0
100
111
58 140 ▶ return 1 if ref $obj eq 'SCALAR' && looks_like_number($$obj) && ($$obj == 1 || $$obj == 0);
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj eq "SCALAR" and &looks_like_number($$obj) and $$obj == 1 || $$obj == 0 4 136 140
Condition66%6/9
ref $obj eq "SCALAR" and &looks_like_number($$obj) and $$obj == 1 || $$obj == 0
!ll&&!rl&&r
13604
ref $obj eq "SCALAR" and &looks_like_number($$obj)
!ll&&!rl&&r
13604
$$obj == 1 or $$obj == 0
l!l&&r!l&&!r
220
MC/DC25%1/4
ref $obj eq "SCALAR" and &looks_like_number($$obj) and $$obj == 1 || $$obj == 0
ref $obj eq "SCALAR" &looks_like_number($$obj) $$obj == 1 $$obj == 0
Truth table40%2/5
A and B and C or D
A= ref $obj eq "SCALAR"B= &looks_like_number($$obj)C= $$obj == 1D= $$obj == 0
ABCDresult
0XXX0
10XX0
11000
111X1
11011
59 136 return 0;
60 }
61  
62 sub is_null {
63 23 ▶ my ($self, $obj) = @_;
Subroutine is_null: called CC=2 SCAR=6.9
Pod undocumented
64 23 ▶ !defined($obj) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($obj) ? : 5 18 23
65 }
66  
67 # json schema core: 3.6 JSON value equality
68 sub is_equal {
69 213 ▶ my ($self, $a, $b) = @_;
Subroutine is_equal: called CC=13 SCAR=25.7
Pod undocumented
70 213 ▶ return 1 if !defined($a) && !defined($b);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a or defined $b 1 212 213
Condition100%3/3
defined $a or defined $b
l!l&&r!l&&!r
194181
MC/DC100%2/2
defined $a or defined $b
defined $a defined $b
Truth table100%3/3
A or B
A= defined $aB= defined $b
ABresult
1X1
011
000
71 212 ▶ return 1 if $self->is_boolean($a) && $self->is_boolean($b) && $a == $b;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_boolean($a) and $self->is_boolean($b) and $a == $b 6 206 212
Condition100%6/6
$self->is_boolean($a) and $self->is_boolean($b) and $a == $b
!ll&&!rl&&r
20426
$self->is_boolean($a) and $self->is_boolean($b)
!ll&&!rl&&r
186188
MC/DC100%3/3
$self->is_boolean($a) and $self->is_boolean($b) and $a == $b
$self->is_boolean($a) $self->is_boolean($b) $a == $b
Truth table100%4/4
A and B and C
A= $self->is_boolean($a)B= $self->is_boolean($b)C= $a == $b
ABCresult
0XX0
10X0
1100
1111
72 206 ▶ return 1 if $self->is_string($a) && $self->is_string($b) && "$a" eq "$b"; # ah
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_string($a) and $self->is_string($b) and "$a" eq "$b" 24 182 206
Condition100%6/6
$self->is_string($a) and $self->is_string($b) and "$a" eq "$b"
!ll&&!rl&&r
1384424
$self->is_string($a) and $self->is_string($b)
!ll&&!rl&&r
1251368
MC/DC100%3/3
$self->is_string($a) and $self->is_string($b) and "$a" eq "$b"
$self->is_string($a) $self->is_string($b) "$a" eq "$b"
Truth table100%4/4
A and B and C
A= $self->is_string($a)B= $self->is_string($b)C= "$a" eq "$b"
ABCresult
0XX0
10X0
1100
1111
73 182 ▶ return 1 if $self->is_number($a) && $self->is_number($b) && $a == $b;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_number($a) and $self->is_number($b) and $a == $b 0 182 182
Condition83%5/6
$self->is_number($a) and $self->is_number($b) and $a == $b
!ll&&!rl&&r
168140
$self->is_number($a) and $self->is_number($b)
!ll&&!rl&&r
1561214
MC/DC0%0/3
$self->is_number($a) and $self->is_number($b) and $a == $b
$self->is_number($a) $self->is_number($b) $a == $b
Truth table75%3/4
A and B and C
A= $self->is_number($a)B= $self->is_number($b)C= $a == $b
ABCresult
0XX0
10X0
1100
1111
74 182 ▶ return 1 if eq_deeply($a, $b); # array & object
Branch: 1 branch
BranchTrueFalseTotal
if eq_deeply($a, $b) 16 166 182
75 166 return 0;
76 }
77  
78 25 1;
« blib/lib/Valiemon/Attributes/Dependencies.pm ↑ Summary blib/lib/Valiemon/Attributes/Properties.pm »