License.pm

filter: Statementstmt 92.7% 474 / 511 Branchbran 82.8% 179 / 216 Conditioncond 73.9% 159 / 215 MC/DCmcdc 37.3% 40 / 107 Subroutinesub 100% 39 / 39 Podpod 20.0% 2 / 10 totaltotal 81.3% 893 / 1098 CC 214 SCAR 48.0
CC
214
Cov
86%
resolve
225.7
__ANON__
22.7
__ANON__
20.6
CRAP 121.7
↑ Summary License/Naming.pm »
1 12 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 12 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use builtin qw(load_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 String::License - detect source code license statements in a text string
13  
14 =head1 VERSION
15  
16 Version v0.1.1
17  
18 =head1 SYNOPSIS
19  
20 use String::License;
21 use String::License::Naming::Custom;
22  
23 my $string = 'Licensed under same terms as Perl itself';
24  
25 my $expressed = String::License->new( string => $string );
26 my $expression = $expressed->as_text; # => "Perl"
27  
28 my $desc = String::License::Naming::Custom->new;
29 my $described = String::License->new( string => $string, naming => $desc );
30 my $description = $described->as_text; # => "The Perl 5 License"
31  
32 =head1 DESCRIPTION
33  
34 L<String::License> identifies license statements in a string
35 and serializes them in a normalized format.
36  
37 =cut
38  
39 class String::License v0.1.1;
40  
41 12 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 12 ▶use Log::Any ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43 12 ▶use List::Util qw(any max uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 12 ▶use Array::IntSpan;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 12 ▶use Regexp::Pattern::License 3.4.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 12 ▶use Regexp::Pattern 0.2.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 12 ▶use String::License::Naming::Custom;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 12 ▶use String::License::Naming::SPDX;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 12 my $CAN_RE2 = false;
51  
52 12 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
53 12 try {
54 12 ▶ load_module('re::engine::RE2');
Subroutine BEGIN: called CC=1 SCAR=0.0
55 11 $CAN_RE2 = true;
56 }
57 catch ($e) {
58  
59 # module not compiled in / not installed
60 }
61 }
62  
63 12 ▶use namespace::clean -except => ['new'];
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 619 ▶my $make_tag = sub ( $type, $begin, $end, %fields ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 619 return [ $type, @fields{qw(name desc)}, $begin, $end ];
67 12 };
68  
69 # enable RE2 engine in later Regexp::Pattern imports if enabled here
70 12 ▶my @OPT_RE2 = $CAN_RE2 ? ( engine => 'RE2' ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$CAN_RE2 ? : 0 12 12
71  
72 12 field $log;
73  
74 =head1 CONSTRUCTOR
75  
76 =over
77  
78 =item new
79  
80 my $licensed = String::License->new( string => 'Licensed under GPLv2' );
81  
82 Accepts named arguments,
83 and constructs and returns a String::License object.
84  
85 The following options are recognized:
86  
87 =over
88  
89 =item string => STRING
90  
91 The scalar string to parse for licensing information.
92  
93 =cut
94  
95 12 field $string : param = undef;
96  
97 =item naming => OBJ
98  
99 A L<String::License::Naming> object,
100 used to define license naming conventions.
101  
102 By default uses L<String::License::Naming::SPDX>.
103  
104 Since instantiation of naming schemes is expensive,
105 there can be a significant speed boost
106 in passing a pre-initialized naming object
107 when processing multiple strings.
108  
109 =cut
110  
111 12 field $naming : param = undef;
112  
113 12 field $license = '';
114 12 field $expr = '';
115  
116 12 field $coverage;
117 12 field @loose_licensing;
118 12 field %fulltext;
119 12 field %grant;
120  
121 =back
122  
123 =back
124  
125 =cut
126  
127 12 my %dash_soup = (
128 "\x{E2}\x{80}\x{93}" => 'U+2013 EN-DASH (UTF-8 as Latin-1)',
129 "\x{E2}\x{80}\x{94}" => 'U+2014 EM-DASH (UTF-8 as Latin-1)',
130 "\x{E2}\x{20AC}\x{201C}" => 'U+2013 EN-DASH (UTF-8 as CP1252)',
131 "\x{E2}\x{20AC}\x{201D}" => 'U+2014 EM-DASH (UTF-8 as CP1252)',
132 "\x{0432}\x{0402}\x{2019}" => 'U+2013 EN-DASH (UTF-8 as CP1251)',
133 "\x{0432}\x{0402}\x{201D}" => 'U+2014 EM-DASH (UTF-8 as CP1251)',
134 );
135 12 my %dash_lookalike = (
136 "\x{2043}" => 'U+2043 HYPHEN BULLET',
137 "\x{02D7}" => 'U+02D7 MODIFIER LETTER MINUS SIGN',
138 "\x{FE32}" => 'U+FE32 PRESENTATION FORM FOR VERTICAL EN DASH',
139 "\x{FF0D}" => 'U+FF0D FULLWIDTH HYPHEN-MINUS',
140 );
141 24 ▶my $_build_alt = sub ($table) {
Subroutine __ANON__: called CC=1 SCAR=0.0
142 join '|',
143 map {
144 join '',
145 120 map { '\x{' . sprintf( '%X', ord $_ ) . '}' }
146 split //, $_
147 }
148 24 sort { length $b <=> length $a } keys %$table;
149 12 };
150 12 my $dash_soup_re = $_build_alt->( \%dash_soup );
151 12 my $dash_lookalike_re = $_build_alt->( \%dash_lookalike );
152 12 my $dash_re = qr/(?:\p{Dash}|$dash_soup_re|$dash_lookalike_re)/;
153 12 my $html_xml_tags_re = qr/<\/?(?:p|br|ref)(?:\s[^>]*)?>/i;
154  
155 338 ▶ADJUST {
Subroutine __ANON__: called CC=19 SCAR=30.3
156 338 $log = Log::Any->get_logger;
157  
158 338 ▶ if ( defined $naming ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $naming) { } 327 11 338
159 327 ▶ croak $log->fatal(
Branch: 1 branch
BranchTrueFalseTotal
unless defined builtin::blessed($naming) and $naming->isa("String::License::Naming") 0 327 327
Condition33%1/3
defined builtin::blessed($naming) and $naming->isa("String::License::Naming")
!ll&&!rl&&r
00327
MC/DC0%0/2
defined builtin::blessed($naming) and $naming->isa("String::License::Naming")
defined builtin::blessed($naming) $naming->isa("String::License::Naming")
Truth table33%1/3
A and B
A= defined builtin::blessed($naming)B= $naming->isa("String::License::Naming")
ABresult
0X0
100
111
160 'parameter "naming" must be a String::License::Naming object')
161 unless defined blessed($naming)
162 and $naming->isa('String::License::Naming');
163 }
164 else {
165 11 $naming = String::License::Naming::SPDX->new;
166 }
167  
168 338 my %changed;
169 338 my $pre = $string;
170  
171 # dash / unicode-soup / lookalike normalization
172 338 ▶ if ( $string =~ s/$dash_re/-/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/$dash_re/-/gu) 276 62 338
173 276 $changed{dash} = 1;
174 276 ▶ if ( $log->is_trace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log->is_trace) 4 272 276
175 4 my %seen;
176 my @notes;
177 4 for my $c ( $pre =~ /(\p{Dash})/g ) {
178 8 my $cp = ord $c;
179 8 ▶ next if $cp == 0x2D; # ASCII hyphen = the target
Branch: 1 branch
BranchTrueFalseTotal
if $cp == 45 5 3 8
180 3 ▶ next if $seen{$cp}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cp}++ 0 3 3
181 3 push @notes, sprintf( 'U+%04X', $cp );
182 }
183 4 ▶ $changed{dash} = \@notes if @notes;
Branch: 1 branch
BranchTrueFalseTotal
if @notes 3 1 4
184 4 ▶ while ( $pre =~ /$dash_soup_re/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre =~ /$dash_soup_re/gu) 0 4 4
185 0 ▶ push @{ $changed{soup} //= [] }, $dash_soup{$&};
Condition0%0/2
$changed{"soup"} //= []
l!l
00
MC/DC0%0/1
$changed{"soup"} //= []
$changed{"soup"}
Truth table0%0/2
A
A= $changed{"soup"}
Aresult
11
00
186 }
187 4 ▶ while ( $pre =~ /$dash_lookalike_re/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre =~ /$dash_lookalike_re/gu) 1 4 5
188 1 ▶ push @{ $changed{lookalike} //= [] }, $dash_lookalike{$&};
Condition50%1/2
$changed{"lookalike"} //= []
l!l
01
MC/DC0%0/1
$changed{"lookalike"} //= []
$changed{"lookalike"}
Truth table50%1/2
A
A= $changed{"lookalike"}
Aresult
11
00
189 }
190 }
191 }
192  
193 338 ▶ if ( ( my $c = $string =~ s/-\r?\n(?=\S)//g ) ) { $changed{unwrap} = $c }
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $string =~ s/-\r?\n(?=\S)//gu) 6 332 338
194 338 $string =~ s/\v+/ /g; # normalize line endings
195 0 ▶ if ( my $c = $string =~ s{$html_xml_tags_re}{}g ) { $changed{html} = $c }
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $string =~ s/$html_xml_tags_re//gu) 0 338 338
196 338 $string =~ tr/\t\r\n/ /; # tabs/newlines -> space
197  
198 338 $pre = $string;
199 338 $string =~ tr% A-Za-z.,:@;0-9()/+-%%cd;
200 338 ▶ if ( my $c = length($pre) - length($string) ) { $changed{noise} = $c }
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = length($pre) - length($string)) 161 177 338
201 338 $string =~ tr/ //s; # collapse runs of spaces
202  
203 338 ▶ if (%changed) {
Branch: 1 branch
BranchTrueFalseTotal
if (%changed) 303 35 338
204 303 ▶ if ( $log->is_trace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($log->is_trace) { } 6 297 303
205 6 $log->trace( 'normalized license string', \%changed );
206 }
207 else {
208 297 $log->debugf(
209 'normalized license string: %s',
210 join( ', ', sort keys %changed )
211 );
212 }
213 }
214  
215 338 $coverage = Array::IntSpan->new();
216 }
217  
218 =head1 METHODS
219  
220 =over
221  
222 =cut
223  
224 2754 ▶method note ( $name, $begin = undef, $end = undef )
Subroutine note: called CC=5 SCAR=16.1
Pod undocumented
225 2754 {
226 2754 my $obj;
227  
228 2754 ▶ if ( ref($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) 526 2228 2754
229 526 $obj = $name;
230 526 ( undef, $name, undef, $begin, $end ) = @$obj;
231 }
232  
233 $log->tracef(
234 2754 'noted %s: %d-%d "%s"',
235 $name, $begin, $end,
236 substr( $string, $begin, $end - $begin )
237 );
238  
239 2754 ▶ return $obj
Branch: 1 branch
BranchTrueFalseTotal
if $obj 526 2228 2754
240 if $obj;
241  
242 2228 return [ $begin, $end ];
243 }
244  
245 707 ▶method tag ($obj)
Subroutine tag: called CC=2 SCAR=6.9
Pod undocumented
246 {
247 707 my ( $type, $name, $desc, $begin, $end ) = @$obj;
248  
249 707 ▶ if ( $type eq 'licensing' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'licensing') { } 341 366 707
250 341 push @loose_licensing, [ $type, $name, $desc ];
251 }
252 else {
253 366 $coverage->set_range( $begin, $end, [ $type, $name, $desc ] );
254 366 $log->tracef(
255 'tagged %s: %s: %d-%d',
256 $type, $desc, $begin, $end
257 );
258 }
259  
260 707 return $obj;
261 }
262  
263 2246 ▶method contains_tag ( $begin, $end )
Subroutine contains_tag: called CC=1 SCAR=0.0
Pod undocumented
264 {
265 2246 return defined( $coverage->get_range( $begin, $end )->get_element(0) );
266 }
267  
268 337 ▶method get_tags ()
Subroutine get_tags: called CC=5 SCAR=16.3
Pod undocumented
269 {
270 337 my ( @thing, %set );
271  
272 337 @thing = $coverage->get_range_list;
273 337 $set{grant}{ $_->[1] } = $_ for @loose_licensing;
274 337 for my $i ( 0 .. $#thing ) {
275 361 my ( $begin, $end, $thing, $type, $key );
276  
277 361 ( $begin, $end, $thing ) = $coverage->get_element($i);
278 361 $type = $thing->[0];
279  
280 # TODO: drop fallback when all flaws have shortname
281 361 ▶ $key = $thing->[1] || $thing->[2];
Condition33%1/3
$thing->[1] || $thing->[2]
l!l&&r!l&&!r
36100
MC/DC0%0/2
$thing->[1] || $thing->[2]
$thing->[1] $thing->[2]
Truth table33%1/3
A || B
A= $thing->[1]B= $thing->[2]
ABresult
1X1
011
000
282  
283 361 ▶ next unless $type =~ /^[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^[a-z]/u 0 361 361
284  
285 361 $set{$type}{$key} = $thing;
286 }
287  
288 return (
289 337 [ values %{ $set{fulltexts} }, values %{ $set{grant} } ],
290 337 [ values %{ $set{exception} } ],
291 337 [ values %{ $set{flaw} } ],
292 );
293 }
294  
295 1 ▶method string ()
Subroutine string: called CC=1 SCAR=0.0
Pod documented
296 {
297 1 return $string;
298 }
299  
300 12 my $any = '[A-Za-z_][A-Za-z0-9_]*';
301 12 my $str = '[A-Za-z][A-Za-z0-9_]*';
302 12 my $re_prop_attrs = qr/
303 \A(?'prop'$str)\.alt(?:
304 \.org\.(?'org'$str)|
305 \.version\.(?'version'$str)|
306 \.since\.date_(?'since_date'\d{8})|
307 \.until\.date_(?'until_date'\d{8})|
308 \.synth\.$any|
309 (?'other'\.$any)
310 )*\z/x;
311  
312 13626 ▶method best_value ( $hashref, @props )
Subroutine best_value: called CC=12 SCAR=24.9
Pod undocumented
313 {
314 13626 my $value;
315  
316 PROPERTY:
317 13626 for my $prop (@props) {
318 13626 for my $org ( $naming->list_schemes ) {
319 19418 for ( keys %$hashref ) {
320 372237 /$re_prop_attrs/;
321 next
322 if not defined $+{prop}
323 or $+{prop} ne $prop
324 or not defined $+{org}
325 or $+{org} ne $org
326 or defined $+{version}
327 or defined $+{other}
328 372237 ▶ or defined $+{until_date};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org or defined $+{"version"} or defined $+{"other"} or defined $+{"until_date"} 368120 4117 372237
Condition88%16/18
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org or defined $+{"version"} or defined $+{"other"} or defined $+{"until_date"}
l!l&&r!l&&!r
3675815394117
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org or defined $+{"version"} or defined $+{"other"}
l!l&&r!l&&!r
36758104656
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org or defined $+{"version"}
l!l&&r!l&&!r
36758104656
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org
l!l&&r!l&&!r
344704228774656
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"}
l!l&&r!l&&!r
3328291187527533
not defined $+{"prop"} or $+{"prop"} ne $prop
l!l&&r!l&&!r
14389818893139408
MC/DC71%5/7
not defined $+{"prop"} or $+{"prop"} ne $prop or not defined $+{"org"} or $+{"org"} ne $org or defined $+{"version"} or defined $+{"other"} or defined $+{"until_date"}
not defined $+{"prop"} $+{"prop"} ne $prop not defined $+{"org"} $+{"org"} ne $org defined $+{"version"} defined $+{"other"} defined $+{"until_date"}
Truth table75%6/8
not(A) or B or not(C) or D or E or F or G
A= not defined $+{"prop"}B= $+{"prop"} ne $propC= not defined $+{"org"}D= $+{"org"} ne $orgE= defined $+{"version"}F= defined $+{"other"}G= defined $+{"until_date"}
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
329  
330 4117 $value = $hashref->{$_};
331 4117 last PROPERTY;
332 }
333 }
334 9509 ▶ $value ||= $hashref->{$prop};
Condition66%2/3
$value ||= $hashref->{$prop}
l!l&&r!l&&!r
08646863
MC/DC50%1/2
$value ||= $hashref->{$prop}
$value $hashref->{$prop}
Truth table66%2/3
A ||= B
A= $valueB= $hashref->{$prop}
ABresult
1X1
011
000
335 }
336  
337 13626 return $value;
338 }
339  
340 6813 ▶method name_and_desc ($id)
Subroutine name_and_desc: called CC=4 SCAR=14.0
Pod undocumented
341 {
342 6813 my ( $ref, %result );
343  
344 6813 $ref = $Regexp::Pattern::License::RE{$id};
345 6813 ▶ $result{name} = $self->best_value( $ref, 'name' ) || $id;
Condition66%2/3
$self->best_value($ref, 'name') || $id
l!l&&r!l&&!r
62175960
MC/DC0%0/2
$self->best_value($ref, 'name') || $id
$self->best_value($ref, 'name') $id
Truth table66%2/3
A || B
A= $self->best_value($ref, 'name')B= $id
ABresult
1X1
011
000
346 $result{desc}
347 6813 ▶ = $self->best_value( $ref, 'caption' ) || $ref->{name} || $id;
Condition83%5/6
$self->best_value($ref, 'caption') || $ref->{'name'} || $id
l!l&&r!l&&!r
66072060
$self->best_value($ref, "caption") or $ref->{"name"}
l!l&&r!l&&!r
654661206
MC/DC0%0/3
$self->best_value($ref, 'caption') || $ref->{'name'} || $id
$self->best_value($ref, "caption") $ref->{"name"} $id
Truth table75%3/4
A or B || C
A= $self->best_value($ref, "caption")B= $ref->{"name"}C= $id
ABCresult
1XX1
01X1
0011
0000
348  
349 6813 return \%result;
350 }
351  
352 12 my $license_contains_license_re
353 = qr/^license:contains:license:([a-z][a-z0-9_]*)/;
354 12 my $type_re
355 = qr/^type:([a-z][a-z0-9_]*)(?::([a-z][a-z0-9_]*))?(?::([a-z][a-z0-9_]*))?/;
356  
357 12 our %RE;
358 12 my (%L, @EXCEPTIONS, @LICENSES, @NAMES, @USAGE, @SINGLEVERSION, @VERSIONED,
359 @UNVERSIONED, @COMBO, @GROUP
360 );
361  
362 337 ▶method init_licensepatterns ()
Subroutine init_licensepatterns: called CC=20 SCAR=30.0
Pod undocumented
363 {
364 # reuse if already resolved
365 337 ▶ return %L if exists $L{re_trait};
Branch: 1 branch
BranchTrueFalseTotal
if exists $L{"re_trait"} 326 11 337
366  
367 11 Regexp::Pattern->import(
368 're',
369 'License::*' => (
370 @OPT_RE2,
371 subject => 'trait',
372 -prefix => 'EXCEPTION_',
373 -has_tag_matching => '^type:trait:exception(?:\z|:)',
374 -lacks_tag_matching => '^type:trait:exception:prefix(?:\z|:)',
375 ),
376 'License::*' => (
377 @OPT_RE2,
378 capture => 'named',
379 subject => 'trait',
380 -prefix => 'TRAIT_',
381 -has_tag_matching => '^type:trait(?:\z|:)',
382 -lacks_tag_matching => '^type:trait:exception(?!:prefix)(?:\z|:)',
383 ),
384 'License::version' => (
385 @OPT_RE2,
386 capture => 'named',
387 subject => 'trait',
388 anchorleft => 1,
389 -prefix => 'ANCHORLEFT_NAMED_',
390 ),
391 'License::version_later' => (
392 @OPT_RE2,
393 capture => 'named',
394 subject => 'trait',
395 anchorleft => 1,
396 -prefix => 'ANCHORLEFT_NAMED_',
397 ),
398 'License::any_of' => (
399 subject => 'trait',
400 -prefix => 'LOCAL_TRAIT_',
401 ),
402 'License::by_fsf' => (
403 subject => 'trait',
404 -prefix => 'LOCAL_TRAIT_',
405 ),
406 'License::fsf_unlimited' => (
407 subject => 'trait',
408 -prefix => 'LOCAL_TRAIT_',
409 ),
410 'License::fsf_unlimited_retention' => (
411 subject => 'trait',
412 -prefix => 'LOCAL_TRAIT_',
413 ),
414 'License::licensed_under' => (
415 subject => 'trait',
416 -prefix => 'LOCAL_TRAIT_',
417 ),
418 'License::or_at_option' => (
419 subject => 'trait',
420 -prefix => 'LOCAL_TRAIT_',
421 ),
422 'License::version' => (
423 capture => 'named',
424 subject => 'trait',
425 -prefix => 'LOCAL_TRAIT_KEEP_',
426 ),
427 'License::apache' => (
428 subject => 'name',
429 -prefix => 'LOCAL_NAME_',
430 ),
431 'License::gpl' => (
432 subject => 'name',
433 -prefix => 'LOCAL_NAME_',
434 ),
435 'License::lgpl' => (
436 subject => 'name',
437 -prefix => 'LOCAL_NAME_',
438 ),
439 'License::mit' => (
440 subject => 'name',
441 -prefix => 'LOCAL_NAME_',
442 ),
443 'License::*' => (
444 @OPT_RE2,
445 subject => 'name',
446 -prefix => 'NAME_',
447 anchorleft => 1,
448 -lacks_tag_matching => '^type:trait(?:\z|:)',
449 ),
450 'License::*' => (
451 @OPT_RE2,
452 subject => 'grant',
453 -prefix => 'GRANT_',
454 -lacks_tag_matching => '^type:trait(?:\z|:)',
455 ),
456 'License::*' => (
457 @OPT_RE2,
458 subject => 'license',
459 -prefix => 'LICENSE_',
460 -lacks_tag_matching => '^type:trait(?:\z|:)',
461 ),
462 );
463  
464 11 my @license_containers;
465 11 for my $key ( grep {/^[a-z]/} keys %Regexp::Pattern::License::RE ) {
466 6204 my $val = $Regexp::Pattern::License::RE{$key};
467  
468 ( $L{name}{$key}, $L{caption}{$key} )
469 6204 = @{ $self->name_and_desc($key) }{ 'name', 'desc' };
470 6204 for ( @{ $val->{tags} } ) {
471 11649 ▶ if (/$license_contains_license_re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$license_contains_license_re/u) 440 11209 11649
472 440 $L{contained_licenses}{$key}{$1} = undef;
473 440 push @license_containers, $key;
474 }
475 11649 ▶ /$type_re/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/$type_re/u or next 6160 5489 11649
476 6160 $L{type}{$1}{$key} = 1;
477 6160 ▶ if ( $2 and $1 eq 'singleversion' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 and $1 eq "singleversion") 2343 3817 6160
Condition100%3/3
$2 and $1 eq "singleversion"
!ll&&!rl&&r
173820792343
MC/DC100%2/2
$2 and $1 eq "singleversion"
$2 $1 eq "singleversion"
Truth table100%3/3
A and B
A= $2B= $1 eq "singleversion"
ABresult
0X0
100
111
478 2343 $L{series}{$key} = $2;
479 }
480 6160 ▶ if ( $2 and $1 eq 'usage' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 and $1 eq "usage") 297 5863 6160
Condition100%3/3
$2 and $1 eq "usage"
!ll&&!rl&&r
17384125297
MC/DC100%2/2
$2 and $1 eq "usage"
$2 $1 eq "usage"
Truth table100%3/3
A and B
A= $2B= $1 eq "usage"
ABresult
0X0
100
111
481 297 $L{usage}{$key} = $2;
482 }
483  
484 # TODO: simplify, and require Regexp::Pattern::License v3.9.0
485 6160 ▶ if ( $3 and $1 eq 'trait' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($3 and $1 eq "trait") 253 5907 6160
Condition100%3/3
$3 and $1 eq "trait"
!ll&&!rl&&r
5610297253
MC/DC100%2/2
$3 and $1 eq "trait"
$3 $1 eq "trait"
Truth table100%3/3
A and B
A= $3B= $1 eq "trait"
ABresult
0X0
100
111
486 253 ▶ if ( substr( $key, 0, 14 ) eq 'except_prefix_' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($key, 0, 14) eq 'except_prefix_') { } 55 198 253
487 55 $L{TRAITS_exception_prefix}{$key} = undef;
488 }
489 else {
490 198 $L{"TRAITS_$2_$3"}{$key} = undef;
491 }
492 }
493 }
494 }
495 11 for my $container (@license_containers) {
496 440 for my $contained ( keys %{ $L{contained_licenses}{$container} } ) {
497 627 ▶ if ( exists $L{contained_licenses}->{$contained} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $L{"contained_licenses"}{$contained}) 292 335 627
498 $L{contained_licenses}{$container}{$_} = undef
499 292 for keys %{ $L{contained_licenses}{$contained} };
500 }
501 }
502 }
503  
504 # list by amount of contained licenses (fewest first),
505 # then key length (longest first), then alphabetically
506 @LICENSES = sort {
507 41761 keys %{ $L{contained_licenses}{$b} } <=>
508 41761 ▶ keys %{ $L{contained_licenses}{$a} }
Condition83%5/6
keys %{$L{'contained_licenses'}{$b};} <=> keys %{$L{'contained_licenses'}{$a};} || length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
21400203610
keys %{$L{"contained_licenses"}{$b};} <=> keys %{$L{"contained_licenses"}{$a};} or length $b <=> length $a
l!l&&r!l&&!r
24311896920361
MC/DC0%0/3
keys %{$L{'contained_licenses'}{$b};} <=> keys %{$L{'contained_licenses'}{$a};} || length $b <=> length $a || $a cmp $b
keys %{$L{"contained_licenses"}{$b};} <=> keys %{$L{"contained_licenses"}{$a};} length $b <=> length $a $a cmp $b
Truth table75%3/4
A or B || C
A= keys %{$L{"contained_licenses"}{$b};} <=> keys %{$L{"contained_licenses"}{$a};}B= length $b <=> length $aC= $a cmp $b
ABCresult
1XX1
01X1
0011
0000
509 || length($b) <=> length($a)
510 || $a cmp $b
511 }
512 11 map {/^LICENSE_(.*)/} keys %RE;
513  
514 # list by key length (longest first), then alphabetically
515 41798 ▶ @NAMES = sort { length($b) <=> length($a) || $a cmp $b }
Condition66%2/3
length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
20041217570
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a $a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
ABresult
1X1
011
000
516 11 map {/^NAME_(.*)/} keys %RE;
517  
518 # list alphabetically
519 11 @EXCEPTIONS = sort map {/^EXCEPTION_(.*)/} keys %RE;
520  
521 11 @USAGE = grep { exists $L{type}{usage}{$_} } @LICENSES;
522 @SINGLEVERSION
523 11 = grep { exists $L{type}{singleversion}{$_} } @LICENSES;
524 11 @VERSIONED = grep { exists $L{type}{versioned}{$_} } @LICENSES;
525 @UNVERSIONED
526 11 = grep { exists $L{type}{unversioned}{$_} } @LICENSES;
527 11 @COMBO = grep { exists $L{type}{combo}{$_} } @LICENSES;
528 11 @GROUP = grep { exists $L{type}{group}{$_} } @LICENSES;
529  
530 # FIXME: drop when perl doesn't mysteriously freak out over it
531 11 $L{re_trait}{any_of} = '';
532  
533 #<<< do not let perltidy touch this (keep long regex on one line)
534 11 $L{multi_1} = qr/$RE{LOCAL_TRAIT_licensed_under}$RE{LOCAL_TRAIT_any_of}(?:[^.]|\.\S)*$RE{LOCAL_NAME_lgpl}$RE{LOCAL_TRAIT_KEEP_version}?/i;
535 11 $L{multi_2} = qr/$RE{LOCAL_TRAIT_licensed_under}$RE{LOCAL_TRAIT_any_of}(?:[^.]|\.\S)*$RE{LOCAL_NAME_gpl}$RE{LOCAL_TRAIT_KEEP_version}?/i;
536 11 $L{lgpl_5} = qr/$RE{LOCAL_TRAIT_licensed_under}$RE{LOCAL_NAME_lgpl}(?:$RE{LOCAL_TRAIT_by_fsf})?$RE{LOCAL_TRAIT_KEEP_version}(?:,? ?$RE{LOCAL_TRAIT_or_at_option} $RE{LOCAL_TRAIT_KEEP_version})?/i;
537 11 $L{gpl_7} = qr/either $RE{LOCAL_NAME_gpl}$RE{LOCAL_TRAIT_KEEP_version}?(?: \((?:the )?"?GPL"?\))?, or $RE{LOCAL_NAME_lgpl}$RE{LOCAL_TRAIT_KEEP_version}?/i;
538 11 $L{apache_1} = qr/$RE{LOCAL_NAME_apache}$RE{LOCAL_TRAIT_KEEP_version}?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]+\))*,? or $RE{LOCAL_NAME_gpl}$RE{LOCAL_TRAIT_KEEP_version}?/i;
539 11 $L{apache_2} = qr/$RE{LOCAL_NAME_apache}$RE{LOCAL_TRAIT_KEEP_version}?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]\))*,? or(?: the)? bsd(?P<version_bsd>[ -](\d)-clause)?\b/i;
540 11 $L{apache_4} = qr/$RE{LOCAL_NAME_apache}$RE{LOCAL_TRAIT_KEEP_version}?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]\))*,? or $RE{LOCAL_NAME_mit}\b/i;
541 11 $L{fsful} = qr/This (\w+)(?: (?:file|script))? is free software; $RE{LOCAL_TRAIT_fsf_unlimited}/i;
542 11 $L{fsfullr} = qr/This (\w+)(?: (?:file|script))? is free software; $RE{LOCAL_TRAIT_fsf_unlimited_retention}/i;
543 #>>>
544 }
545  
546 # license objects where atomic scan must always be applied
547 12 my %L_grant_stepwise_incomplete = (
548  
549 # usage
550  
551 # singleversion
552 apache_2 => 1,
553  
554 # versioned
555 gpl => 1,
556 lgpl => 1,
557  
558 # other
559 mit_new => 1, # misdetects ambiguous "MIT X11" grant
560 public_domain => 1,
561 );
562  
563 # license objects where stepwise scan cannot be skipped
564 12 my %L_grant_atomic_incomplete = (
565 afl_1_1 => 1,
566 afl_1_2 => 1,
567 afl_2 => 1,
568 afl_2_1 => 1,
569 afl_3 => 1,
570 apache_1_1 => 1,
571 artistic_1 => 1,
572 artistic_2 => 1,
573 bsl_1 => 1,
574 cc_by_2_5 => 1,
575 cc_by_sa => 1,
576 cpl_1 => 1,
577 mpl => 1,
578 mpl_1 => 1,
579 mpl_1_1 => 1,
580 mpl_2 => 1,
581 openssl => 1,
582 postgresql => 1,
583 zpl_2_1 => 1,
584 );
585  
586 # scan for grants first stepwise and if not found then also atomic
587 # flip either of these flags to test stepwise/atomic pattern coverage
588 12 my $skip_stepwise = 0;
589 12 my $force_atomic = 0;
590  
591 12 my $id2patterns_re = qr/(.*)(?:_(\d+(?:\.\d+)*)(_or_later)?)?/;
592  
593 337 ▶method resolve ()
Subroutine resolve: called CC=129 SCAR=54.2
Pod undocumented
594 {
595 337 $self->init_licensepatterns;
596  
597 337 my @spdx_gplver;
598  
599 337 my @agpl = qw(agpl agpl_1 agpl_2 agpl_3);
600 337 my @gpl = qw(gpl gpl_1 gpl_2 gpl_3);
601 337 my @lgpl = qw(lgpl lgpl_2 lgpl_2_1 lgpl_3);
602  
603 337 my %match;
604  
605 3 ▶ my $patterns2id = sub ( $stem, $version = undef ) {
Subroutine __ANON__: called CC=3 SCAR=11.1
606 3 ▶ return $stem
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 3 3
607 unless ($version);
608 3 $version =~ tr/./_/;
609 3 $version =~ s/_0$//g;
610 3 return "${stem}_$version";
611 337 };
612 225 ▶ my $id2patterns = sub ($id) {
Subroutine __ANON__: called CC=1 SCAR=0.0
613 225 return $id =~ /$id2patterns_re/;
614 337 };
615 341 ▶ my $gen_license = sub (
Subroutine __ANON__: called CC=21 SCAR=31.2
616 341 $id, $v = undef, $later = undef, $id2 = undef, $v2 = undef,
617 $later2 = undef
618 )
619 341 {
620 341 my ( @spdx, $name, $desc, $name2, $desc2, $legacy, $expr );
621  
622 341 ▶ $name = $L{name}{$id} || $id;
Condition33%1/3
$L{'name'}{$id} || $id
l!l&&r!l&&!r
34100
MC/DC0%0/2
$L{'name'}{$id} || $id
$L{'name'}{$id} $id
Truth table33%1/3
A || B
A= $L{'name'}{$id}B= $id
ABresult
1X1
011
000
623 341 ▶ $desc = $L{caption}{$id} || $id;
Condition33%1/3
$L{'caption'}{$id} || $id
l!l&&r!l&&!r
34100
MC/DC0%0/2
$L{'caption'}{$id} || $id
$L{'caption'}{$id} $id
Truth table33%1/3
A || B
A= $L{'caption'}{$id}B= $id
ABresult
1X1
011
000
624 341 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) { } 5 336 341
625 5 ▶ push @spdx, $later ? "$name-$v+" : "$name-$v";
Branch: 1 branch
BranchTrueFalseTotal
$later ? : 2 3 5
626 5 ▶ $v .= ' or later' if ($later);
Branch: 1 branch
BranchTrueFalseTotal
if $later 2 3 5
627 }
628 else {
629 336 push @spdx, $name;
630 }
631 341 ▶ if ($id2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id2) 5 336 341
632 5 ▶ $name2 = $L{name}{$id2} || $id2;
Condition33%1/3
$L{'name'}{$id2} || $id2
l!l&&r!l&&!r
500
MC/DC0%0/2
$L{'name'}{$id2} || $id2
$L{'name'}{$id2} $id2
Truth table33%1/3
A || B
A= $L{'name'}{$id2}B= $id2
ABresult
1X1
011
000
633 5 ▶ $desc2 = $L{caption}{$id2} || $id2;
Condition33%1/3
$L{'caption'}{$id2} || $id2
l!l&&r!l&&!r
500
MC/DC0%0/2
$L{'caption'}{$id2} || $id2
$L{'caption'}{$id2} $id2
Truth table33%1/3
A || B
A= $L{'caption'}{$id2}B= $id2
ABresult
1X1
011
000
634 5 ▶ if ($v2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2) { } 4 1 5
635 4 ▶ push @spdx, $later2 ? "$name2-$v2+" : "$name2-$v2";
Branch: 1 branch
BranchTrueFalseTotal
$later2 ? : 2 2 4
636 4 ▶ $v2 .= ' or later' if ($later2);
Branch: 1 branch
BranchTrueFalseTotal
if $later2 2 2 4
637 }
638 else {
639 1 push @spdx, $name2;
640 }
641 }
642 341 ▶ $legacy = join(
Branch: 3 branches
BranchTrueFalseTotal
$v ? : 5 336 341
$desc2 ? : 5 336 341
$v2 ? : 4 337 341
643 ' ',
644 $desc,
645 $v ? "(v$v)" : (),
646 $desc2 ? "or $desc2" : (),
647 $v2 ? "(v$v2)" : (),
648 );
649 341 $expr = join( ' or ', sort @spdx );
650 341 ▶ $self->tag( [ licensing => $expr, $L{caption}{$legacy} || $legacy ] );
Condition66%2/3
$L{'caption'}{$legacy} || $legacy
l!l&&r!l&&!r
83330
MC/DC0%0/2
$L{'caption'}{$legacy} || $legacy
$L{'caption'}{$legacy} $legacy
Truth table66%2/3
A || B
A= $L{'caption'}{$legacy}B= $legacy
ABresult
1X1
011
000
651 337 };
652  
653 # fulltext
654 337 $log->trace('scan for license fulltext');
655 337 my %pos_license;
656 337 for my $id (@LICENSES) {
657 166141 ▶ next unless ( $RE{"LICENSE_$id"} );
Branch: 1 branch
BranchTrueFalseTotal
unless $String::License::RE{"LICENSE_$id"} 43810 122331 166141
658 122331 ▶ while ( $string =~ /$RE{"LICENSE_$id"}/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"LICENSE_$id"}/gu) 321 122331 122652
659 $pos_license{ $-[0] }{obj}{$id} = $self->note(
660 $make_tag->(
661 321 'fulltext', $-[0], $+[0], %{ $self->name_and_desc($id) }
662 )
663 );
664 321 $pos_license{ $-[0] }{end}{$id} = $+[0];
665 }
666 }
667 337 for my $trait ( keys %{ $L{TRAITS_exception_prefix} } ) {
668 1685 ▶ next unless ( $string =~ /$RE{"TRAIT_$trait"}/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /$String::License::RE{"TRAIT_$trait"}/u 1643 42 1685
669 42 ▶ while ( $string =~ /$RE{"TRAIT_$trait"}/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"TRAIT_$trait"}/gu) 46 42 88
670 46 ▶ next if $self->contains_tag( $-[0], $+[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $self->contains_tag($-[0], $+[0]) 0 46 46
671 46 $self->note( $trait, $-[0], $+[0] );
672 }
673 }
674 337 for my $pos ( sort { $a <=> $b } keys %pos_license ) {
675  
676 # pick longest or most specific among matched license fulltexts
677 291 my $longest = max values %{ $pos_license{$pos}{end} };
678 my @licenses = grep {
679 291 exists $pos_license{$pos}{end}{$_}
680 143463 ▶ and $pos_license{$pos}{end}{$_} eq $longest
Condition100%3/3
exists $pos_license{$pos}{'end'}{$_} && $pos_license{$pos}{'end'}{$_} eq $longest
!ll&&!rl&&r
14314217304
MC/DC100%2/2
exists $pos_license{$pos}{'end'}{$_} && $pos_license{$pos}{'end'}{$_} eq $longest
exists $pos_license{$pos}{'end'}{$_} $pos_license{$pos}{'end'}{$_} eq $longest
Truth table100%3/3
A && B
A= exists $pos_license{$pos}{'end'}{$_}B= $pos_license{$pos}{'end'}{$_} eq $longest
ABresult
0X0
100
111
681 } @LICENSES;
682 291 my $id = $licenses[0];
683 next
684 if not $id
685 291 ▶ or $self->contains_tag( $pos, $pos_license{$pos}{end}{$id} );
Branch: 1 branch
BranchTrueFalseTotal
if not $id or $self->contains_tag($pos, $pos_license{$pos}{"end"}{$id}) 18 273 291
Condition66%2/3
not $id or $self->contains_tag($pos, $pos_license{$pos}{"end"}{$id})
l!l&&r!l&&!r
018273
MC/DC50%1/2
not $id or $self->contains_tag($pos, $pos_license{$pos}{"end"}{$id})
not $id $self->contains_tag($pos, $pos_license{$pos}{"end"}{$id})
Truth table66%2/3
not(A) or B
A= not $idB= $self->contains_tag($pos, $pos_license{$pos}{"end"}{$id})
ABresult
1X1
011
000
686 273 $fulltext{$id} = $self->tag( $pos_license{$pos}{obj}{$id} );
687 }
688  
689 # grant, stepwise
690 337 my %is_versioned = map { $_ => 1 } @VERSIONED;
691 337 my %is_singleversion = map { $_ => 1 } @SINGLEVERSION;
692 my @grant_types_default
693 337 = ( @COMBO, @UNVERSIONED, @VERSIONED, @SINGLEVERSION, @USAGE );
694 337 my @prefixes;
695 337 $log->trace('scan stepwise for license grant');
696 337 for my $trait ( keys %{ $L{TRAITS_grant_prefix} } ) {
697 1348 ▶ while ( $string =~ /$RE{"TRAIT_$trait"}/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"TRAIT_$trait"}/gu) 1698 1348 3046
698 1698 ▶ next if $self->contains_tag( $-[0], $+[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $self->contains_tag($-[0], $+[0]) 97 1601 1698
699 1601 push @prefixes, $self->note( $trait, $-[0], $+[0] );
700 }
701 }
702 LICENSED_UNDER:
703 337 for my $licensed_under ( sort { $a->[1] <=> $b->[1] } @prefixes ) {
704 1601 my $pos = $licensed_under->[1];
705  
706 # possible grant names
707 1601 my @grant_types = @grant_types_default;
708  
709 # optional grant version
710 1601 my ( $version, $suffix );
711  
712 # scan for prepended version
713 1601 substr( $string, $pos ) =~ $RE{ANCHORLEFT_NAMED_version};
714 1601 ▶ if ( defined $+{version_number} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_number"}) 9 1592 1601
715 9 $self->note( 'version', $pos + $-[0], $pos + $+[0] );
716 9 $self->note( 'version_number', $pos + $-[1], $pos + $+[1] );
717 9 $version = $+{version_number};
718 9 ▶ if ( defined $+{version_later} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_later"}) 0 9 9
719 0 $self->note( 'version_later', $pos + $-[2], $pos + $+[2] );
720 0 $suffix = '_or_later';
721 }
722 9 ▶ if ( defined $+{version_only} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_only"}) 0 9 9
723 0 $self->note( 'version_only', $pos + $-[4], $pos + $+[4] );
724 0 $suffix = '_only';
725 }
726 9 ▶ if ( defined $+{version_of} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{'version_of'}) { } 3 6 9
727 3 $self->note( 'version_of', $pos + $-[5], $pos + $+[5] );
728 3 $pos += $+[0];
729 3 @grant_types = @VERSIONED;
730 }
731 else {
732 6 $version = '';
733 }
734 }
735  
736 # scan for name
737 1601 for my $id (@NAMES) {
738 789293 ▶ if ( substr( $string, $pos ) =~ $RE{"NAME_$id"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($string, $pos) =~ /$String::License::RE{"NAME_$id"}/u) 544 788749 789293
739 544 $match{$id}{name}{ $pos + $-[0] }
740 = $self->note( "name($id)", $pos + $-[0], $pos + $+[0] );
741 }
742 }
743  
744 # pick longest matched license name
745 # TODO: include all of most specific type when more are longest
746 my @names = sort {
747 284 $match{$a}{name}{$pos}->[1] <=> $match{$b}{name}{$pos}->[1]
748 }
749 grep {
750 1601 $match{$_}
751 and $match{$_}{name}
752 770539 ▶ and $match{$_}{name}{$pos}
Condition83%5/6
$match{$_} && $match{$_}{'name'} && $match{$_}{'name'}{$pos}
!ll&&!rl&&r
769346767426
$match{$_} and $match{$_}{"name"}
!ll&&!rl&&r
76934601193
MC/DC66%2/3
$match{$_} && $match{$_}{'name'} && $match{$_}{'name'}{$pos}
$match{$_} $match{$_}{"name"} $match{$_}{'name'}{$pos}
Truth table75%3/4
A and B && C
A= $match{$_}B= $match{$_}{"name"}C= $match{$_}{'name'}{$pos}
ABCresult
0XX0
10X0
1100
1111
753 } @grant_types;
754 1601 my $name = $names[-1];
755 1601 ▶ if ( $name
Branch: 1 branch
BranchTrueFalseTotal
if ($name and $match{$name}{"name"}{$pos} and not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1]) and !$skip_stepwise || $L_grant_atomic_incomplete{$name}) 205 1396 1601
Condition66%8/12
$name and $match{$name}{"name"}{$pos} and not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1]) and !$skip_stepwise || $L_grant_atomic_incomplete{$name}
!ll&&!rl&&r
13960205
$name and $match{$name}{"name"}{$pos} and not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1])
!ll&&!rl&&r
13951205
$name and $match{$name}{"name"}{$pos}
!ll&&!rl&&r
13950206
not $skip_stepwise or $L_grant_atomic_incomplete{$name}
l!l&&r!l&&!r
20500
MC/DC40%2/5
$name and $match{$name}{"name"}{$pos} and not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1]) and !$skip_stepwise || $L_grant_atomic_incomplete{$name}
$name $match{$name}{"name"}{$pos} not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1]) not $skip_stepwise $L_grant_atomic_incomplete{$name}
Truth table50%3/6
A and B and not(C) and not(D) or E
A= $nameB= $match{$name}{"name"}{$pos}C= not $self->contains_tag($pos, $match{$name}{"name"}{$pos}[1])D= not $skip_stepwiseE= $L_grant_atomic_incomplete{$name}
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
756 and $match{$name}{name}{$pos}
757 and !$self->contains_tag( $pos, $match{$name}{name}{$pos}->[1] )
758 and ( !$skip_stepwise or $L_grant_atomic_incomplete{$name} ) )
759 {
760 205 my $pos_end = $pos = $match{$name}{name}{$pos}->[1];
761  
762 # may include version
763 205 ▶ if ( !$version and $is_versioned{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $version and $is_versioned{$name}) { } 35 170 205
elsif (not $version and $is_singleversion{$name}) { } 88 85 173
Condition100%3/3
not $version and $is_versioned{$name}
!ll&&!rl&&r
316735
MC/DC100%2/2
not $version and $is_versioned{$name}
not $version $is_versioned{$name}
Truth table100%3/3
not(A) and B
A= not $versionB= $is_versioned{$name}
ABresult
0X0
100
111
764 35 substr( $string, $pos ) =~ $RE{ANCHORLEFT_NAMED_version};
765 35 ▶ if ( defined $+{version_number} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_number"}) 4 31 35
766 4 $self->note(
767 'version',
768 $pos + $-[0], $pos + $+[0]
769 );
770 4 $self->note(
771 'version_number',
772 $pos + $-[1], $pos + $+[1]
773 );
774 4 $version = $+{version_number};
775 4 ▶ if ( $+{version_later} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($+{"version_later"}) 0 4 4
776 0 $self->note(
777 'version_later',
778 $pos + $-[2], $pos + $+[2]
779 );
780 0 $suffix = '_or_later';
781 }
782 4 ▶ if ( defined $+{version_only} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_only"}) 0 4 4
783 0 $self->note(
784 'version_only',
785 $pos + $-[4], $pos + $+[4]
786 );
787 0 $suffix = '_only';
788 }
789 4 $pos_end = $pos + $+[0];
790 }
791 }
792 ▶ elsif ( !$version and $is_singleversion{$name} ) {
Condition100%3/3
not $version and $is_singleversion{$name}
!ll&&!rl&&r
37988
MC/DC100%2/2
not $version and $is_singleversion{$name}
not $version $is_singleversion{$name}
Truth table100%3/3
not(A) and B
A= not $versionB= $is_singleversion{$name}
ABresult
0X0
100
111
793 substr( $string, $pos )
794 88 =~ $RE{ANCHORLEFT_NAMED_version_later};
795 88 ▶ if ( defined $+{version_later} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{"version_later"}) 3 85 88
796 3 $self->note(
797 'version_later',
798 $pos + $-[1], $pos + $+[1]
799 );
800 3 $suffix = '_or_later';
801 3 $pos_end = $pos + $+[0];
802 }
803 }
804 205 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 7 198 205
805 7 $version =~ tr/./_/;
806 7 $version =~ s/(?:_0)+$//;
807 7 $name .= "_$version";
808 }
809 205 ▶ if ($suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix) 3 202 205
810 3 my $latername = "$name$suffix";
811 $grant{$latername} = $self->note(
812 $make_tag->(
813 'grant', $licensed_under->[0], $pos_end,
814 3 %{ $self->name_and_desc($latername) }
815 )
816 );
817 3 ▶ next LICENSED_UNDER if any { $grant{$_} } @NAMES;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $grant{$_}; } , @NAMES) 3 0 3
818 }
819 $grant{$name} = $self->note(
820 $make_tag->(
821 'grant', $licensed_under->[0], $pos_end,
822 202 %{ $self->name_and_desc($name) }
823 )
824 );
825 }
826 }
827  
828 # GNU oddities
829 337 ▶ if ( any { $match{$_}{name} } @agpl, @gpl, @lgpl ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $match{$_}{"name"}; } , @agpl, @gpl, @lgpl)) 97 240 337
830 97 $log->trace('scan for GNU oddities');
831  
832 # address in AGPL/GPL/LGPL
833 97 ▶ while ( $string =~ /$RE{TRAIT_addr_fsf}/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"TRAIT_addr_fsf"}/gu) 39 97 136
834 39 for my $id (
835 qw(addr_fsf_franklin_steet addr_fsf_mass addr_fsf_temple))
836 {
837 117 ▶ if ( defined $+{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{$id}) 14 103 117
838 $self->tag(
839 $make_tag->(
840 'flaw', $-[0], $+[0],
841 14 %{ $self->name_and_desc($id) }
842 )
843 );
844 }
845 }
846 }
847 }
848  
849 # exceptions
850 # TODO: conditionally limit to AGPL/GPL/LGPL
851 337 for my $id (@EXCEPTIONS) {
852 12132 ▶ if ( $string =~ $RE{"EXCEPTION_$id"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"EXCEPTION_$id"}/u) 55 12077 12132
853 $self->tag(
854 $make_tag->(
855 55 'exception', $-[0], $+[0], %{ $self->name_and_desc($id) }
856 )
857 );
858 }
859 }
860  
861 # oddities
862 337 $log->trace('scan for oddities');
863  
864 # generated file
865 337 ▶ if ( $string =~ $RE{TRAIT_generated} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$String::License::RE{"TRAIT_generated"}/u) 14 323 337
866 $self->tag(
867 $make_tag->(
868 14 'flaw', $-[0], $+[0], %{ $self->name_and_desc('generated') }
869 )
870 );
871 }
872  
873 # multi-licensing
874 337 my @multilicenses;
875  
876 # LGPL, dual-licensed
877 # FIXME: add test covering this pattern
878 337 ▶ if ( any { $match{$_}{name} } @lgpl ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $match{$_}{"name"}; } , @lgpl)) 30 307 337
879 30 $log->trace('scan for LGPL dual-license grant');
880 30 ▶ if ( $string =~ $L{multi_1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"multi_1"}/u) 0 30 30
881 0 $self->note( 'grant(multi#1)', $-[0], $+[0] );
882 0 push @multilicenses, 'lgpl', $1, $2;
883 }
884 }
885  
886 # GPL, dual-licensed
887 # FIXME: add test covering this pattern
888 337 ▶ if ( any { $match{$_}{name} } @gpl ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $match{$_}{"name"}; } , @gpl)) 69 268 337
889 69 $log->trace('scan for GPL dual-license grant');
890 69 ▶ if ( $string =~ $L{multi_2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"multi_2"}/u) 0 69 69
891 0 $self->note( 'grant(multi#2)', $-[0], $+[0] );
892 0 push @multilicenses, 'gpl', $1, $2;
893 }
894 }
895  
896 337 ▶ $gen_license->(@multilicenses) if (@multilicenses);
Branch: 1 branch
BranchTrueFalseTotal
if @multilicenses 0 337 337
897  
898 # LGPL
899 337 for ( grep { $match{$_}{name} } @lgpl ) {
900 53 $log->trace('scan for LGPL fulltext/grant');
901  
902 # LGPL, dual versions last
903 53 ▶ if ( $string =~ $L{lgpl_5} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"lgpl_5"}/u) 48 5 53
904  
905 # TODO: simplify, and require Regexp::Pattern::License v3.11.0
906 48 ▶ my $v2 = ( $+{version_number_2} // $-{version_number}[1] );
Condition66%2/3
$+{"version_number_2"} // $-{"version_number"}[1]
l!l&&r!l&&!r
10038
MC/DC50%1/2
$+{"version_number_2"} // $-{"version_number"}[1]
$+{"version_number_2"} $-{"version_number"}[1]
Truth table66%2/3
A // B
A= $+{"version_number_2"}B= $-{"version_number"}[1]
ABresult
1X1
011
000
907 48 ▶ next unless defined $v2 && length $v2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v2 and length $v2 38 10 48
Condition66%2/3
defined $v2 and length $v2
!ll&&!rl&&r
38010
MC/DC50%1/2
defined $v2 and length $v2
defined $v2 length $v2
Truth table66%2/3
A and B
A= defined $v2B= length $v2
ABresult
0X0
100
111
908  
909 10 $self->tag(
910 $make_tag->(
911 'grant', $-[0], $+[0],
912 name => "LGPL-$+{version_number} or LGPL-$v2",
913 desc => "LGPL (v$+{version_number} or v$v2)",
914 )
915 );
916 10 $match{ 'lgpl_' . $+{version_number} =~ tr/./_/r }{custom} = 1;
917 10 $match{ 'lgpl_' . $v2 =~ tr/./_/r }{custom} = 1;
918 10 $match{lgpl}{custom} = 1;
919 }
920 }
921  
922 # GPL or LGPL
923 337 ▶ if ( any { $match{$_}{name} } @gpl ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $match{$_}{"name"}; } , @gpl)) 69 268 337
924 69 $log->trace('scan for GPL or LGPL dual-license grant');
925 69 ▶ if ( $string =~ $L{gpl_7} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"gpl_7"}/u) 2 67 69
926 2 $self->note( "grant(gpl#7)", $-[0], $+[0] );
927 $gen_license->(
928 'gpl', $-{version_number}[0], $-{version_later}[0],
929 2 'lgpl', $-{version_number}[1], $-{version_later}[1],
930 );
931 2 $match{gpl}{custom} = 1;
932 2 $match{lgpl}{custom} = 1;
933 }
934 }
935  
936 # Apache dual-licensed with GPL/BSD/MIT
937 337 ▶ if ( $match{apache}{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match{"apache"}{"name"}) 11 326 337
938 11 $log->trace('scan for Apache license grant');
939 11 for ($string) {
940 11 ▶ if ( $string =~ $L{apache_1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"apache_1"}/u) 2 9 11
941 2 $self->note( 'grant(apache#1)', $-[0], $+[0] );
942 $gen_license->(
943 'apache', $-{version_number}[0], $-{version_later}[0],
944 2 'gpl', $-{version_number}[1], $-{version_later}[1],
945 );
946 $match{ $patterns2id->( 'apache', $-{version_number}[0] ) }
947 2 {custom} = 1;
948 2 next;
949 }
950 9 ▶ if ( $string =~ $L{apache_2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"apache_2"}/u) 0 9 9
951 0 $self->note( 'grant(apache#2)', $-[0], $+[0] );
952 $gen_license->(
953 'apache', $+{version_number}, $+{version_later},
954 0 ▶ $+{version_bsd} ? "bsd_$+{version_bsd}_clause" : ''
Branch: 1 branch
BranchTrueFalseTotal
$+{'version_bsd'} ? : 0 0 0
955 );
956 $match{ $patterns2id->( 'apache', $+{version_number} ) }
957 0 {custom} = 1;
958 0 next;
959 }
960 9 ▶ if ( $string =~ $L{apache_4} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$L{"apache_4"}/u) 1 8 9
961 1 $self->note( 'grant(apache#4)', $-[0], $+[0] );
962 $gen_license->(
963 'apache', $+{version_number}, $+{version_later},
964 1 'mit',
965 );
966 $match{ $patterns2id->( 'apache', $+{version_number} ) }
967 1 {custom} = 1;
968 1 next;
969 }
970 }
971 }
972  
973 # FSFUL
974 # FIXME: add test covering this pattern
975 337 $log->trace('scan for FSFUL fulltext');
976 337 ▶ if ( !$fulltext{fsful}
Branch: 1 branch
BranchTrueFalseTotal
if (not $fulltext{"fsful"} and $string =~ /$L{"fsful"}/u) 0 337 337
Condition66%2/3
not $fulltext{"fsful"} and $string =~ /$L{"fsful"}/u
!ll&&!rl&&r
13360
MC/DC0%0/2
not $fulltext{"fsful"} and $string =~ /$L{"fsful"}/u
not $fulltext{"fsful"} $string =~ /$L{"fsful"}/u
Truth table66%2/3
not(A) and B
A= not $fulltext{"fsful"}B= $string =~ /$L{"fsful"}/u
ABresult
0X0
100
111
977 and $string =~ $L{fsful} )
978 {
979 0 $self->tag(
980 $make_tag->(
981 'fulltext', $-[0], $+[0],
982 name => "FSFUL~$1",
983 desc => "FSF Unlimited ($1 derivation)",
984 )
985 );
986 0 $match{fsful}{custom} = 1;
987 }
988  
989 # FSFULLR
990 # FIXME: add test covering this pattern
991 337 $log->trace('scan for FSFULLR fulltext');
992 337 ▶ if ( !$fulltext{fsfullr}
Branch: 1 branch
BranchTrueFalseTotal
if (not $fulltext{"fsfullr"} and $string =~ /$L{"fsfullr"}/u) 0 337 337
Condition66%2/3
not $fulltext{"fsfullr"} and $string =~ /$L{"fsfullr"}/u
!ll&&!rl&&r
13360
MC/DC0%0/2
not $fulltext{"fsfullr"} and $string =~ /$L{"fsfullr"}/u
not $fulltext{"fsfullr"} $string =~ /$L{"fsfullr"}/u
Truth table66%2/3
not(A) and B
A= not $fulltext{"fsfullr"}B= $string =~ /$L{"fsfullr"}/u
ABresult
0X0
100
111
993 and $string =~ $L{fsfullr} )
994 {
995 0 $self->tag(
996 $make_tag->(
997 'fulltext', $-[0], $+[0],
998 name => "FSFULLR~$1",
999 desc => "FSF Unlimited (with Retention, $1 derivation)",
1000 )
1001 );
1002 0 $match{fsfullr}{custom} = 1;
1003 }
1004  
1005 # usage
1006 337 $log->trace('scan atomic for singleversion usage license grant');
1007 337 for my $id (@USAGE) {
1008 9099 ▶ next if ( $match{$id}{custom} );
Branch: 1 branch
BranchTrueFalseTotal
if $match{$id}{"custom"} 0 9099 9099
1009 9099 ▶ if ( !$grant{$id}
Branch: 1 branch
BranchTrueFalseTotal
if (not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u) 0 9099 9099
Condition44%4/9
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u
!ll&&!rl&&r
909900
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic
!ll&&!rl&&r
6390360
$L_grant_stepwise_incomplete{$id} or $force_atomic
l!l&&r!l&&!r
009036
MC/DC0%0/4
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u
not $grant{$id} $L_grant_stepwise_incomplete{$id} $force_atomic $string =~ /$String::License::RE{"GRANT_$id"}/u
Truth table33%2/6
not(A) and B or C and D
A= not $grant{$id}B= $L_grant_stepwise_incomplete{$id}C= $force_atomicD= $string =~ /$String::License::RE{"GRANT_$id"}/u
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1010 and ( $L_grant_stepwise_incomplete{$id} or $force_atomic )
1011 and $string =~ $RE{"GRANT_$id"} )
1012 {
1013 0 ▶ if ( $self->contains_tag( $-[0], $+[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contains_tag($-[0], $+[0])) { } 0 0 0
1014 0 $log->tracef( 'skip grant in covered range: %s', $id );
1015 }
1016 else {
1017 $self->tag(
1018 $make_tag->(
1019 0 'grant', $-[0], $+[0], %{ $self->name_and_desc($id) }
1020 )
1021 );
1022 }
1023 }
1024  
1025 9099 ▶ if ( $grant{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grant{$id}) 63 9036 9099
1026 63 $gen_license->( $id2patterns->($id) );
1027  
1028 # skip singleversion and unversioned equivalents
1029 63 ▶ if ( $L{usage}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($L{"usage"}{$id}) 63 0 63
1030 63 $log->tracef( 'flagged license object: %s', $id );
1031 63 $match{ $L{usage}{$id} }{custom} = 1;
1032 63 ▶ if ( $L{series}{ $L{usage}{$id} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($L{"series"}{$L{"usage"}{$id}}) 63 0 63
1033 $log->tracef(
1034 'flagged license object: %s',
1035 63 $L{usage}{$id}
1036 );
1037 63 $match{ $L{series}{ $L{usage}{$id} } }{custom} = 1;
1038 }
1039 }
1040 }
1041 }
1042  
1043 # singleversion
1044 337 $log->trace('scan atomic for singleversion license grant');
1045 337 for my $id (@SINGLEVERSION) {
1046 71781 ▶ if ( !$fulltext{$id}
Branch: 1 branch
BranchTrueFalseTotal
if (not $fulltext{$id} || $grant{$id} || $match{$id}{"custom"} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u) 0 71781 71781
Condition86%13/15
not $fulltext{$id} || $grant{$id} || $match{$id}{"custom"} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u
!ll&&!rl&&r
714543270
not $fulltext{$id} || $grant{$id} || $match{$id}{"custom"} and $L_grant_stepwise_incomplete{$id} || $force_atomic
!ll&&!rl&&r
23871216327
$fulltext{$id} || $grant{$id} || $match{$id}{'custom'}
l!l&&r!l&&!r
1736571543
$fulltext{$id} or $grant{$id}
l!l&&r!l&&!r
1155871608
$L_grant_stepwise_incomplete{$id} or $force_atomic
l!l&&r!l&&!r
327071216
MC/DC0%0/6
not $fulltext{$id} || $grant{$id} || $match{$id}{"custom"} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $string =~ /$String::License::RE{"GRANT_$id"}/u
$fulltext{$id} $grant{$id} $match{$id}{'custom'} $L_grant_stepwise_incomplete{$id} $force_atomic $string =~ /$String::License::RE{"GRANT_$id"}/u
Truth table62%5/8
not(A or B || C) and D or E and F
A= $fulltext{$id}B= $grant{$id}C= $match{$id}{'custom'}D= $L_grant_stepwise_incomplete{$id}E= $force_atomicF= $string =~ /$String::License::RE{"GRANT_$id"}/u
ABCDEFresult
1XXXXX0
01XXXX0
001XXX0
00000X0
0001X00
0000100
0001X11
0000111
1047 and !$grant{$id}
1048 and !$match{$id}{custom}
1049 and ( $L_grant_stepwise_incomplete{$id} or $force_atomic )
1050 and $string =~ $RE{"GRANT_$id"} )
1051 {
1052 0 ▶ if ( $self->contains_tag( $-[0], $+[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contains_tag($-[0], $+[0])) { } 0 0 0
1053 0 $log->tracef( 'skip grant in covered range: %s', $id );
1054 }
1055 else {
1056 $self->tag(
1057 $make_tag->(
1058 0 'grant', $-[0], $+[0], %{ $self->name_and_desc($id) }
1059 )
1060 );
1061 }
1062 }
1063  
1064 71781 ▶ if ( $fulltext{$id} or $grant{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fulltext{$id} or $grant{$id}) 173 71608 71781
Condition100%3/3
$fulltext{$id} or $grant{$id}
l!l&&r!l&&!r
1155871608
MC/DC100%2/2
$fulltext{$id} or $grant{$id}
$fulltext{$id} $grant{$id}
Truth table100%3/3
A or B
A= $fulltext{$id}B= $grant{$id}
ABresult
1X1
011
000
1065 $gen_license->( $id2patterns->($id) )
1066 173 ▶ unless ( $match{$id}{custom} );
Branch: 1 branch
BranchTrueFalseTotal
unless $match{$id}{"custom"} 162 11 173
1067  
1068 # skip unversioned equivalent
1069 173 ▶ if ( $L{series}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($L{"series"}{$id}) 173 0 173
1070 173 $log->tracef( 'flagged license object: %s', $id );
1071 173 $match{ $L{series}{$id} }{custom} = 1;
1072 }
1073 }
1074 }
1075  
1076 # versioned
1077 337 $log->trace('scan atomic for versioned license grant');
1078 337 for my $id (@VERSIONED) {
1079 next
1080 if $match{$id}{custom}
1081 398 ▶ or ( $fulltext{rpsl_1} and any { $id eq $_ } qw(mpl python) )
Subroutine __ANON__: called CC=1 SCAR=0.0
1082 34037 ▶ or $fulltext{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $match{$id}{"custom"} or $fulltext{"rpsl_1"} and &any(sub { $id eq $_; } , "mpl", "python") or $fulltext{$id} 237 33800 34037
Condition88%8/9
$match{$id}{"custom"} or $fulltext{"rpsl_1"} and &any(sub { $id eq $_; } , "mpl", "python") or $fulltext{$id}
l!l&&r!l&&!r
237033800
$match{$id}{"custom"} or $fulltext{"rpsl_1"} and &any(sub { $id eq $_; } , "mpl", "python")
l!l&&r!l&&!r
235233800
$fulltext{"rpsl_1"} and &any(sub { $id eq $_; } , "mpl", "python")
!ll&&!rl&&r
336021982
MC/DC75%3/4
$match{$id}{"custom"} or $fulltext{"rpsl_1"} and &any(sub { $id eq $_; } , "mpl", "python") or $fulltext{$id}
$match{$id}{"custom"} $fulltext{"rpsl_1"} &any(sub { $id eq $_; } , "mpl", "python") $fulltext{$id}
Truth table66%4/6
A or B and C or D
A= $match{$id}{"custom"}B= $fulltext{"rpsl_1"}C= &any(sub { $id eq $_; } , "mpl", "python")D= $fulltext{$id}
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
1083 33800 ▶ if ( !$grant{$id}
Branch: 1 branch
BranchTrueFalseTotal
if (not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $String::License::RE{"GRANT_$id"} and $string =~ /$String::License::RE{"GRANT_$id"}/u) 5 33795 33800
Condition83%10/12
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $String::License::RE{"GRANT_$id"} and $string =~ /$String::License::RE{"GRANT_$id"}/u
!ll&&!rl&&r
332365595
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $String::License::RE{"GRANT_$id"}
!ll&&!rl&&r
332360564
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic
!ll&&!rl&&r
1433222564
$L_grant_stepwise_incomplete{$id} or $force_atomic
l!l&&r!l&&!r
564033222
MC/DC60%3/5
not $grant{$id} and $L_grant_stepwise_incomplete{$id} || $force_atomic and $String::License::RE{"GRANT_$id"} and $string =~ /$String::License::RE{"GRANT_$id"}/u
not $grant{$id} $L_grant_stepwise_incomplete{$id} $force_atomic $String::License::RE{"GRANT_$id"} $string =~ /$String::License::RE{"GRANT_$id"}/u
Truth table50%4/8
not(A) and B or C and D and E
A= not $grant{$id}B= $L_grant_stepwise_incomplete{$id}C= $force_atomicD= $String::License::RE{"GRANT_$id"}E= $string =~ /$String::License::RE{"GRANT_$id"}/u
ABCDEresult
0XXXX0
100XX0
11X0X0
1010X0
11X100
101100
11X111
101111
1084 and ( $L_grant_stepwise_incomplete{$id} or $force_atomic )
1085 and $RE{"GRANT_$id"}
1086 and $string =~ $RE{"GRANT_$id"} )
1087 {
1088 5 ▶ if ( $self->contains_tag( $-[0], $+[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contains_tag($-[0], $+[0])) { } 5 0 5
1089 5 $log->tracef( 'skip grant in covered range: %s', $id );
1090 }
1091 else {
1092 $self->tag(
1093 $make_tag->(
1094 0 'grant', $-[0], $+[0], %{ $self->name_and_desc($id) }
1095 )
1096 );
1097 }
1098 }
1099 33800 ▶ if ( $grant{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grant{$id}) 14 33786 33800
1100 14 $gen_license->($id);
1101 }
1102 }
1103  
1104 # other
1105 # TODO: add @GROUP
1106 337 $log->trace('scan atomic for misc fulltext/grant');
1107 337 for my $id ( @UNVERSIONED, @COMBO ) {
1108 next
1109 if (not $fulltext{$id}
1110 and not $grant{$id}
1111 and not $L_grant_stepwise_incomplete{$id}
1112 and not $force_atomic )
1113 or ( $fulltext{caldera} and $id eq 'bsd' )
1114 or ( $fulltext{cube} and $id eq 'zlib' )
1115 or ( $fulltext{dsdp} and $id eq 'ntp' )
1116 or ( $fulltext{mit_cmu} and $id eq 'ntp_disclaimer' )
1117 47517 ▶ or ( $fulltext{ntp_disclaimer} and $id eq 'ntp' );
Branch: 1 branch
BranchTrueFalseTotal
if not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib" or $fulltext{"dsdp"} and $id eq "ntp" or $fulltext{"mit_cmu"} and $id eq "ntp_disclaimer" or $fulltext{"ntp_disclaimer"} and $id eq "ntp" 46754 763 47517
Condition69%27/39
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib" or $fulltext{"dsdp"} and $id eq "ntp" or $fulltext{"mit_cmu"} and $id eq "ntp_disclaimer" or $fulltext{"ntp_disclaimer"} and $id eq "ntp"
l!l&&r!l&&!r
467540763
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib" or $fulltext{"dsdp"} and $id eq "ntp" or $fulltext{"mit_cmu"} and $id eq "ntp_disclaimer"
l!l&&r!l&&!r
467540763
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib" or $fulltext{"dsdp"} and $id eq "ntp"
l!l&&r!l&&!r
467540763
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib"
l!l&&r!l&&!r
467540763
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd"
l!l&&r!l&&!r
467540763
$fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic
l!l&&r!l&&!r
763046754
$fulltext{$id} or $grant{$id} or $L_grant_stepwise_incomplete{$id}
l!l&&r!l&&!r
9766646754
$fulltext{$id} or $grant{$id}
l!l&&r!l&&!r
871047420
$fulltext{"caldera"} and $id eq "bsd"
!ll&&!rl&&r
76300
$fulltext{"cube"} and $id eq "zlib"
!ll&&!rl&&r
76030
$fulltext{"dsdp"} and $id eq "ntp"
!ll&&!rl&&r
76030
$fulltext{"mit_cmu"} and $id eq "ntp_disclaimer"
!ll&&!rl&&r
75760
$fulltext{"ntp_disclaimer"} and $id eq "ntp"
!ll&&!rl&&r
75760
MC/DC21%3/14
not $fulltext{$id} || $grant{$id} || $L_grant_stepwise_incomplete{$id} || $force_atomic or $fulltext{"caldera"} and $id eq "bsd" or $fulltext{"cube"} and $id eq "zlib" or $fulltext{"dsdp"} and $id eq "ntp" or $fulltext{"mit_cmu"} and $id eq "ntp_disclaimer" or $fulltext{"ntp_disclaimer"} and $id eq "ntp"
$fulltext{$id} $grant{$id} $L_grant_stepwise_incomplete{$id} $force_atomic $fulltext{"caldera"} $id eq "bsd" $fulltext{"cube"} $id eq "zlib" $fulltext{"dsdp"} $id eq "ntp" $fulltext{"mit_cmu"} $id eq "ntp_disclaimer" $fulltext{"ntp_disclaimer"} $id eq "ntp"
Truth table4%12/253
not(A or B or C || D) or E and F or G and H or I and J or K and L or M and N
A= $fulltext{$id}B= $grant{$id}C= $L_grant_stepwise_incomplete{$id}D= $force_atomicE= $fulltext{"caldera"}F= $id eq "bsd"G= $fulltext{"cube"}H= $id eq "zlib"I= $fulltext{"dsdp"}J= $id eq "ntp"K= $fulltext{"mit_cmu"}L= $id eq "ntp_disclaimer"M= $fulltext{"ntp_disclaimer"}N= $id eq "ntp"
ABCDEFGHIJKLMNresult
0000XXXXXXXXXX1
1XXX11XXXXXXXX1
01XX11XXXXXXXX1
001X11XXXXXXXX1
000111XXXXXXXX1
1XXX0X11XXXXXX1
1XXX1011XXXXXX1
01XX0X11XXXXXX1
01XX1011XXXXXX1
001X0X11XXXXXX1
001X1011XXXXXX1
00010X11XXXXXX1
00011011XXXXXX1
1XXX0X0X11XXXX1
1XXX0X1011XXXX1
1XXX100X11XXXX1
1XXX101011XXXX1
01XX0X0X11XXXX1
01XX0X1011XXXX1
01XX100X11XXXX1
01XX101011XXXX1
001X0X0X11XXXX1
001X0X1011XXXX1
001X100X11XXXX1
001X101011XXXX1
00010X0X11XXXX1
00010X1011XXXX1
0001100X11XXXX1
0001101011XXXX1
1XXX0X0X0X11XX1
1XXX0X0X1011XX1
1XXX0X100X11XX1
1XXX0X101011XX1
1XXX100X0X11XX1
1XXX100X1011XX1
1XXX10100X11XX1
1XXX10101011XX1
01XX0X0X0X11XX1
01XX0X0X1011XX1
01XX0X100X11XX1
01XX0X101011XX1
01XX100X0X11XX1
01XX100X1011XX1
01XX10100X11XX1
01XX10101011XX1
001X0X0X0X11XX1
001X0X0X1011XX1
001X0X100X11XX1
001X0X101011XX1
001X100X0X11XX1
001X100X1011XX1
001X10100X11XX1
001X10101011XX1
00010X0X0X11XX1
00010X0X1011XX1
00010X100X11XX1
00010X101011XX1
0001100X0X11XX1
0001100X1011XX1
000110100X11XX1
000110101011XX1
1XXX0X0X0X0X111
1XXX0X0X0X10111
1XXX0X0X100X111
1XXX0X0X1010111
1XXX0X100X0X111
1XXX0X100X10111
1XXX0X10100X111
1XXX0X101010111
1XXX100X0X0X111
1XXX100X0X10111
1XXX100X100X111
1XXX100X1010111
1XXX10100X0X111
1XXX10100X10111
1XXX1010100X111
1XXX10101010111
01XX0X0X0X0X111
01XX0X0X0X10111
01XX0X0X100X111
01XX0X0X1010111
01XX0X100X0X111
01XX0X100X10111
01XX0X10100X111
01XX0X101010111
01XX100X0X0X111
01XX100X0X10111
01XX100X100X111
01XX100X1010111
01XX10100X0X111
01XX10100X10111
01XX1010100X111
01XX10101010111
001X0X0X0X0X111
001X0X0X0X10111
001X0X0X100X111
001X0X0X1010111
001X0X100X0X111
001X0X100X10111
001X0X10100X111
001X0X101010111
001X100X0X0X111
001X100X0X10111
001X100X100X111
001X100X1010111
001X10100X0X111
001X10100X10111
001X1010100X111
001X10101010111
00010X0X0X0X111
00010X0X0X10111
00010X0X100X111
00010X0X1010111
00010X100X0X111
00010X100X10111
00010X10100X111
00010X101010111
0001100X0X0X111
0001100X0X10111
0001100X100X111
0001100X1010111
000110100X0X111
000110100X10111
00011010100X111
000110101010111
1XXX0X0X0X0X0X0
1XXX0X0X0X0X100
1XXX0X0X0X100X0
1XXX0X0X0X10100
1XXX0X0X100X0X0
1XXX0X0X100X100
1XXX0X0X10100X0
1XXX0X0X1010100
1XXX0X100X0X0X0
1XXX0X100X0X100
1XXX0X100X100X0
1XXX0X100X10100
1XXX0X10100X0X0
1XXX0X10100X100
1XXX0X1010100X0
1XXX0X101010100
1XXX100X0X0X0X0
1XXX100X0X0X100
1XXX100X0X100X0
1XXX100X0X10100
1XXX100X100X0X0
1XXX100X100X100
1XXX100X10100X0
1XXX100X1010100
1XXX10100X0X0X0
1XXX10100X0X100
1XXX10100X100X0
1XXX10100X10100
1XXX1010100X0X0
1XXX1010100X100
1XXX101010100X0
1XXX10101010100
01XX0X0X0X0X0X0
01XX0X0X0X0X100
01XX0X0X0X100X0
01XX0X0X0X10100
01XX0X0X100X0X0
01XX0X0X100X100
01XX0X0X10100X0
01XX0X0X1010100
01XX0X100X0X0X0
01XX0X100X0X100
01XX0X100X100X0
01XX0X100X10100
01XX0X10100X0X0
01XX0X10100X100
01XX0X1010100X0
01XX0X101010100
01XX100X0X0X0X0
01XX100X0X0X100
01XX100X0X100X0
01XX100X0X10100
01XX100X100X0X0
01XX100X100X100
01XX100X10100X0
01XX100X1010100
01XX10100X0X0X0
01XX10100X0X100
01XX10100X100X0
01XX10100X10100
01XX1010100X0X0
01XX1010100X100
01XX101010100X0
01XX10101010100
001X0X0X0X0X0X0
001X0X0X0X0X100
001X0X0X0X100X0
001X0X0X0X10100
001X0X0X100X0X0
001X0X0X100X100
001X0X0X10100X0
001X0X0X1010100
001X0X100X0X0X0
001X0X100X0X100
001X0X100X100X0
001X0X100X10100
001X0X10100X0X0
001X0X10100X100
001X0X1010100X0
001X0X101010100
001X100X0X0X0X0
001X100X0X0X100
001X100X0X100X0
001X100X0X10100
001X100X100X0X0
001X100X100X100
001X100X10100X0
001X100X1010100
001X10100X0X0X0
001X10100X0X100
001X10100X100X0
001X10100X10100
001X1010100X0X0
001X1010100X100
001X101010100X0
001X10101010100
00010X0X0X0X0X0
00010X0X0X0X100
00010X0X0X100X0
00010X0X0X10100
00010X0X100X0X0
00010X0X100X100
00010X0X10100X0
00010X0X1010100
00010X100X0X0X0
00010X100X0X100
00010X100X100X0
00010X100X10100
00010X10100X0X0
00010X10100X100
00010X1010100X0
00010X101010100
0001100X0X0X0X0
0001100X0X0X100
0001100X0X100X0
0001100X0X10100
0001100X100X0X0
0001100X100X100
0001100X10100X0
0001100X1010100
000110100X0X0X0
000110100X0X100
000110100X100X0
000110100X10100
00011010100X0X0
00011010100X100
0001101010100X0
000110101010100
1118  
1119 763 ▶ if ( !$fulltext{$id}
Branch: 1 branch
BranchTrueFalseTotal
if (not $fulltext{$id} || $grant{$id} and $string =~ /$String::License::RE{"GRANT_$id"}/u) 0 763 763
Condition83%5/6
not $fulltext{$id} || $grant{$id} and $string =~ /$String::License::RE{"GRANT_$id"}/u
!ll&&!rl&&r
976660
$fulltext{$id} || $grant{$id}
l!l&&r!l&&!r
8710666
MC/DC0%0/3
not $fulltext{$id} || $grant{$id} and $string =~ /$String::License::RE{"GRANT_$id"}/u
$fulltext{$id} $grant{$id} $string =~ /$String::License::RE{"GRANT_$id"}/u
Truth table75%3/4
not(A || B) and C
A= $fulltext{$id}B= $grant{$id}C= $string =~ /$String::License::RE{"GRANT_$id"}/u
ABCresult
1XX0
01X0
0000
0011
1120 and !$grant{$id}
1121 and $string =~ $RE{"GRANT_$id"} )
1122 {
1123 0 ▶ if ( $self->contains_tag( $-[0], $+[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contains_tag($-[0], $+[0])) { } 0 0 0
1124 0 $log->tracef( 'skip grant in covered range: %s', $id );
1125 }
1126 else {
1127 $self->tag(
1128 $make_tag->(
1129 0 'grant', $-[0], $+[0], %{ $self->name_and_desc($id) }
1130 )
1131 );
1132 }
1133 }
1134 763 ▶ if ( $fulltext{$id} or $grant{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fulltext{$id} or $grant{$id}) 97 666 763
Condition100%3/3
$fulltext{$id} or $grant{$id}
l!l&&r!l&&!r
8710666
MC/DC100%2/2
$fulltext{$id} or $grant{$id}
$fulltext{$id} $grant{$id}
Truth table100%3/3
A or B
A= $fulltext{$id}B= $grant{$id}
ABresult
1X1
011
000
1135 97 $gen_license->($id);
1136 }
1137 }
1138  
1139 # Expressions and exceptions contain DEP-5 or SPDX identifiers;
1140 # flaws contain non-SPDX notes.
1141 337 my ( $licenses, $exceptions, $flaws ) = $self->get_tags;
1142  
1143 337 my @expressions = map { $_->[1] } @$licenses;
1144 337 my @license = map { $_->[2] } @$licenses;
1145 337 $expr = join( ' and/or ', sort @expressions );
1146 337 $license = join( ' and/or ', sort @license );
1147 337 ▶ $expr ||= 'UNKNOWN';
Condition100%2/2
$expr ||= "UNKNOWN"
l!l
31324
MC/DC100%1/1
$expr ||= "UNKNOWN"
$expr
Truth table100%2/2
A
A= $expr
Aresult
11
00
1148 337 ▶ $license ||= 'UNKNOWN';
Condition100%2/2
$license ||= "UNKNOWN"
l!l
31324
MC/DC100%1/1
$license ||= "UNKNOWN"
$license
Truth table100%2/2
A
A= $license
Aresult
11
00
1149  
1150 337 ▶ if (@$exceptions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$exceptions) 53 284 337
1151 53 ▶ $expr = "($expr)"
Branch: 1 branch
BranchTrueFalseTotal
if @expressions > 1 20 33 53
1152 if ( @expressions > 1 );
1153 $expr .= ' with ' . join(
1154 '_AND_',
1155 53 sort map { $_->[1] } @$exceptions
1156 ) . ' exception';
1157 }
1158 337 ▶ if (@$flaws) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$flaws) 28 309 337
1159 $license .= ' [' . join(
1160 ', ',
1161 28 sort map { $_->[2] } @$flaws
1162 ) . ']';
1163 }
1164 337 $log->infof( 'resolved license expression: %s', $expr );
1165  
1166 337 return $self;
1167 }
1168  
1169 =item as_text
1170  
1171 Returns identified licensing patterns as a string,
1172 either structured as SPDX License Expressions,
1173 or with scheme-less naming as a short description.
1174  
1175 =cut
1176  
1177 337 ▶method as_text ()
Subroutine as_text: called CC=4 SCAR=14.1
Pod documented
1178 {
1179 337 ▶ if ( $naming->list_schemes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($naming->list_schemes) 317 20 337
1180 317 ▶ $self->resolve
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 317 0 317
1181 unless $expr;
1182  
1183 317 return $expr;
1184 }
1185  
1186 $self->resolve
1187 20 ▶ unless $license;
Branch: 1 branch
BranchTrueFalseTotal
unless $license 20 0 20
1188  
1189 20 return $license;
1190 }
1191  
1192 =back
1193  
1194 =encoding UTF-8
1195  
1196 =head1 AUTHOR
1197  
1198 Jonas Smedegaard C<< <dr@jones.dk> >>
1199  
1200 =head1 COPYRIGHT AND LICENSE
1201  
1202 This program is based on the script "licensecheck" from the KDE SDK,
1203 originally introduced by Stefan Westerfeld C<< <stefan@space.twc.de> >>.
1204  
1205 Copyright © 2007, 2008 Adam D. Barratt
1206  
1207 Copyright © 2016-2023 Jonas Smedegaard
1208  
1209 Copyright © 2017-2022 Purism SPC
1210  
1211 This program is free software:
1212 you can redistribute it and/or modify it
1213 under the terms of the GNU Affero General Public License
1214 as published by the Free Software Foundation,
1215 either version 3, or (at your option) any later version.
1216  
1217 This program is distributed in the hope that it will be useful,
1218 but WITHOUT ANY WARRANTY;
1219 without even the implied warranty
1220 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1221 See the GNU Affero General Public License for more details.
1222  
1223 You should have received a copy
1224 of the GNU Affero General Public License along with this program.
1225 If not, see <https://www.gnu.org/licenses/>.
1226  
1227 =cut
1228  
1229 12 1;
↑ Summary License/Naming.pm »