File Coverage

blib/lib/String/License/Naming.pm
Criterion Covered Total %
statement 41 49 83.6
branch 19 26 73.0
condition 7 8 87.5
subroutine 6 8 75.0
pod 0 3 0.0
total 73 94 77.6


line stmt bran cond sub pod time code
1 12     12   540 use Feature::Compat::Class 0.04;
  12         224  
  12         75  
2              
3 12     12   3311 use v5.12;
  12         44  
4 12     12   73 use utf8;
  12         23  
  12         96  
5 12     12   359 use warnings;
  12         41  
  12         648  
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.0.4
14              
15             =head1 DESCRIPTION
16              
17             L 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.
23              
24             =cut
25              
26             package String::License::Naming v0.0.4;
27              
28 12     12   113 use namespace::clean;
  12         31  
  12         82  
29              
30             class String::License::Naming;
31              
32             method list_schemes
33 0     0 0 0 {
34 0         0 ...;
35             }
36              
37             method list_licenses
38 0     0 0 0 {
39 0         0 ...;
40             }
41              
42             sub resolve_shortnames
43             {
44 20     20 0 66 my ( $keys, $schemes, $bootstrap ) = @_;
45 20         48 my ( @schemes, $fallback, %names );
46              
47 20 100 100     7835 $keys = [ sort keys %Regexp::Pattern::License::RE ]
48             unless defined $keys and scalar @$keys;
49              
50 20         348 for (@$schemes) {
51 22 100       94 if ( $_ eq 'internal' ) {
52 4         11 $fallback = 1;
53 4         11 last;
54             }
55 18         58 push @schemes, $_;
56             }
57              
58             KEY:
59 20         69 for my $key (@$keys) {
60 11014 100       18241 for my $key2 (
61             @schemes
62 8308         97390 ? sort keys %{ $Regexp::Pattern::License::RE{$key} }
63             : ()
64             )
65             {
66 157440         192233 my %attr;
67 157440         293914 my @attr = split /[.]/, $key2;
68              
69 157440 100       317191 next unless $attr[0] eq 'name';
70              
71             # TODO: simplify, and require R::P::License v3.8.1
72 24445 50       111728 if ( $Regexp::Pattern::License::VERSION < v3.8.1 ) {
73 0 0       0 push @attr, undef
74             if @attr % 2;
75 0         0 %attr = @attr[ 2 .. $#attr ];
76 0 0       0 next if exists $attr{version};
77 0 0       0 next if exists $attr{until};
78             }
79             else {
80 24445         56401 %attr = @attr[ 2 .. $#attr ];
81 24445 100       51312 next if exists $attr{until};
82             }
83 22897         47814 for my $org (@schemes) {
84 27073 100 100     79117 if ( exists $attr{org} and $attr{org} eq $org ) {
85 3864         11629 $names{$key} = $Regexp::Pattern::License::RE{$key}{$key2};
86 3864         13251 next KEY;
87             }
88             }
89             }
90 7150 100       18900 if ($fallback) {
    100          
91 1328   66     4220 $names{$key} = $Regexp::Pattern::License::RE{$key}{name} // $key;
92             }
93             elsif ( exists $Regexp::Pattern::License::RE{$key}{name} ) {
94 5238         13134 $names{$key} = $Regexp::Pattern::License::RE{$key}{name};
95             }
96             }
97              
98 20 100       5672 my @result = $bootstrap ? sort keys %names : sort { lc $a cmp lc $b }
  19794         26994  
99             values %names;
100              
101 20         4260 return @result;
102             }
103              
104             =encoding UTF-8
105              
106             =head1 AUTHOR
107              
108             Jonas Smedegaard C<< >>
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             Copyright © 2023 Jonas Smedegaard
113              
114             This program is free software:
115             you can redistribute it and/or modify it
116             under the terms of the GNU Affero General Public License
117             as published by the Free Software Foundation,
118             either version 3, or (at your option) any later version.
119              
120             This program is distributed in the hope that it will be useful,
121             but WITHOUT ANY WARRANTY;
122             without even the implied warranty
123             of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
124             See the GNU Affero General Public License for more details.
125              
126             You should have received a copy
127             of the GNU Affero General Public License along with this program.
128             If not, see .
129              
130             =cut
131              
132             1;