| 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
Condition100%3/3
$arg2_type || $arg1_type
MC/DC100%2/2
$arg2_type || $arg1_type
$arg2_type
$arg1_type
Truth table100%3/3
A || B
A= $arg2_typeB= $arg1_type
| |||||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | $result = index($arg2, $arg1) > -1 ? 1: 0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | $result = exists $arg2->{$arg1} ? 1: 0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if( not $found ) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $result = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | foreach my $key1 (keys %$arg1) | |||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $arg2->{$key1} and DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1->{$key1}, $arg2->{$key1})
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})
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not defined $result and UNIVERSAL::can($arg1, "in")
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")
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not defined $result and UNIVERSAL::can($arg2, "contains")
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")
| |||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | die $self->get_render_error( | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$arg1 // "undef"
$arg1_type || 'SCALAR'
$arg2 // "undef"
$arg2_type || 'SCALAR'
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
Truth table50%1/2
A
A= $arg1_type
Truth table50%1/2
A
A= $arg2
Truth table50%1/2
A
A= $arg2_type
| |||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||