line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Expression::Operator::Binary::In; |
2
|
3
|
|
|
3
|
|
1982
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
3
|
|
|
3
|
|
7
|
|
|
3
|
|
|
3
|
|
91
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
81
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
132
|
|
3
|
3
|
|
|
3
|
|
11
|
use parent 'DTL::Fast::Expression::Operator::Binary'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
19
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::OPS_HANDLERS{'in'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
583
|
use DTL::Fast::Expression::Operator::Binary::Eq; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1232
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub dispatch |
10
|
|
|
|
|
|
|
{ |
11
|
13
|
|
|
13
|
0
|
16
|
my( $self, $arg1, $arg2, $context) = @_; |
12
|
13
|
|
|
|
|
19
|
my ($arg1_type, $arg2_type) = (ref $arg1, ref $arg2); |
13
|
13
|
|
|
|
|
10
|
my $result = undef; |
14
|
|
|
|
|
|
|
|
15
|
13
|
100
|
100
|
|
|
82
|
if( not $arg2_type and not $arg1_type ) # substring checking |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
4
|
100
|
|
|
|
12
|
$result = index($arg2, $arg1) > -1 ? 1: 0; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
elsif( not $arg1_type and $arg2_type eq 'ARRAY') # operand in array |
20
|
|
|
|
|
|
|
{ |
21
|
4
|
|
|
|
|
5
|
$result = 0; |
22
|
4
|
|
|
|
|
4
|
foreach my $a2 (@$arg2) |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
# @todo: deep comparision, shouldn't it be optional? |
25
|
8
|
100
|
|
|
|
15
|
if( DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $arg1, $a2) ) |
26
|
|
|
|
|
|
|
{ |
27
|
2
|
|
|
|
|
2
|
$result = 1; |
28
|
2
|
|
|
|
|
4
|
last; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif( not $arg1_type and $arg2_type eq 'HASH') # exists synonim |
33
|
|
|
|
|
|
|
{ |
34
|
4
|
100
|
|
|
|
7
|
$result = exists $arg2->{$arg1} ? 1: 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif( $arg2_type eq 'ARRAY' and $arg1_type eq 'ARRAY') # second operand is an ARRAY |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
|
|
|
|
0
|
$result = 1; |
39
|
0
|
|
|
|
|
0
|
foreach my $a1 (@$arg1) |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
|
|
0
|
my $found = 0; |
42
|
0
|
|
|
|
|
0
|
foreach my $a2 (@$arg2) |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
# @todo: deep comparision, shouldn't it be optional? |
45
|
0
|
0
|
|
|
|
0
|
if( DTL::Fast::Expression::Operator::Binary::Eq::dispatch($self, $a1, $a2) ) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
0
|
$found = 1; |
48
|
0
|
|
|
|
|
0
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
0
|
if( not $found ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
0
|
$result = 0; |
55
|
0
|
|
|
|
|
0
|
last; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif( $arg2_type eq 'HASH' and $arg1_type eq 'HASH' ) # hash contains hash |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
$result = 1; |
62
|
0
|
|
|
|
|
0
|
foreach my $key1 (keys %$arg1) |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
0
|
0
|
|
|
0
|
if( |
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
|
|
|
|
|
0
|
$result = 0; |
71
|
0
|
|
|
|
|
0
|
last; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# `in` method implementation |
77
|
13
|
50
|
66
|
|
|
28
|
if( |
78
|
|
|
|
|
|
|
not defined $result |
79
|
|
|
|
|
|
|
and UNIVERSAL::can($arg1, 'in') |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
$result = $arg1->in($arg2); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# `contains` method implementation |
86
|
13
|
50
|
66
|
|
|
38
|
if( |
87
|
|
|
|
|
|
|
not defined $result |
88
|
|
|
|
|
|
|
and UNIVERSAL::can($arg2, 'contains') |
89
|
|
|
|
|
|
|
) |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
0
|
$result = $arg2->contains($arg1); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# still nothing |
95
|
13
|
100
|
|
|
|
28
|
if( not defined $result ) |
96
|
|
|
|
|
|
|
{ |
97
|
1
|
|
50
|
|
|
25
|
die $self->get_render_error( |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
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
|
|
|
|
|
31
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |