CSAF/Validator/Base.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 78 CC 5 SCAR 15.8
CC
5
Cov
0%
exec_test
12.0
has_error
6.0
has_warning
6.0
CRAP 4.9
1 package CSAF::Validator::Base;
2  
3 use 5.010001;
4 use strict;
5 use warnings;
6 use utf8;
7  
8 use CSAF::Validator::Message;
9 use List::Util qw(first);
10  
11 use Moo;
12 extends 'CSAF::Base';
13  
14 has messages => (is => 'rw', default => sub { [] });
15 has tests => (is => 'rw', default => sub { [] });
16  
17 sub validate {
18 my $self = shift;
19 $self->exec_test($_) for (@{$self->tests});
20 return @{$self->messages};
21 }
22  
23 sub has_error {
24 return (first { $_->type eq 'error' } @{$_[0]->messages}) ? 1 : 0;
25 }
26  
27 sub has_warning {
28 return (first { $_->type eq 'warning' } @{$_[0]->messages}) ? 1 : 0;
29 }
30  
31 sub add_message {
32  
33 my ($self, %params) = @_;
34  
35 my $message = CSAF::Validator::Message->new(%params);
36 push @{$self->messages}, $message;
37  
38 }
39  
40 sub exec_test {
41  
42 my ($self, $test_id) = @_;
43  
44 my $test_sub = "TEST_$test_id";
45 $test_sub =~ tr/\./_/;
46  
47 if (my $code_ref = $self->can($test_sub)) {
48 eval { $code_ref->($self) };
49 Carp::croak "Failed to execute test $test_id: $@" if ($@);
50 return 1;
51 }
52  
53 Carp::carp "Missing test $test_id";
54  
55 }
56  
57 1;
58  
59 __END__