Policy/Individual.pm

filter: Statementstmt 80.3% 53 / 66 Branchbran 58.8% 20 / 34 Conditioncond 44.4% 4 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 84.0% 21 / 25 Podpod 100% 15 / 15 totaltotal 74.1% 115 / 155 CC 21 SCAR 14.3
CC
21
Cov
71%
url
12.0
Program
12.0
version
12.0
CRAP 4.2
« Policy.pm ↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Software::Security::Policy::Individual;
4  
5 2 our $VERSION = '0.11'; # VERSION
6  
7 2 ▶use parent 'Software::Security::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: The Individual Security Policy
9  
10 2 ▶use Data::Section -setup => { header_re => qr/\A__([^_]+)__\Z/ };
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Text::Template ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶sub name { 'individual' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
14  
15  
16 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
17 6 my ($class, $arg) = @_;
18  
19 6 ▶ Carp::croak "no maintainer is specified" unless $arg->{maintainer};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{"maintainer"} 0 6 6
20  
21 6 bless $arg => $class;
22 }
23  
24  
25 0 ▶sub url { (defined $_[0]->{url} ? $_[0]->{url} :
Subroutine url: not called CC=3 SCAR=24.8
Pod documented
26 (defined $_[0]->{git_url} ? $_[0]->{git_url} :
27 0 ▶ undef)) }
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0]{'url'} ? : 0 0 0
defined $_[0]{'git_url'} ? : 0 0 0
28  
29 24 ▶sub git_url { (defined $_[0]->{git_url} ? $_[0]->{git_url} :
Subroutine git_url: called CC=3 SCAR=11.0
Pod documented
30 (defined $_[0]->{url} ? $_[0]->{url} :
31 24 ▶ undef)) }
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0]{'git_url'} ? : 12 12 24
defined $_[0]{'url'} ? : 4 8 12
32  
33  
34 16 ▶sub perl_support_years { $_[0]->{perl_support_years} };
Subroutine perl_support_years: called CC=1 SCAR=0.0
Pod documented
35  
36 16 ▶sub minimum_perl_version { $_[0]->{minimum_perl_version} }
Subroutine minimum_perl_version: called CC=1 SCAR=0.0
Pod documented
37  
38 16 ▶sub timeframe {
Subroutine timeframe: called CC=4 SCAR=13.9
Pod documented
39 16 ▶ return $_[0]->{timeframe} if defined $_[0]->{timeframe};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]{"timeframe"} 8 8 16
40 return $_[0]->{timeframe_quantity} . ' ' . $_[0]->{timeframe_units}
41 if defined $_[0]->{timeframe_quantity} &&
42 8 ▶ defined $_[0]->{timeframe_units};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]{"timeframe_quantity"} and defined $_[0]{"timeframe_units"} 2 6 8
Condition66%2/3
defined $_[0]{"timeframe_quantity"} and defined $_[0]{"timeframe_units"}
!ll&&!rl&&r
602
MC/DC50%1/2
defined $_[0]{"timeframe_quantity"} and defined $_[0]{"timeframe_units"}
defined $_[0]{"timeframe_quantity"} defined $_[0]{"timeframe_units"}
Truth table66%2/3
A and B
A= defined $_[0]{"timeframe_quantity"}B= defined $_[0]{"timeframe_units"}
ABresult
0X0
100
111
43 6 return '5 days';
44 }
45  
46 28 ▶sub maintainer { $_[0]->{maintainer} }
Subroutine maintainer: called CC=1 SCAR=0.0
Pod documented
47  
48 0 ▶sub _dotless_maintainer {
Subroutine _dotless_maintainer: not called CC=1 SCAR=6.9
49 0 my $maintainer = $_[0]->maintainer;
50 0 $maintainer =~ s/\.$//;
51 0 return $maintainer;
52 }
53  
54 32 ▶sub report_url { $_[0]->{report_url} }
Subroutine report_url: called CC=1 SCAR=0.0
Pod documented
55  
56  
57 224 ▶sub program { $_[0]->{program} || $_[0]->{Program} || 'this program' }
Subroutine program: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"program"} or $_[0]{"Program"} or "this program" 112 112 224
Condition66%2/3
$_[0]{"program"} or $_[0]{"Program"}
l!l&&r!l&&!r
1120112
MC/DC50%1/2
$_[0]{"program"} or $_[0]{"Program"}
$_[0]{"program"} $_[0]{"Program"}
Truth table66%2/3
A or B
A= $_[0]{"program"}B= $_[0]{"Program"}
ABresult
1X1
011
000
58  
59  
60 0 ▶sub Program { $_[0]->{Program} || $_[0]->{program} || 'This program' }
Subroutine Program: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"Program"} or $_[0]{"program"} or "This program" 0 0 0
Condition0%0/3
$_[0]{"Program"} or $_[0]{"program"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"Program"} or $_[0]{"program"}
$_[0]{"Program"} $_[0]{"program"}
Truth table0%0/3
A or B
A= $_[0]{"Program"}B= $_[0]{"program"}
ABresult
1X1
011
000
61  
62  
63 16 ▶sub summary { shift->_fill_in('SUMMARY') }
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
64  
65  
66 16 ▶sub security_policy { shift->_fill_in('SECURITY-POLICY') }
Subroutine security_policy: called CC=1 SCAR=0.0
Pod documented
67  
68  
69 16 ▶sub fulltext {
Subroutine fulltext: called CC=1 SCAR=0.0
Pod documented
70 16 my ($self) = @_;
71 16 return join "\n", $self->summary, $self->security_policy;
72 }
73  
74  
75 0 ▶sub version {
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
76 0 my ($self) = @_;
77 0 ▶ my $pkg = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
78 0 $pkg =~ s/.+:://;
79 0 my (undef, @vparts) = split /_/, $pkg;
80  
81 0 ▶ return unless @vparts;
Branch: 1 branch
BranchTrueFalseTotal
unless @vparts 0 0 0
82 0 return join '.', @vparts;
83 }
84  
85 32 ▶sub _fill_in {
Subroutine _fill_in: called CC=2 SCAR=7.1
86 32 my ($self, $which) = @_;
87  
88 32 ▶ Carp::confess "couldn't build $which section" unless
Branch: 1 branch
BranchTrueFalseTotal
unless my $template = $self->section_data($which) 0 32 32
89 my $template = $self->section_data($which);
90  
91 32 return Text::Template->fill_this_in(
92 $$template,
93 HASH => { self => \$self },
94 DELIMITERS => [ qw({{ }}) ],
95 );
96 }
97  
98 16 ▶sub _perl_supported_version_section {
Subroutine _perl_supported_version_section: called CC=3 SCAR=11.2
99 16 my $self = shift;
100 16 my $program = $self->program;
101 16 ▶ if (my $minimum_perl_version = $self->minimum_perl_version) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $minimum_perl_version = $self->minimum_perl_version) { } 0 16 16
elsif (my $perl_support_years = $self->perl_support_years) { } 14 2 16
102 0 return <<EOF;
103  
104 Note that the $program project only supports major versions of Perl since
105 $minimum_perl_version, even though $program will run on
106 older versions of Perl. If a security fix requires us to increase
107 the minimum version of Perl that is supported, then we may do so.
108 EOF
109 } elsif (my $perl_support_years = $self->perl_support_years) {
110 return <<EOF
111  
112 Note that the $program project only supports major versions of Perl
113 released in the past $perl_support_years years, even though $program will run on
114 older versions of Perl. If a security fix requires us to increase
115 the minimum version of Perl that is supported, then we may do so.
116 EOF
117 14 } else {
118 2 return '';
119 }
120 }
121 16 ▶sub _latest_policy_location {
Subroutine _latest_policy_location: called CC=2 SCAR=6.9
122 16 my $self = shift;
123 16 my $git_url = $self->git_url;
124 16 my $program = $self->program;
125 16 ▶ if (defined $git_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $git_url) { } 8 8 16
126 8 return <<EOF;
127  
128 The latest version of the Security Policy can be found in the
129 [git repository for $program]($git_url).
130 EOF
131 } else {
132 8 return '';
133 }
134 }
135  
136 32 ▶sub _how_to_report {
Subroutine _how_to_report: called CC=3 SCAR=11.2
137 32 my $self = shift;
138 32 ▶ if ( my $url = $self->report_url ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = $self->report_url) { } 8 24 32
139 8 ▶ if ( $url eq $self->git_url . "/security/advisories" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url eq $self->git_url . '/security/advisories') { } 8 0 8
140 8 return "via the project\n[Security Advisories](${url})";
141 }
142 else {
143 0 return "using " . $url;
144 }
145 }
146 else {
147 24 return "by email to " . $self->maintainer;
148 }
149 }
150  
151  
152 2 1;
153  
154 =pod
155  
156 =encoding UTF-8
157  
158 =head1 NAME
159  
160 Software::Security::Policy::Individual - The Individual Security Policy
161  
162 =head1 VERSION
163  
164 version 0.11
165  
166 =head1 SYNOPSIS
167  
168 use strict;
169 use warnings;
170  
171 use Software::Security::Policy::Individual;
172  
173 my $policy = Software::Security::Policy::Individual->new({
174 maintainer => 'Timothy Legge <timlegge@gmail.com>', # required
175 program => 'Software::Security::Policy',
176 timeframe => '7 days',
177 url => 'https://github.com/CPAN-Security/Software-Security-Policy/blob/main/SECURITY.md',
178 perl_support_years => '10',
179 });
180  
181 print $policy->fulltext, "\n";
182  
183 =head1 METHODS
184  
185 =over
186  
187 =item new
188  
189 my $policy = $subclass->new(\%arg);
190  
191 This method returns a new security policy object for the given
192 security policy class. Valid arguments are:
193  
194 =back
195  
196 =head2 ATTRIBUTES
197  
198 =over
199  
200 =item maintainer
201  
202 the current maintainer for the distibrution; B<Required>
203  
204 =item timeframe
205  
206 the time to expect acknowledgement of a security issue. Should
207 include the units such as '5 days or 2 weeks';
208  
209 Default: 5 days
210  
211 =item timeframe_quantity
212  
213 the amount of time to expect an acknowledgement of a security issue.
214 Only used if timeframe is undefined and timeframe_units is defined
215 (eg. '5')
216  
217 =item timeframe_units
218  
219 the units of time to expect an acknowledgement of a security issue.
220 Only used if timeframe is undefined and timeframe_quantity is defined
221 (eg. 'days')
222  
223 =item url
224  
225 a url where the most current security policy can be found.
226  
227 =item git_url
228  
229 a git url where the most current security policy can be found.
230  
231 =item report_url
232  
233 the URL where you can report security issues.
234  
235 =item perl_support_years
236  
237 the number of years for which past major versions of Perl would be
238 supported
239  
240 =item program
241  
242 the name of software for use in the middle of a sentence
243  
244 =item Program
245  
246 the name of software for use in the beginning of a sentence
247  
248 C<program> and C<Program> arguments may be specified both, either one or none.
249 Each argument, if not specified, is defaulted to another one, or to properly
250 capitalized "this program", if both arguments are omitted.
251  
252 =back
253  
254 =head2 minimum_perl_version
255  
256 The minimum version of perl that is supported.
257  
258 =head2 perl_support_years
259  
260 Get the number of years for which past major versions of Perl would be
261 supported.
262  
263 =head2 timeframe
264  
265 Get the expected response time. Defaults to 5 days and uses
266 timeframe_quantity and timeframe_units if the timeframe attribute
267 us undefined.
268  
269 =head2 maintainer
270  
271 Get the maintainer that should be contacted for security issues.
272  
273 =head2 report_url
274  
275 Get the URL where you can report security issues.
276  
277 These methods are attribute readers.
278  
279 =head2 program
280  
281 Name of software for using in the middle of a sentence.
282  
283 The method returns value of C<program> constructor argument (if it evaluates as true, i. e.
284 defined, non-empty, non-zero), or value of C<Program> constructor argument (if it is true), or
285 "this program" as the last resort.
286  
287 Default: 'this program'
288  
289 =head2 Program
290  
291 Name of software for using at the beginning of a sentence.
292  
293 The method returns value of C<Program> constructor argument (if it is true), or value of C<program>
294 constructor argument (if it is true), or "This program" as the last resort.
295  
296 Default: 'This program'
297  
298 =head2 name
299  
300 This method returns the name of the policy, suitable for shoving in the middle
301 of a sentence, generally with a leading capitalized "The."
302  
303 =head2 url
304  
305 This method returns the URL at which a canonical text of the security policy can be
306 found, if one is available. If possible, this will point at plain text, but it
307 may point to an HTML resource.
308  
309 =head2 git_url
310  
311 This method returns the git URL at which a canonical text of the security policy can be
312 found, if one is available. If possible, this will point at plain text, but it
313 may point to an HTML resource.
314  
315 =head2 summary
316  
317 This method returns a snippet of text, usually a few lines, indicating the
318 maintainer as well as an indication of the policy under which the software
319 is maintained.
320  
321 =head2 security_policy
322  
323 This method returns the full text of the policy.
324  
325 =head2 fulltext
326  
327 This method returns the complete text of the policy.
328  
329 =head2 version
330  
331 This method returns the version of the policy. If the security
332 policy is not versioned, this method will return undefined.
333  
334 =head1 AUTHOR
335  
336 Timothy Legge <timlegge@gmail.com>
337  
338 =head1 COPYRIGHT AND LICENSE
339  
340 This software is copyright (c) 2025 by Timothy Legge <timlegge@gmail.com>.
341  
342 This is free software; you can redistribute it and/or modify it under
343 the same terms as the Perl 5 programming language system itself.
344  
345 =cut
346  
347 __DATA__
« Policy.pm ↑ Summary