line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
2
|
|
|
2
|
|
84190
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo::Role; |
7
|
2
|
|
|
2
|
|
14
|
use namespace::clean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
8
|
2
|
|
|
2
|
|
749
|
use Catmandu::Fix::reject; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
11
|
|
9
|
2
|
|
|
2
|
|
905
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fix::Base'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has pass_fixes => (is => 'rw', default => sub {[]}); |
13
|
|
|
|
|
|
|
has fail_fixes => (is => 'rw', default => sub {[]}); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $target = caller; |
16
|
|
|
|
|
|
|
my ($fix, %opts) = @_; |
17
|
1
|
|
|
1
|
|
11
|
|
18
|
1
|
|
|
|
|
18
|
if (my $sym = $opts{as}) { |
19
|
|
|
|
|
|
|
my $sub = sub { |
20
|
1
|
50
|
|
|
|
18
|
my $data = shift; |
21
|
|
|
|
|
|
|
if ($opts{clone}) { |
22
|
0
|
|
|
0
|
|
|
$data = Clone::clone($data); |
23
|
0
|
0
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
|
my $cond = $fix->new(@_); |
25
|
|
|
|
|
|
|
$cond->fail_fixes([Catmandu::Fix::reject->new]); |
26
|
0
|
|
|
|
|
|
!!$cond->fix($data); |
27
|
0
|
|
|
|
|
|
}; |
28
|
0
|
|
|
|
|
|
no strict 'refs'; |
29
|
0
|
|
|
|
|
|
*{"${target}::$sym"} = $sub; |
30
|
2
|
|
|
2
|
|
16
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
216
|
|
31
|
0
|
|
|
|
|
|
} |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Catmandu::Fix::Condition - Role for all Catmandu::Fix conditionals |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if <Catmandu::Fix::Condition instance> |
45
|
|
|
|
|
|
|
<pass_fixes> |
46
|
|
|
|
|
|
|
else |
47
|
|
|
|
|
|
|
<fail_fixes> |
48
|
|
|
|
|
|
|
end |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
All L<Catmandu::Fix> conditions need to implement Catmandu::Fix::Condition. |
53
|
|
|
|
|
|
|
This subclass of L<Catmandu::Fix::Base> provides a list of fixes that need to |
54
|
|
|
|
|
|
|
be executed when a conditional matches (pass_fixes) and conditional that need |
55
|
|
|
|
|
|
|
to be executed when a conditional fails (fail_fixes). |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Conditions can be used as inline fixes as well: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use Catmandu::Fix::Condition::exists as => 'has_field'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $item = { foo => { bar => 1 } }; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has_field($item, 'foo.bar'); # true |
64
|
|
|
|
|
|
|
has_field($item, 'doz'); # false |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 EXAMPLES |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Catmandu core comes with the following conditions: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L<all_equal|Catmandu::Fix::Condition::all_equal> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L<all_match|Catmandu::Fix::Condition::all_match> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L<any_equal|Catmandu::Fix::Condition::any_equal> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L<any_match|Catmandu::Fix::Condition::any_match> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<exists|Catmandu::Fix::Condition::exists> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L<greater_than|Catmandu::Fix::Condition::greater_than> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L<in|Catmandu::Fix::Condition::in> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<is_array|Catmandu::Fix::Condition::is_array> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L<is_false|Catmandu::Fix::Condition::is_false> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<is_null|Catmandu::Fix::Condition::is_null> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L<is_number|Catmandu::Fix::Condition::is_number> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<is_object|Catmandu::Fix::Condition::is_object> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<is_string|Catmandu::Fix::Condition::is_string> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L<is_true|Catmandu::Fix::Condition::is_true> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L<less_than|Catmandu::Fix::Condition::less_than> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |