App/CSAF/Renderer.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 99 CC 9 SCAR 37.3
CC
9
Cov
0%
run
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 41.6
1 package App::CSAF::Renderer;
2  
3 use 5.010001;
4 use strict;
5 use warnings;
6 use utf8;
7  
8 use Getopt::Long qw( GetOptionsFromArray :config gnu_compat );
9 use Pod::Usage;
10 use Carp;
11 use Log::Any::Adapter;
12  
13 use CSAF::Util qw(file_write);
14 use CSAF::Util::App qw(cli_error cli_version);
15 use CSAF::Parser;
16  
17 sub run {
18  
19 my ($class, @args) = @_;
20  
21 my %options = ();
22  
23 delete $ENV{CSAF_DEBUG};
24  
25 GetOptionsFromArray(
26 \@args, \%options, qw(
27 file|f=s
28 output|o=s
29 template|t=s
30 verbose|v
31  
32 help|h
33 man
34 version
35 )
36 ) or pod2usage(-verbose => 0);
37  
38 pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man};
39 pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help};
40  
41 return cli_version if defined $options{version};
42  
43 if (defined $options{verbose}) {
44 Log::Any::Adapter->set('Stderr');
45 }
46  
47 $options{template} //= 'default';
48  
49 unless ($options{file}) {
50 cli_error("Specify CSAF input file");
51 return 255;
52 }
53  
54 my $csaf = eval { CSAF::Parser->new(file => $options{file})->parse };
55  
56 if ($@) {
57 cli_error($@);
58 return 255;
59 }
60  
61 if (my @errors = $csaf->validate) {
62 say STDERR $_ for (@errors);
63 }
64  
65 my $rendered = $csaf->render(format => 'html', template => $options{template});
66  
67 unless ($options{output}) {
68 say $rendered;
69 return 0;
70 }
71  
72 file_write($options{output}, $rendered);
73 return 0;
74  
75 }
76  
77 1;
78  
79 __END__