line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
1372
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo::Role; |
7
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
401
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Fix::Condition'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
requires 'path'; |
12
|
|
|
|
|
|
|
requires 'emit_test'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ($self, $fixer, $label) = @_; |
15
|
|
|
|
|
|
|
my $path = $fixer->split_path($self->path); |
16
|
0
|
|
|
0
|
0
|
|
my $key = pop @$path; |
17
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $pass_fixes = $self->pass_fixes; |
19
|
|
|
|
|
|
|
my $fail_fixes = $self->fail_fixes; |
20
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $fail_label; |
22
|
|
|
|
|
|
|
my $fail_block = $fixer->emit_block( |
23
|
0
|
|
|
|
|
|
sub { |
24
|
|
|
|
|
|
|
$fail_label = shift; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
|
|
$fixer->emit_fixes($fail_fixes); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $has_match_var = $fixer->generate_var; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $perl = $fixer->emit_declare_vars($has_match_var, '0'); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$perl .= $fixer->emit_walk_path( |
35
|
|
|
|
|
|
|
$fixer->var, |
36
|
|
|
|
|
|
|
$path, |
37
|
|
|
|
|
|
|
sub { |
38
|
|
|
|
|
|
|
my $var = shift; |
39
|
|
|
|
|
|
|
$fixer->emit_get_key( |
40
|
0
|
|
|
0
|
|
|
$var, $key, |
41
|
|
|
|
|
|
|
sub { |
42
|
|
|
|
|
|
|
my $var = shift; |
43
|
|
|
|
|
|
|
my $perl = "${has_match_var} ||= 1;"; |
44
|
0
|
|
|
|
|
|
$perl .= "unless (" |
45
|
0
|
|
|
|
|
|
. $self->emit_test($var, $fixer) . ") {"; |
46
|
0
|
|
|
|
|
|
if (@$fail_fixes) { |
47
|
|
|
|
|
|
|
$perl .= "goto ${fail_label};"; |
48
|
0
|
0
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
else { |
50
|
|
|
|
|
|
|
$perl .= "last ${label};"; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
$perl .= "}"; |
53
|
|
|
|
|
|
|
$perl; |
54
|
0
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$perl .= "if (${has_match_var}) {"; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$perl .= $fixer->emit_fixes($pass_fixes); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$perl .= "last ${label};"; |
64
|
|
|
|
|
|
|
$perl .= "}"; |
65
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
if (@$fail_fixes) { |
67
|
|
|
|
|
|
|
$perl .= $fail_block; |
68
|
0
|
0
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$perl; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Catmandu::Fix::Condition::SimpleAllTest - Base class to ease the construction of all match conditionals |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SYNOPSIS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
package Catmandu::Fix::Condition::is_even |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use Catmandu::Sane; |
87
|
|
|
|
|
|
|
use Moo; |
88
|
|
|
|
|
|
|
use Catmandu::Fix::Has; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
with 'Catmandu::Fix::Condition::SimpleAllTest'; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub emit_test { |
95
|
|
|
|
|
|
|
my ($self, $var) = @_; |
96
|
|
|
|
|
|
|
"is_value(${var}) && ${var} % 2 == 0"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Now you can write in your fixes |
102
|
|
|
|
|
|
|
is_even('my_field') # True when my_field is 0,2,4,6,... |
103
|
|
|
|
|
|
|
is_even('my_field.*') # True when all my_field's are 0,2,4,6,... |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The is a base class to ease the construction of Catmandu::Fix::Conditional-s. An 'all' test matches |
108
|
|
|
|
|
|
|
when all node on a path match a condition. E.g. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
all_match('title','abc') # true when the title field contains 'abc' |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
all_match('title.*','abc') # true when all title fields contain 'abc' |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SEE ALSO |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<Catmandu::Fix::Condition::all_match>, |
117
|
|
|
|
|
|
|
L<Catmandu::Fix::Condition::greater_than>, |
118
|
|
|
|
|
|
|
L<Catmandu::Fix::Condition::less_than> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |