line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Condition::valid; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
697
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
405
|
use Catmandu::Util qw(require_package); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
58
|
|
9
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
345
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
12
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has name => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has validator_opts => (fix_opt => 'collect'); |
15
|
|
|
|
|
|
|
has validator => (is => 'lazy', init_arg => undef); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Catmandu::Fix::Condition::Builder::Simple'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_value_tester { |
20
|
2
|
|
|
2
|
|
21
|
my ($self) = @_; |
21
|
2
|
|
|
|
|
34
|
my $validator = $self->validator; |
22
|
|
|
|
|
|
|
sub { |
23
|
2
|
|
|
2
|
|
9
|
$validator->is_valid($_[0]); |
24
|
|
|
|
|
|
|
} |
25
|
2
|
|
|
|
|
18
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_validator { |
28
|
2
|
|
|
2
|
|
17
|
my ($self) = @_; |
29
|
2
|
|
|
|
|
11
|
require_package($self->name, 'Catmandu::Validator') |
30
|
|
|
|
|
|
|
->new($self->validator_opts); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Catmandu::Fix::Condition::valid - Execute fixes if the data passes validation |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# reject all items not conforming to a schema |
46
|
|
|
|
|
|
|
select valid('', JSONSchema, schema: "my/schema.json") |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# check the author field |
49
|
|
|
|
|
|
|
unless valid(author, JSONSchema, schema: "my/author.schema.json") |
50
|
|
|
|
|
|
|
... # repair or give warning |
51
|
|
|
|
|
|
|
end |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SEE ALSO |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
See L<Catmandu::Fix::validate> to check and get validation errors. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |