License/Naming.pm

filter: Statementstmt 87.5% 42 / 48 Branchbran 73.0% 19 / 26 Conditioncond 87.5% 7 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 3 totaltotal 78.5% 77 / 98 CC 22 SCAR 29.6
CC
22
Cov
83%
resolve_shortnames
25.0
list_schemes
2.0
list_licenses
2.0
CRAP 19.3
« License.pm ↑ Summary License/Naming/Custom.pm »
1 14 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 14 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 String::License::Naming - base class for names of licenses and license naming schemes
10  
11 =head1 VERSION
12  
13 Version v0.1.1
14  
15 =head1 DESCRIPTION
16  
17 L<String::License::Naming> is a base class
18 for how to constrain, enumerate, and present licenses.
19  
20 This class cannot be instantiated on its own.
21 Please use a subclass instead,
22 e.g. L<String::License::Naming::SPDX>.
23  
24 =cut
25  
26 package String::License::Naming v0.1.1;
27  
28 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 class String::License::Naming;
31  
32 0 ▶method list_schemes () { ...; }
Subroutine list_schemes: not called CC=1 SCAR=6.9
Pod undocumented
33  
34 0 ▶method list_licenses () { ...; }
Subroutine list_licenses: not called CC=1 SCAR=6.9
Pod undocumented
35  
36 29 ▶sub resolve_shortnames ( $keys, $schemes, $bootstrap = undef )
Subroutine resolve_shortnames: called CC=22 SCAR=32.2
Pod undocumented
37 29 {
38 29 my ( @schemes, $fallback, %names, @result );
39  
40 29 ▶ $keys = [ sort keys %Regexp::Pattern::License::RE ]
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keys and scalar @$keys 24 5 29
Condition100%2/2
defined $keys and scalar @$keys
!ll
245
MC/DC100%1/1
defined $keys and scalar @$keys
defined $keys
Truth table100%2/2
A
A= defined $keys
Aresult
00
11
41 unless defined $keys and scalar @$keys;
42  
43 29 for (@$schemes) {
44 31 ▶ if ( $_ eq 'internal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "internal") 4 27 31
45 4 $fallback = 1;
46 4 last;
47 }
48 27 push @schemes, $_;
49 }
50  
51 KEY:
52 29 for my $key (@$keys) {
53 16090 ▶ for my $key2 (
Branch: 1 branch
BranchTrueFalseTotal
@schemes ? : 13384 2706 16090
54 @schemes
55 13384 ? sort keys %{ $Regexp::Pattern::License::RE{$key} }
56 : ()
57 )
58 {
59 249776 my ( %attr, @attr );
60  
61 249776 @attr = split /[.]/, $key2;
62  
63 249776 ▶ next unless $attr[0] eq 'name';
Branch: 1 branch
BranchTrueFalseTotal
unless $attr[0] eq "name" 210358 39418 249776
64  
65 # TODO: simplify, and require R::P::License v3.8.1
66 39418 ▶ if ( $Regexp::Pattern::License::VERSION < v3.8.1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Regexp::Pattern::License::VERSION < v3.8.1) { } 0 39418 39418
67 0 ▶ push @attr, undef
Branch: 1 branch
BranchTrueFalseTotal
if @attr % 2 0 0 0
68 if @attr % 2;
69 0 %attr = @attr[ 2 .. $#attr ];
70 0 ▶ next if exists $attr{version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr{"version"} 0 0 0
71 0 ▶ next if exists $attr{until};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr{"until"} 0 0 0
72 }
73 else {
74 39418 %attr = @attr[ 2 .. $#attr ];
75 39418 ▶ next if exists $attr{until};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr{"until"} 2538 36880 39418
76 }
77 36880 for my $org (@schemes) {
78 41059 ▶ if ( exists $attr{org} and $attr{org} eq $org ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr{"org"} and $attr{"org"} eq $org) 6627 34432 41059
Condition100%3/3
exists $attr{"org"} and $attr{"org"} eq $org
!ll&&!rl&&r
19710147226627
MC/DC100%2/2
exists $attr{"org"} and $attr{"org"} eq $org
exists $attr{"org"} $attr{"org"} eq $org
Truth table100%3/3
A and B
A= exists $attr{"org"}B= $attr{"org"} eq $org
ABresult
0X0
100
111
79 6627 $names{$key} = $Regexp::Pattern::License::RE{$key}{$key2};
80 6627 next KEY;
81 }
82 }
83 }
84 9463 ▶ if ($fallback) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fallback) { } 1328 8135 9463
elsif (exists $Regexp::Pattern::License::RE{$key}{'name'}) { } 7056 1079 8135
85 1328 ▶ $names{$key} = $Regexp::Pattern::License::RE{$key}{name} // $key;
Condition66%2/3
$Regexp::Pattern::License::RE{$key}{"name"} // $key
l!l&&r!l&&!r
11341940
MC/DC0%0/2
$Regexp::Pattern::License::RE{$key}{"name"} // $key
$Regexp::Pattern::License::RE{$key}{"name"} $key
Truth table66%2/3
A // B
A= $Regexp::Pattern::License::RE{$key}{"name"}B= $key
ABresult
1X1
011
000
86 }
87 elsif ( exists $Regexp::Pattern::License::RE{$key}{name} ) {
88 7056 $names{$key} = $Regexp::Pattern::License::RE{$key}{name};
89 }
90 }
91  
92 29 ▶ @result = $bootstrap ? sort keys %names : sort { lc $a cmp lc $b }
Branch: 1 branch
BranchTrueFalseTotal
$bootstrap ? : 24 5 29
93 values %names;
94  
95 29 return @result;
96 }
97  
98 =encoding UTF-8
99  
100 =head1 AUTHOR
101  
102 Jonas Smedegaard C<< <dr@jones.dk> >>
103  
104 =head1 COPYRIGHT AND LICENSE
105  
106 Copyright © 2023 Jonas Smedegaard
107  
108 This program is free software:
109 you can redistribute it and/or modify it
110 under the terms of the GNU Affero General Public License
111 as published by the Free Software Foundation,
112 either version 3, or (at your option) any later version.
113  
114 This program is distributed in the hope that it will be useful,
115 but WITHOUT ANY WARRANTY;
116 without even the implied warranty
117 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
118 See the GNU Affero General Public License for more details.
119  
120 You should have received a copy
121 of the GNU Affero General Public License along with this program.
122 If not, see <https://www.gnu.org/licenses/>.
123  
124 =cut
125  
126 14 1;
« License.pm ↑ Summary License/Naming/Custom.pm »