File Coverage

blib/lib/String/License/Naming/SPDX.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod n/a
total 47 47 100.0


line stmt bran cond sub pod time code
1 11     11   1397493 use v5.20;
  11         47  
2 11     11   66 use utf8;
  11         21  
  11         73  
3 11     11   325 use warnings;
  11         26  
  11         661  
4 11     11   63 use feature qw(signatures);
  11         23  
  11         1482  
5 11     11   65 no warnings qw(experimental::signatures);
  11         25  
  11         553  
6              
7 11     11   624 use Feature::Compat::Class 0.07;
  11         705  
  11         67  
8              
9             =head1 NAME
10              
11             String::License::Naming::SPDX - licenses as named by SPDX
12              
13             =head1 VERSION
14              
15             Version v0.0.11
16              
17             =head1 SYNOPSIS
18              
19             use String::License::Naming::SPDX;
20              
21             my $spdx = String::License::Naming::SPDX->new;
22              
23             my $license = [ grep { /^(Expat|Perl)$/ } $spdx->list_licenses ]; # => is_deeply ['Perl']
24              
25             =head1 DESCRIPTION
26              
27             L enumerates supported licenses
28             matching an ordered set of naming schemes,
29             or enumerates the names of supported license naming schemes.
30              
31             Some licenses are known by different names.
32             E.g. the license "MIT" according to SPDX
33             is named "Expat" in Debian.
34              
35             Some licenses are not always represented.
36             E.g. "Perl" is a (discouraged) license in Debian
37             while it is a relationship of several licenses with SPDX
38             (and that expression is recommended in Debian as well).
39              
40             By default,
41             licenses are matched using naming schemes C<[ 'spdx', 'internal' ]>,
42             which lists all supported licenses,
43             preferrably by their SPDX name
44             or as fallback by an internal name.
45              
46             =cut
47              
48             package String::License::Naming::SPDX v0.0.11;
49              
50 11     11   1129 use Carp qw(croak);
  11         25  
  11         660  
51 11     11   60 use Log::Any ();
  11         25  
  11         360  
52 11     11   57 use List::Util qw(uniq);
  11         23  
  11         864  
53 11     11   87 use Regexp::Pattern::License 3.4.0;
  11         175  
  11         343  
54              
55 11     11   639 use namespace::clean;
  11         19883  
  11         89  
56              
57 1     1   837 class String::License::Naming::SPDX : isa(String::License::Naming);
  1         4  
  1         348  
58              
59             field $log;
60              
61             =head1 CONSTRUCTOR
62              
63             =over
64              
65             =item new
66              
67             Constructs and returns a String::License::Naming object.
68              
69             Includes all licenses defined by SPDX,
70             and presents them by their SPDX shortname.
71              
72             =back
73              
74             =cut
75              
76             field $schemes;
77              
78             # TODO: maybe support seeding explicit keys
79             field $keys;
80              
81             ADJUST {
82             $log = Log::Any->get_logger;
83              
84             $schemes = ['spdx'];
85              
86             $keys = [
87             String::License::Naming::resolve_shortnames( $keys, $schemes, 1 ) ];
88             }
89              
90             =head1 FUNCTIONS
91              
92             =item list_schemes
93              
94             Returns a list of license naming schemes in use.
95              
96             =cut
97              
98             method list_schemes ()
99             {
100             return @$schemes;
101             }
102              
103             =item list_licenses
104              
105             Returns a list of all licensing patterns covered by SPDX,
106             each labeled by SPDX shortname.
107              
108             =cut
109              
110             method list_licenses ()
111             {
112             return String::License::Naming::resolve_shortnames( $keys, $schemes );
113             }
114              
115             =back
116              
117             =encoding UTF-8
118              
119             =head1 AUTHOR
120              
121             Jonas Smedegaard C<< >>
122              
123             =head1 COPYRIGHT AND LICENSE
124              
125             Copyright © 2023 Jonas Smedegaard
126              
127             This program is free software:
128             you can redistribute it and/or modify it
129             under the terms of the GNU Affero General Public License
130             as published by the Free Software Foundation,
131             either version 3, or (at your option) any later version.
132              
133             This program is distributed in the hope that it will be useful,
134             but WITHOUT ANY WARRANTY;
135             without even the implied warranty
136             of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
137             See the GNU Affero General Public License for more details.
138              
139             You should have received a copy
140             of the GNU Affero General Public License along with this program.
141             If not, see .
142              
143             =cut
144              
145             1;