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