File Coverage

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


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