File Coverage

blib/lib/String/License/Naming.pm
Criterion Covered Total %
statement 51 55 92.7
branch 19 26 73.0
condition 7 8 87.5
subroutine 8 8 100.0
pod 0 1 0.0
total 85 98 86.7


line stmt bran cond sub pod time code
1 12     12   867 use v5.20;
  12         48  
2 12     12   95 use utf8;
  12         25  
  12         151  
3 12     12   553 use warnings;
  12         37  
  12         759  
4 12     12   70 use feature qw(signatures);
  12         30  
  12         2077  
5 12     12   96 no warnings qw(experimental::signatures);
  12         47  
  12         634  
6              
7 12     12   111 use Feature::Compat::Class 0.07;
  12         276  
  12         89  
8              
9             =head1 NAME
10              
11             String::License::Naming - base class for names of licenses and license naming schemes
12              
13             =head1 VERSION
14              
15             Version v0.0.11
16              
17             =head1 DESCRIPTION
18              
19             L is a base class
20             for how to constrain, enumerate, and present licenses.
21              
22             This class cannot be instantiated on its own.
23             Please use a subclass instead,
24             e.g. L.
25              
26             =cut
27              
28             package String::License::Naming v0.0.11;
29              
30 12     12   1283 use namespace::clean;
  12         26  
  12         73  
31              
32             class String::License::Naming;
33              
34             method list_schemes () { ...; }
35              
36             method list_licenses () { ...; }
37              
38 20         66 sub resolve_shortnames ( $keys, $schemes, $bootstrap = undef )
  20         41  
39 20     20 0 65 {
  20         49  
  20         132  
40 20         45 my ( @schemes, $fallback, %names, @result );
41              
42 20 100 100     8489 $keys = [ sort keys %Regexp::Pattern::License::RE ]
43             unless defined $keys and scalar @$keys;
44              
45 20         508 for (@$schemes) {
46 22 100       92 if ( $_ eq 'internal' ) {
47 4         8 $fallback = 1;
48 4         12 last;
49             }
50 18         75 push @schemes, $_;
51             }
52              
53             KEY:
54 20         53 for my $key (@$keys) {
55 11014 100       19296 for my $key2 (
56             @schemes
57 8308         107333 ? sort keys %{ $Regexp::Pattern::License::RE{$key} }
58             : ()
59             )
60             {
61 157226         218091 my ( %attr, @attr );
62              
63 157226         296988 @attr = split /[.]/, $key2;
64              
65 157226 100       347183 next unless $attr[0] eq 'name';
66              
67             # TODO: simplify, and require R::P::License v3.8.1
68 24460 50       125531 if ( $Regexp::Pattern::License::VERSION < v3.8.1 ) {
69 0 0       0 push @attr, undef
70             if @attr % 2;
71 0         0 %attr = @attr[ 2 .. $#attr ];
72 0 0       0 next if exists $attr{version};
73 0 0       0 next if exists $attr{until};
74             }
75             else {
76 24460         61271 %attr = @attr[ 2 .. $#attr ];
77 24460 100       56862 next if exists $attr{until};
78             }
79 22912         53506 for my $org (@schemes) {
80 27091 100 100     95434 if ( exists $attr{org} and $attr{org} eq $org ) {
81 3864         20911 $names{$key} = $Regexp::Pattern::License::RE{$key}{$key2};
82 3864         21800 next KEY;
83             }
84             }
85             }
86 7150 100       22082 if ($fallback) {
    100          
87 1328   66     4018 $names{$key} = $Regexp::Pattern::License::RE{$key}{name} // $key;
88             }
89             elsif ( exists $Regexp::Pattern::License::RE{$key}{name} ) {
90 5238         14079 $names{$key} = $Regexp::Pattern::License::RE{$key}{name};
91             }
92             }
93              
94 20 100       6953 @result = $bootstrap ? sort keys %names : sort { lc $a cmp lc $b }
  19788         27939  
95             values %names;
96              
97 20         5938 return @result;
98             }
99              
100             =encoding UTF-8
101              
102             =head1 AUTHOR
103              
104             Jonas Smedegaard C<< >>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             Copyright © 2023 Jonas Smedegaard
109              
110             This program is free software:
111             you can redistribute it and/or modify it
112             under the terms of the GNU Affero General Public License
113             as published by the Free Software Foundation,
114             either version 3, or (at your option) any later version.
115              
116             This program is distributed in the hope that it will be useful,
117             but WITHOUT ANY WARRANTY;
118             without even the implied warranty
119             of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
120             See the GNU Affero General Public License for more details.
121              
122             You should have received a copy
123             of the GNU Affero General Public License along with this program.
124             If not, see .
125              
126             =cut
127              
128             1;