blib/lib/Catmandu/Fix/Condition/in.pm

filter: Statementstmt 100% 19 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.0% 24 / 25 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Catmandu/Fix/Condition/any_match.pm ↑ Summary blib/lib/Catmandu/Fix/filter.pm »
1 package Catmandu::Fix::Condition::in;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.0201_02';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has path => (fix_arg => 1);
12 1 has path2 => (fix_arg => 1);
13  
14 1 with 'Catmandu::Fix::Condition::SimpleCompareTest';
15  
16 sub emit_test {
17 1 ▶ my ($self, $var, $var2, $fixer) = @_;
Subroutine emit_test: called CC=1 SCAR=0.0
Pod undocumented
18 1 "${var} ~~ ${var2}";
19 }
20  
21 1 1;
22  
23 __END__
24  
25 =pod
26  
27 =head1 NAME
28  
29 Catmandu::Fix::Condition::in - only execute fixes the data in one path is contained in another
30  
31 =head1 SYNOPSIS
32  
33 #-------------------------------------------------------------------
34 # Compare single values
35 # foo => 42 , bar => 42 => in(foo,bar) -> true
36 if in(foo,bar)
37 add_field(forty_two,ok)
38 end
39
40 # When comparing single values to an array: test if the value is
41 # contained in the array
42  
43 # foo => 1 , bar => [3,2,1] => in(foo,bar) -> true
44 if in(foo,bar)
45 add_field(test,ok)
46 end
47  
48 # foo => 42 , bar => [1,2,3] => in(foo,bar) -> false
49 unless in(foo,bar)
50 add_field(test,ok)
51 end
52  
53 # In the following examples we'll write in pseudo code the true/false
54 # values of some 'in()' comparissons
55  
56 # scalars vs arrays - check if the value is in the array
57 foo: 42 , bar: [1,2,3] in(foo,bar) -> false
58 foo: 1 , bar: [1,2,3] in(foo,bar) -> true
59  
60 # scalars vs hashes - check if the key is in the hash
61 foo: name , bar: { name => 'Patrick' } in(foo,bar) -> true
62 foo: name , bar: { deep => {name => 'Nicolas'}} in(foo,bar) -> false
63  
64 # array vs array - check if the contents is equal
65 foo: [1,2] , bar: [1,2] in(foo,bar) -> true
66 foo: [1,2] , bar: [1,2,3] in(foo,bar) -> false
67 foo: [1,2] , bar: [[1,2],3] in(foo,bar) -> false
68  
69 =head1 STATUS
70  
71 Be aware this function is experimental in many perl versions
72  
73 =head1 SEE ALSO
74  
75 L<Catmandu::Fix>
76  
77 =cut
« blib/lib/Catmandu/Fix/Condition/any_match.pm ↑ Summary blib/lib/Catmandu/Fix/filter.pm »