| 1 | package CSAF::Validator; | ||
| 2 | |||
| 3 | 33 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 33 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 33 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 33 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 0 | ▶ | use CSAF::Validator::MandatoryTests; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use CSAF::Validator::OptionalTests; | ||
| 10 | use CSAF::Validator::InformativeTests; | ||
| 11 | |||
| 12 | use CSAF::Validator::Schema; | ||
| 13 | use CSAF::Validator::Message; | ||
| 14 | |||
| 15 | use constant DEBUG => $ENV{CSAF_VALIDATOR_DEBUG}; | ||
| 16 | |||
| 17 | use Moo; | ||
| 18 | extends 'CSAF::Validator::Base'; | ||
| 19 | with 'CSAF::Util::Log'; | ||
| 20 | |||
| 21 | sub validate { | ||
| 22 | |||
| 23 | my ($self, $type) = @_; | ||
| 24 | |||
| 25 | my %validator = ( | ||
| 26 | |||
| 27 | # 9.1.14 Conformance Clause 14: CSAF basic validator | ||
| 28 | schema => sub { CSAF::Validator::Schema->new($self->csaf)->validate }, | ||
| 29 | mandatory => sub { CSAF::Validator::MandatoryTests->new($self->csaf)->validate }, | ||
| 30 | |||
| 31 | # 9.1.15 Conformance Clause 15: CSAF extended validator | ||
| 32 | optional => sub { CSAF::Validator::OptionalTests->new($self->csaf)->validate }, | ||
| 33 | |||
| 34 | # 9.1.16 Conformance Clause 16: CSAF full validator | ||
| 35 | informative => sub { CSAF::Validator::InformativeTests->new($self->csaf)->validate }, | ||
| 36 | |||
| 37 | ); | ||
| 38 | |||
| 39 | my @types = (qw[schema mandatory optional informative]); | ||
| 40 | my @messages = (); | ||
| 41 | |||
| 42 | if (defined $type && defined $validator{$type}) { | ||
| 43 | @types = ($type); | ||
| 44 | } | ||
| 45 | |||
| 46 | foreach (@types) { | ||
| 47 | push @messages, $validator{$_}->(); | ||
| 48 | } | ||
| 49 | |||
| 50 | push @{$self->messages}, @messages; | ||
| 51 | |||
| 52 | if (DEBUG && @{$self->messages}) { | ||
| 53 | $self->log->debug('Validation messages(s)'); | ||
| 54 | $self->log->debug(sprintf('- %s', $_)) for (@{$self->messages}); | ||
| 55 | } | ||
| 56 | |||
| 57 | return @{$self->messages}; | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | 1; | ||
| 62 | |||
| 63 | __END__ | ||