File Coverage

blib/lib/String/License/Naming/SPDX.pm
Criterion Covered Total %
statement 43 43 100.0
branch n/a
condition n/a
subroutine 14 14 100.0
pod 2 2 100.0
total 59 59 100.0


line stmt bran cond sub pod time code
1 11     11   1238970 use v5.20;
  11         52  
2 11     11   82 use utf8;
  11         47  
  11         73  
3 11     11   277 use warnings;
  11         24  
  11         347  
4 11     11   64 use feature qw(signatures);
  11         32  
  11         904  
5 11     11   75 no warnings qw(experimental::signatures);
  11         21  
  11         428  
6              
7 11     11   650 use Feature::Compat::Class 0.04;
  11         469  
  11         61  
8              
9             =head1 NAME
10              
11             String::License::Naming::SPDX - licenses as named by SPDX
12              
13             =head1 VERSION
14              
15             Version v0.0.6
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.6;
49              
50 11     11   15327 use Carp qw(croak);
  11         33  
  11         679  
51 11     11   84 use Log::Any ();
  11         31  
  11         311  
52 11     11   665 use List::SomeUtils qw(uniq);
  11         13782  
  11         746  
53 11     11   98 use Regexp::Pattern::License 3.4.0;
  11         142  
  11         381  
54              
55 11     11   663 use namespace::clean;
  11         10410  
  11         74  
56              
57 1     1   749 class String::License::Naming::SPDX :isa(String::License::Naming);
  1         3  
  1         454  
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 4632         6222 method list_schemes ()
  4632         5915  
99 4632     4632 1 9167 {
100 4632         11523 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 1         3 method list_licenses ()
  1         3  
111 1     1 1 5 {
112 1         6 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;