line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
93756
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
1
|
|
|
1
|
|
6
|
use Catmandu::Util qw(require_package); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
276
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
397
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
10
|
1
|
|
|
1
|
|
6
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
11
|
1
|
|
|
1
|
|
578
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has name => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has error_field => (fix_opt => 1, default => 'errors'); |
15
|
|
|
|
|
|
|
has validator_opts => (fix_opt => 'collect'); |
16
|
|
|
|
|
|
|
has validator => (is => 'lazy', init_arg => undef); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
require_package($self->name, 'Catmandu::Validator') |
22
|
3
|
|
|
3
|
|
20
|
->new($self->validator_opts); |
23
|
3
|
|
|
|
|
11
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $validator = $self->validator; |
28
|
3
|
|
|
3
|
|
22
|
my $get = as_path($self->path)->getter; |
29
|
|
|
|
|
|
|
my $set_error = as_path($self->error_field)->creator; |
30
|
3
|
|
|
|
|
39
|
|
31
|
3
|
|
|
|
|
12
|
sub { |
32
|
3
|
|
|
|
|
21
|
my ($data) = @_; |
33
|
|
|
|
|
|
|
my $values = $get->($data); |
34
|
|
|
|
|
|
|
for my $val (@$values) { |
35
|
3
|
|
|
3
|
|
5
|
next if $validator->is_valid($val); |
36
|
3
|
|
|
|
|
42
|
$set_error->($data, $validator->last_errors); |
37
|
3
|
|
|
|
|
6
|
} |
38
|
3
|
100
|
|
|
|
10
|
$data; |
39
|
2
|
|
|
|
|
31
|
} |
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
45
|
|
42
|
|
|
|
|
|
|
1; |
43
|
3
|
|
|
|
|
25
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catmandu::Fix::validate - validate data and keep errors |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Check author field against a JSON Schema |
54
|
|
|
|
|
|
|
validate('author', JSONSchema, schema: 'my/schema.json') |
55
|
|
|
|
|
|
|
if exists(errors) |
56
|
|
|
|
|
|
|
... # do something |
57
|
|
|
|
|
|
|
end |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Check item against a custom validator, store in errors in 'warnings' |
60
|
|
|
|
|
|
|
validate('author', MyValidatorClass, error_field: warnings) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This L<Catmandu::Fix> validates data with a L<Catmandu::Validator> and stores |
65
|
|
|
|
|
|
|
errors in field C<errors> for further inspection. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 CONFIGURATION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item error_field |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Path where to store errors. Set to C<errors> by default. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Additional options are passed to the validator. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SEE ALSO |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
L<Catmandu::Fix::Condition::valid> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |