blib/lib/DTL/Fast/Expression/Operator/Binary/In.pm

filter: Statementstmt 66.0% 33 / 50 Branchbran 64.2% 18 / 28 Conditioncond 56.2% 18 / 32 MC/DCmcdc 25.0% 5 / 20 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 58.3% 80 / 137 SCAR 43.9
CC
31
Cov
63%
dispatch
113.3
BEGIN
1.0
BEGIN
1.0
CRAP 80.8
« blib/lib/DTL/Fast/Expression/Operator/Binary/Plus.pm ↑ Summary blib/lib/DTL/Fast.pm »
1 package DTL::Fast::Expression::Operator::Binary::In;
2 3 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use parent 'DTL::Fast::Expression::Operator::Binary';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 $DTL::Fast::OPS_HANDLERS{'in'} = __PACKAGE__;
6  
7 3 ▶use DTL::Fast::Expression::Operator::Binary::Eq;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub dispatch
10 {
11 13 ▶ my( $self, $arg1, $arg2, $context) = @_;
Subroutine dispatch: called CC=31 SCAR=47.3
Pod undocumented
12 13 my ($arg1_type, $arg2_type) = (ref $arg1, ref $arg2);
13 13 my $result = undef;
14  
15 13 ▶ if( not $arg2_type and not $arg1_type ) # substring checking
Branch: 5 branches
BranchTrueFalseTotal
if (not $arg2_type || $arg1_type) { } 4 9 13
elsif (not $arg1_type and $arg2_type eq 'ARRAY') { } 4 5 9
elsif (not $arg1_type and $arg2_type eq 'HASH') { } 4 1 5
elsif ($arg2_type eq 'ARRAY' and $arg1_type eq 'ARRAY') { } 0 1 1
elsif ($arg2_type eq 'HASH' and $arg1_type eq 'HASH') { } 0 2 2
Condition100%3/3
$arg2_type || $arg1_type
l!l&&r!l&&!r
814
MC/DC100%2/2
$arg2_type || $arg1_type
$arg2_type $arg1_type
Truth table100%3/3
A || B
A= $arg2_typeB= $arg1_type
ABresult
1X1
011
000
16 {
17 4 ▶ $result = index($arg2, $arg1) > -1 ? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
index($arg2, $arg1) != -1 ? : 2 2 4
18 }
19 ▶ elsif( not $arg1_type and $arg2_type eq 'ARRAY') # operand in array
Condition100%3/3
not $arg1_type and $arg2_type eq "ARRAY"
!ll&&!rl&&r
144
MC/DC100%2/2
not $arg1_type and $arg2_type eq "ARRAY"
not $arg1_type $arg2_type eq "ARRAY"
Truth table100%3/3
not(A) and B
A= not $arg1_typeB= $arg2_type eq "ARRAY"
ABresult
0X0
100
111
20 {
21 4 $result = 0;
22 4 foreach my $a2 (@$arg2)
23 {
24 # @todo: deep comparision, shouldn't it be optional?
25 8 ▶ if( DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1, $a2) )
Branch: 1 branch
BranchTrueFalseTotal
if (DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1, $a2)) 2 6 8
26 {
27 2 $result = 1;
28 2 last;
29 }
30 }
31 }
32 ▶ elsif( not $arg1_type and $arg2_type eq 'HASH') # exists synonim
Condition66%2/3
not $arg1_type and $arg2_type eq "HASH"
!ll&&!rl&&r
104
MC/DC50%1/2
not $arg1_type and $arg2_type eq "HASH"
not $arg1_type $arg2_type eq "HASH"
Truth table66%2/3
not(A) and B
A= not $arg1_typeB= $arg2_type eq "HASH"
ABresult
0X0
100
111
33 {
34 4 ▶ $result = exists $arg2->{$arg1} ? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $arg2->{$arg1} ? : 2 2 4
35 }
36 ▶ elsif( $arg2_type eq 'ARRAY' and $arg1_type eq 'ARRAY') # second operand is an ARRAY
Condition33%1/3
$arg2_type eq "ARRAY" and $arg1_type eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
$arg2_type eq "ARRAY" and $arg1_type eq "ARRAY"
$arg2_type eq "ARRAY" $arg1_type eq "ARRAY"
Truth table33%1/3
A and B
A= $arg2_type eq "ARRAY"B= $arg1_type eq "ARRAY"
ABresult
0X0
100
111
37 {
38 0 $result = 1;
39 0 foreach my $a1 (@$arg1)
40 {
41 0 my $found = 0;
42 0 foreach my $a2 (@$arg2)
43 {
44 # @todo: deep comparision, shouldn't it be optional?
45 0 ▶ if( DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $a1, $a2) )
Branch: 1 branch
BranchTrueFalseTotal
if (DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $a1, $a2)) 0 0 0
46 {
47 0 $found = 1;
48 0 last;
49 }
50 }
51  
52 0 ▶ if( not $found )
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
53 {
54 0 $result = 0;
55 0 last;
56 }
57 }
58 }
59 ▶ elsif( $arg2_type eq 'HASH' and $arg1_type eq 'HASH' ) # hash contains hash
Condition33%1/3
$arg2_type eq "HASH" and $arg1_type eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
$arg2_type eq "HASH" and $arg1_type eq "HASH"
$arg2_type eq "HASH" $arg1_type eq "HASH"
Truth table33%1/3
A and B
A= $arg2_type eq "HASH"B= $arg1_type eq "HASH"
ABresult
0X0
100
111
60 {
61 0 $result = 1;
62 0 foreach my $key1 (keys %$arg1)
63 {
64 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $arg2->{$key1} and DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})) 0 0 0
Condition0%0/3
exists $arg2->{$key1} and DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $arg2->{$key1} and DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
exists $arg2->{$key1} DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
Truth table0%0/3
A and B
A= exists $arg2->{$key1}B= DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
ABresult
0X0
100
111
65 not exists $arg2->{$key1}
66 # @todo: deep comparision, shouldn't it be optional?
67 or not DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
68 )
69 {
70 0 $result = 0;
71 0 last;
72 }
73 }
74 }
75  
76 # `in` method implementation
77 13 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $result and UNIVERSAL::can($arg1, "in")) 0 13 13
Condition66%2/3
not defined $result and UNIVERSAL::can($arg1, "in")
!ll&&!rl&&r
1210
MC/DC0%0/2
not defined $result and UNIVERSAL::can($arg1, "in")
not defined $result UNIVERSAL::can($arg1, "in")
Truth table66%2/3
not(A) and B
A= not defined $resultB= UNIVERSAL::can($arg1, "in")
ABresult
0X0
100
111
78 not defined $result
79 and UNIVERSAL::can($arg1, 'in')
80 )
81 {
82 0 $result = $arg1->in($arg2);
83 }
84  
85 # `contains` method implementation
86 13 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $result and UNIVERSAL::can($arg2, "contains")) 0 13 13
Condition66%2/3
not defined $result and UNIVERSAL::can($arg2, "contains")
!ll&&!rl&&r
1210
MC/DC0%0/2
not defined $result and UNIVERSAL::can($arg2, "contains")
not defined $result UNIVERSAL::can($arg2, "contains")
Truth table66%2/3
not(A) and B
A= not defined $resultB= UNIVERSAL::can($arg2, "contains")
ABresult
0X0
100
111
87 not defined $result
88 and UNIVERSAL::can($arg2, 'contains')
89 )
90 {
91 0 $result = $arg2->contains($arg1);
92 }
93  
94 # still nothing
95 13 ▶ if( not defined $result )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 1 12 13
96 {
97 1 ▶ die $self->get_render_error(
Condition50%4/8
$arg1 // "undef"
l!l
10
$arg1_type || 'SCALAR'
l!l
10
$arg2 // "undef"
l!l
10
$arg2_type || 'SCALAR'
l!l
01
MC/DC0%0/1
$arg1 // "undef"
$arg1
MC/DC0%0/1
$arg1_type || 'SCALAR'
$arg1_type
MC/DC0%0/1
$arg2 // "undef"
$arg2
MC/DC0%0/1
$arg2_type || 'SCALAR'
$arg2_type
Truth table50%1/2
A
A= $arg1
Aresult
11
00
Truth table50%1/2
A
A= $arg1_type
Aresult
11
00
Truth table50%1/2
A
A= $arg2
Aresult
11
00
Truth table50%1/2
A
A= $arg2_type
Aresult
11
00
98 $context,
99 sprintf("Don't know how to check that %s (%s) is in %s (%s)"
100 , $arg1 // 'undef'
101 , $arg1_type || 'SCALAR'
102 , $arg2 // 'undef'
103 , $arg2_type || 'SCALAR'
104 )
105 );
106 }
107  
108 12 return $result;
109 }
110  
111 3 1;
« blib/lib/DTL/Fast/Expression/Operator/Binary/Plus.pm ↑ Summary blib/lib/DTL/Fast.pm »