File Coverage

blib/lib/Software/LicenseMoreUtils.pm
Criterion Covered Total %
statement 54 56 96.4
branch 6 10 60.0
condition 4 5 80.0
subroutine 14 15 93.3
pod 1 2 50.0
total 79 88 89.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Software-LicenseMoreUtils
3             #
4             # This software is copyright (c) 2018, 2022 by Dominique Dumont.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Software::LicenseMoreUtils;
10             $Software::LicenseMoreUtils::VERSION = '1.008';
11 3     3   1952 use strict;
  3         6  
  3         71  
12 3     3   13 use warnings;
  3         5  
  3         56  
13 3     3   25 use 5.10.1;
  3         9  
14              
15 3     3   1275 use Try::Tiny;
  3         5105  
  3         129  
16 3     3   17 use Carp;
  3         4  
  3         126  
17 3     3   1116 use Software::LicenseMoreUtils::LicenseWithSummary;
  3         6  
  3         109  
18 3     3   1184 use Software::License 0.103014;
  3         46573  
  3         81  
19              
20             # ABSTRACT: More utilities and a summary for Software::License
21              
22 3     3   16 use base qw/Software::LicenseUtils/;
  3         6  
  3         1219  
23              
24             # a short name with '+' at the end of the short name implies an
25             # "or later" clause. i.e. GPL-1+ is "GPL-1 or any later version"
26             my %more_short_names = (
27             'Apache-2' => 'Software::License::Apache_2_0',
28             'Artistic' => 'Software::License::Artistic_1_0',
29             'Artistic-1' => 'Software::License::Artistic_1_0',
30             'Artistic-2' => 'Software::License::Artistic_2_0',
31             'BSD-3-clause' => 'Software::License::BSD',
32             'Expat' => 'Software::License::MIT',
33             'LGPL-2' => 'Software::LicenseMoreUtils::LGPL_2',
34             'LGPL_2' => 'Software::LicenseMoreUtils::LGPL_2',
35             'LGPL-3' => 'Software::License::LGPL_3_0',
36             'MPL-1.0' => 'Software::License::Mozilla_1_0',
37             'MPL-1.1' => 'Software::License::Mozilla_1_1',
38             'MPL-2.0' => 'Software::License::Mozilla_2_0',
39              
40             # GPL SPDX identifiers have another convention for GPL version number
41             'LGPL-2.0' => 'Software::LicenseMoreUtils::LGPL_2',
42              
43             'GPL-1.0' => 'Software::License::GPL_1',
44             'GPL-2.0' => 'Software::License::GPL_2',
45             'GPL-3.0' => 'Software::License::GPL_3',
46             );
47              
48             sub _create_license {
49 46     46   76 my ( $class, $arg ) = @_;
50             croak "no license short name specified"
51 46 50       88 unless defined $arg->{short_name};
52              
53 46         56 my $lic_obj;
54             try {
55 46     46   1738 $lic_obj = SUPER::new_from_short_name($arg);
56 46         205 };
57              
58 46 50       601 return $lic_obj if $lic_obj;
59              
60             try {
61 46     46   1312 $lic_obj = SUPER::new_from_spdx_expression($arg);
62 46         159 };
63              
64 46 50       515 return $lic_obj if $lic_obj;
65              
66 46         69 my $short = $arg->{short_name};
67 46         115 $short =~ s/-(only|or-later)$//;
68 46         90 $short =~ s/\+$//;
69              
70 46         61 my $subclass = $short;
71 46         150 $subclass =~ s/[\-.]/_/g;
72              
73 46   66     148 my $info = $more_short_names{$short} || "Software::License::$subclass";
74 46         72 my $lic_file = my $lic_class = $info;
75 46         132 $lic_file =~ s!::!/!g;
76             try {
77             ## no critic (Modules::RequireBarewordIncludes)
78 46     46   3483 require "$lic_file.pm";
79             } catch {
80 1     1   33 Carp::croak "Unknow license with short name $short ($_)";
81 46         248 } ;
82 45         504 delete $arg->{short_name};
83 45         326 $lic_obj = $lic_class->new( { %$arg } );
84              
85 45         280 return $lic_obj;
86             }
87              
88             sub new_license_with_summary {
89 0     0 0 0 carp "new_license_with_summary is deprecated. Please use new_from_short_name";
90 0         0 goto & new_from_short_name;
91             }
92              
93             sub new_from_short_name {
94 46     46 1 26384 my ( $class, $arg ) = @_;
95             croak "no license short name specified"
96 46 50       110 unless defined $arg->{short_name};
97              
98 46         67 my $short = $arg->{short_name};
99              
100 46   100     136 my $info = $more_short_names{$short} || '';
101 46 100       200 my $or_later = $short =~ /(\+|-or-later)$/ ? 1 : 0;
102 46         103 my $lic = $class->_create_license($arg);
103              
104 45         163 my $xlic = Software::LicenseMoreUtils::LicenseWithSummary->new({
105             license => $lic,
106             or_later => $or_later
107             });
108 45         117 return $xlic;
109             }
110              
111             1;
112              
113             __END__