App/CVSS.pm

filter: Statementstmt 70.0% 63 / 90 Branchbran 52.1% 24 / 46 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 84.6% 11 / 13 Podpod 100% 2 / 2 totaltotal 64.9% 100 / 154 CC 25 SCAR 37.9
CC
25
Cov
63%
run
69.1
_print
12.0
cli_error
2.0
CRAP 44.2
« CVSS/v4.pm ↑ Summary CVSS/v2.pm »
1 package App::CVSS;
2  
3 1 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Getopt::Long qw(GetOptionsFromArray :config gnu_compat);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use CVSS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = $CVSS::VERSION;
17  
18 1 my %options = (format => 'json');
19  
20 0 ▶sub _print { print(($_[0] || '') . (defined $options{null} ? "\0" : "\n")) }
Subroutine _print: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'null'} ? : 0 0 0
Condition0%0/2
$_[0] || ''
l!l
00
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
21  
22 0 ▶sub cli_error {
Subroutine cli_error: not called CC=1 SCAR=6.9
Pod documented
23 0 my ($error) = @_;
24 0 $error =~ s/ at .* line \d+.*//;
25 0 print STDERR "ERROR: $error\n";
26 }
27  
28 2 ▶sub run {
Subroutine run: called CC=23 SCAR=42.4
Pod documented
29  
30 2 my ($class, @args) = @_;
31  
32 2 ▶ GetOptionsFromArray(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, \%options, ("help|h", "man", "v", "vector-string=s", "severity", "score", "base-score", "base-severity", "temporal-score", "temporal-severity", "environmental-score", "environmental-severity", "exploitability-score", "impact-score", "modified-impact-score", "null|0", "format=s", "json", "xml")) or pod2usage("-verbose", 0) 2 0 2
33 \@args, \%options, qw(
34 help|h
35 man
36 v
37  
38 vector-string=s
39  
40 severity
41 score
42  
43 base-score
44 base-severity
45  
46 temporal-score
47 temporal-severity
48  
49 environmental-score
50 environmental-severity
51  
52 exploitability-score
53 impact-score
54 modified-impact-score
55  
56 null|0
57 format=s
58  
59 json
60 xml
61 )
62 ) or pod2usage(-verbose => 0);
63  
64 2 ▶ pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"man"} 0 2 2
65 2 ▶ pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"help"} 0 2 2
66  
67 2 ▶ if (defined $options{v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"v"}) 0 2 2
68  
69 0 (my $progname = $0) =~ s/.*\///;
70  
71 0 say <<"VERSION";
72 $progname version $VERSION
73  
74 Copyright 2023-2025, Giuseppe Di Terlizzi <gdt\@cpan.org>
75  
76 This program is part of the "CVSS" distribution and is free software;
77 you can redistribute it and/or modify it under the same terms as Perl itself.
78  
79 Complete documentation for $progname can be found using 'man $progname'
80 or on the internet at <https://metacpan.org/dist/CVSS>.
81 VERSION
82  
83 0 return 0;
84  
85 }
86  
87 2 my ($vector_string) = @args;
88  
89 2 ▶ pod2usage(-verbose => 1) if !$vector_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $vector_string 0 2 2
90  
91 2 ▶ $options{format} = 'json' if defined $options{json};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"json"} 2 0 2
92 2 ▶ $options{format} = 'xml' if defined $options{xml};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"xml"} 1 1 2
93  
94 2 ▶ $options{'base-severity'} = 1 if defined $options{severity};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"severity"} 0 2 2
95 2 ▶ $options{'base-score'} = 1 if defined $options{score};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"score"} 0 2 2
96  
97 2 my $cvss = eval { CVSS->from_vector_string($vector_string) };
98  
99 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
100 0 cli_error($@);
101 0 return 1;
102 }
103  
104 2 ▶ if ($options{'base-severity'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"base-severity"}) 0 2 2
105 0 _print $cvss->base_severity;
106 0 return 0;
107 }
108  
109 2 ▶ if ($options{'base-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"base-score"}) 0 2 2
110 0 _print $cvss->base_score;
111 0 return 0;
112 }
113  
114 2 ▶ if ($cvss->version <= 3.1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cvss->version <= "3.1") 2 0 2
115  
116 2 ▶ if ($options{'environmental-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"environmental-score"}) 0 2 2
117 0 _print $cvss->environmental_score;
118 0 return 0;
119 }
120  
121 2 ▶ if ($options{'environmental-severity'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"environmental-severity"}) 0 2 2
122 0 _print $cvss->environmental_severity;
123 0 return 0;
124 }
125  
126 2 ▶ if ($options{'temporal-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"temporal-score"}) 0 2 2
127 0 _print $cvss->temporal_score;
128 0 return 0;
129 }
130  
131 2 ▶ if ($options{'temporal-severity'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"temporal-severity"}) 0 2 2
132 0 _print $cvss->temporal_severity;
133 0 return 0;
134 }
135  
136 2 ▶ if ($options{'impact-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"impact-score"}) 0 2 2
137 0 _print $cvss->impact_score;
138 0 return 0;
139 }
140  
141 2 ▶ if ($options{'exploitability-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"exploitability-score"}) 0 2 2
142 0 _print $cvss->exploitability_score;
143 0 return 0;
144 }
145  
146 2 ▶ if ($options{'modified-impact-score'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"modified-impact-score"}) 0 2 2
147 0 _print $cvss->modified_impact_score;
148 0 return 0;
149 }
150  
151 }
152  
153 2 ▶ if ($options{format} eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"format"} eq "json") 1 1 2
154 1 print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($cvss);
155 1 return 0;
156 }
157  
158 1 ▶ if ($options{format} eq 'xml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"format"} eq "xml") 1 0 1
159 1 print $cvss->to_xml;
160 1 return 0;
161 }
162  
163 }
164  
165 1 1;
166  
167 __END__
« CVSS/v4.pm ↑ Summary CVSS/v2.pm »