| 1 | package Catmandu::Validator::PICA; | ||||||||||
| 2 | 1 | ▶ | use Catmandu::Sane; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Catmandu::Util qw(:io :is :check); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use PICA::Schema; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '1.18'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | with qw(Catmandu::Validator); | |||||||||
| 10 | |||||||||||
| 11 | has schema => ( | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | required => 1, | ||||||||||
| 14 | 5 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||
| 15 | 5 | my ($self, $schema) = @_; | |||||||||
| 16 | 5 | ▶ | unless (is_instance($schema, 'PICA::Schema')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 3 | ▶ | if (is_string($schema)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 2 | ▶ | if ($schema =~ /\.y.?ml/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 1 | $schema = read_yaml($schema); | |||||||||
| 20 | } else { | ||||||||||
| 21 | 1 | $schema = read_json($schema); | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | 3 | $self->{schema} = PICA::Schema->new(check_hash_ref($schema)); | |||||||||
| 25 | } | ||||||||||
| 26 | } | ||||||||||
| 27 | 1 | ); | |||||||||
| 28 | |||||||||||
| 29 | 1 | has ignore_unknown_fields => ( is => 'ro' ); | |||||||||
| 30 | 1 | has ignore_unknown_subfields => ( is => 'ro' ); | |||||||||
| 31 | 1 | has ignore_unknown => ( is => 'ro' ); | |||||||||
| 32 | 1 | has allow_deprecated_fields => ( is => 'ro' ); | |||||||||
| 33 | 1 | has allow_deprecated_subfields => ( is => 'ro' ); | |||||||||
| 34 | 1 | has allow_deprecated_codes => ( is => 'ro' ); | |||||||||
| 35 | 1 | has allow_deprecated => ( is => 'ro' ); | |||||||||
| 36 | 1 | has ignore_subfield_order => ( is => 'ro' ); | |||||||||
| 37 | 1 | has ignore_subfields => ( is => 'ro' ); | |||||||||
| 38 | |||||||||||
| 39 | has options => ( | ||||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | init_arg => undef, | ||||||||||
| 42 | 5 | ▶ | builder => sub { | ||||||||
|
Subroutine
_build_options: called CC=1 SCAR=0.0
| |||||||||||
| 43 | return { | ||||||||||
| 44 | 5 | ignore_unknown_fields => $_[0]->ignore_unknown_fields, | |||||||||
| 45 | ignore_unknown_subfields => $_[0]->ignore_unknown_subfields, | ||||||||||
| 46 | ignore_unknown => $_[0]->ignore_unknown, | ||||||||||
| 47 | allow_deprecated_fields => $_[0]->allow_deprecated_fields, | ||||||||||
| 48 | allow_deprecated_subfields => $_[0]->allow_deprecated_subfields, | ||||||||||
| 49 | allow_deprecated_codes => $_[0]->allow_deprecated_codes, | ||||||||||
| 50 | allow_deprecated => $_[0]->allow_deprecated, | ||||||||||
| 51 | ignore_subfield_order => $_[0]->ignore_subfield_order, | ||||||||||
| 52 | ignore_subfields => $_[0]->ignore_subfields, | ||||||||||
| 53 | } | ||||||||||
| 54 | }, | ||||||||||
| 55 | 1 | ); | |||||||||
| 56 | |||||||||||
| 57 | 6 | ▶ | sub validate_data { | ||||||||
|
Subroutine
validate_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 6 | my ($self, $record) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 6 | my @errors = $self->{schema}->check($record, %{$self->options}); | |||||||||
| 61 | |||||||||||
| 62 | 6 | ▶ | return @errors ? \@errors : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | 1; | |||||||||
| 66 | __END__ | ||||||||||