line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Condition::in; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
705
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
397
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
9
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
10
|
1
|
|
|
1
|
|
361
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has path1 => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has path2 => (fix_arg => 1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Catmandu::Fix::Condition::Builder'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_tester { |
18
|
1
|
|
|
1
|
|
12
|
my ($self) = @_; |
19
|
1
|
|
|
|
|
19
|
my $path1_getter = as_path($self->path1)->getter; |
20
|
1
|
|
|
|
|
14
|
my $path2_getter = as_path($self->path2)->getter; |
21
|
|
|
|
|
|
|
sub { |
22
|
14
|
|
|
14
|
|
25
|
my $data = $_[0]; |
23
|
14
|
|
|
|
|
248
|
my $vals1 = $path1_getter->($data); |
24
|
14
|
|
|
|
|
234
|
my $vals2 = $path2_getter->($data); |
25
|
14
|
50
|
66
|
|
|
98
|
return 0 unless @$vals1 && @$vals2 && @$vals1 == @$vals2; |
|
|
|
66
|
|
|
|
|
26
|
13
|
|
|
|
|
39
|
for (my $i = 0; $i < @$vals1; $i++) { |
27
|
1
|
|
|
1
|
|
574
|
no if $] >= 5.018, warnings => 'experimental::smartmatch'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
28
|
13
|
100
|
|
|
|
137
|
return 0 unless $vals1->[$i] ~~ $vals2->[$i]; |
29
|
|
|
|
|
|
|
} |
30
|
9
|
|
|
|
|
180
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
1
|
|
|
|
|
10
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Catmandu::Fix::Condition::in - only execute fixes the data in one path is contained in another |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
47
|
|
|
|
|
|
|
# Compare single values |
48
|
|
|
|
|
|
|
# foo => 42 , bar => 42 => in(foo,bar) -> true |
49
|
|
|
|
|
|
|
if in(foo,bar) |
50
|
|
|
|
|
|
|
add_field(forty_two,ok) |
51
|
|
|
|
|
|
|
end |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# When comparing single values to an array: test if the value is |
54
|
|
|
|
|
|
|
# contained in the array |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# foo => 1 , bar => [3,2,1] => in(foo,bar) -> true |
57
|
|
|
|
|
|
|
if in(foo,bar) |
58
|
|
|
|
|
|
|
add_field(test,ok) |
59
|
|
|
|
|
|
|
end |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# foo => 42 , bar => [1,2,3] => in(foo,bar) -> false |
62
|
|
|
|
|
|
|
unless in(foo,bar) |
63
|
|
|
|
|
|
|
add_field(test,ok) |
64
|
|
|
|
|
|
|
end |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# In the following examples we'll write in pseudo code the true/false |
67
|
|
|
|
|
|
|
# values of some 'in()' comparissons |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# scalars vs arrays - check if the value is in the array |
70
|
|
|
|
|
|
|
foo: 42 , bar: [1,2,3] in(foo,bar) -> false |
71
|
|
|
|
|
|
|
foo: 1 , bar: [1,2,3] in(foo,bar) -> true |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# scalars vs hashes - check if the key is in the hash |
74
|
|
|
|
|
|
|
foo: name , bar: { name => 'Patrick' } in(foo,bar) -> true |
75
|
|
|
|
|
|
|
foo: name , bar: { deep => {name => 'Nicolas'}} in(foo,bar) -> false |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# array vs array - check if the contents is equal |
78
|
|
|
|
|
|
|
foo: [1,2] , bar: [1,2] in(foo,bar) -> true |
79
|
|
|
|
|
|
|
foo: [1,2] , bar: [1,2,3] in(foo,bar) -> false |
80
|
|
|
|
|
|
|
foo: [1,2] , bar: [[1,2],3] in(foo,bar) -> false |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 STATUS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Be aware this function is experimental in many perl versions |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L<Catmandu::Fix> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |