| 1 | package CPANPLUS::Dist::Debora::License; | ||||||||||||
| 2 | |||||||||||||
| 3 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||
| 4 | |||||||||||||
| 5 | 8 | ▶ | use 5.016; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 8 | our $VERSION = '0.019'; | |||||||||||
| 10 | |||||||||||||
| 11 | 8 | ▶ | use parent qw(Software::License); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 8 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 8 | ▶ | use Scalar::Util qw(weaken); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 8 | ▶ | use Text::Wrap qw(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | 8 | ▶ | use CPANPLUS::Dist::Debora::Util qw(slurp_utf8); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | # Common modules whose license might not be guessed. | ||||||||||||
| 20 | 8 | my %LICENSE_NAME_FOR = ( | |||||||||||
| 21 | 'Coro' => '(Artistic-1.0-Perl OR GPL-1.0-or-later) ' | ||||||||||||
| 22 | . 'AND (BSD-2-Clause OR GPL-2.0-or-later)', | ||||||||||||
| 23 | 'Crypt-Blowfish' => 'BSD-4-Clause', | ||||||||||||
| 24 | 'Data-Hexdumper' => 'Artistic-1.0-Perl OR GPL-2.0-or-later', | ||||||||||||
| 25 | 'EV' => '(Artistic-1.0-Perl OR GPL-1.0-or-later) ' | ||||||||||||
| 26 | . 'AND (BSD-2-Clause OR GPL-2.0-or-later)', | ||||||||||||
| 27 | 'Exporter-Tidy' => 'SUSE-Permissive ' | ||||||||||||
| 28 | . 'OR GPL-2.0-or-later OR LGPL-2.1-or-later OR MPL-2.0', | ||||||||||||
| 29 | 'FCGI' => 'BSD-2-Clause', | ||||||||||||
| 30 | 'Net-Patricia' => 'GPL-2.0-or-later AND BSD-2-Clause', | ||||||||||||
| 31 | 'Time-ParseDate' => 'SUSE-Permissive', | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 35 | 1 | my ($class, $attrs) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 1 | my $package = $attrs->{package}; | |||||||||||
| 38 | 1 | delete $attrs->{package}; | |||||||||||
| 39 | |||||||||||||
| 40 | 1 | my $self = $class->SUPER::new($attrs); | |||||||||||
| 41 | |||||||||||||
| 42 | 1 | $self->{package} = $package; | |||||||||||
| 43 | 1 | weaken $self->{package}; | |||||||||||
| 44 | |||||||||||||
| 45 | 1 | return $self; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 1 | ▶ | sub name { | ||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 49 | 1 | my $self = shift; | |||||||||||
| 50 | |||||||||||||
| 51 | 1 | return 'Unknown license'; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 1 | ▶ | sub url { | ||||||||||
|
Subroutine
url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 55 | 1 | my $self = shift; | |||||||||||
| 56 | |||||||||||||
| 57 | 1 | return; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 1 | ▶ | sub meta_name { | ||||||||||
|
Subroutine
meta_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 61 | 1 | my $self = shift; | |||||||||||
| 62 | |||||||||||||
| 63 | 1 | return 'restrictive'; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | ▶ | sub meta2_name { | ||||||||||
|
Subroutine
meta2_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 67 | 1 | my $self = shift; | |||||||||||
| 68 | |||||||||||||
| 69 | 1 | return 'restricted'; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 1 | ▶ | sub spdx_expression { | ||||||||||
|
Subroutine
spdx_expression: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 73 | 1 | my $self = shift; | |||||||||||
| 74 | |||||||||||||
| 75 | 1 | my $package = $self->{package}; | |||||||||||
| 76 | 1 | my $dist_name = $package->dist_name; | |||||||||||
| 77 | |||||||||||||
| 78 | 1 | ▶ | return $LICENSE_NAME_FOR{$dist_name} // 'Unknown'; | ||||||||||
|
Condition50%1/2
$LICENSE_NAME_FOR{$dist_name} // "Unknown"
MC/DC0%0/1
$LICENSE_NAME_FOR{$dist_name} // "Unknown"
$LICENSE_NAME_FOR{$dist_name}
Truth table50%1/2
A
A= $LICENSE_NAME_FOR{$dist_name}
| |||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 1 | ▶ | sub license { | ||||||||||
|
Subroutine
license: called CC=8 SCAR=26.2
Pod
documented
| |||||||||||||
| 82 | 1 | my $self = shift; | |||||||||||
| 83 | |||||||||||||
| 84 | 1 | my $package = $self->{package}; | |||||||||||
| 85 | 1 | my $builddir = $package->builddir; | |||||||||||
| 86 | |||||||||||||
| 87 | 1 | my $text = q{}; | |||||||||||
| 88 | |||||||||||||
| 89 | # Read the license files. | ||||||||||||
| 90 | 1 | my @license_files = @{$package->files_by_type('license')}; | |||||||||||
| 91 | 1 | for my $filename (@license_files) { | |||||||||||
| 92 | 1 | my $buf = eval { slurp_utf8(catfile($builddir, $filename)) }; | |||||||||||
| 93 | 1 | ▶ | if ($buf) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 1 | $buf =~ s{\A \v+}{}xms; # Remove leading newlines. | |||||||||||
| 95 | 1 | $buf =~ s{\v+ \z}{}xms; # Remove trailing newlines. | |||||||||||
| 96 | |||||||||||||
| 97 | 1 | ▶ | if ($text) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 0 | $text .= "\n\n"; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 1 | ▶ | if (@license_files > 1) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | 0 | $text .= "-- $filename file --\n\n"; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 1 | $text .= $buf; | |||||||||||
| 106 | } | ||||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | # Is there a LICENSE section in the Pod document? | ||||||||||||
| 110 | 1 | ▶ | if (!$text) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | my $pod = $package->_pod; | |||||||||||
| 112 | 0 | ▶ | if ($pod) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 113 | 0 | my $section = $pod->section(q{1}, qr{LICEN[CS]E}xmsi); | |||||||||||
| 114 | 0 | ▶ | if ($section) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | ## no critic (Variables::ProhibitPackageVars) | ||||||||||||
| 116 | # Remove headings. | ||||||||||||
| 117 | 0 | $section =~ s{^ =head\d \h (\V+) \v+}{}xmsg; | |||||||||||
| 118 | 0 | local $Text::Wrap::unexpand = 0; | |||||||||||
| 119 | 0 | $text = Text::Wrap::wrap(q{}, q{}, $section); | |||||||||||
| 120 | } | ||||||||||||
| 121 | } | ||||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | 1 | return $text; | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 8 | 1; | |||||||||||
| 128 | |||||||||||||
| 129 | ## no critic (Documentation::RequirePodAtEnd) | ||||||||||||
| 130 | |||||||||||||
| 131 | =pod | ||||||||||||
| 132 | |||||||||||||
| 133 | =encoding UTF-8 | ||||||||||||
| 134 | |||||||||||||
| 135 | =head1 NAME | ||||||||||||
| 136 | |||||||||||||
| 137 | CPANPLUS::Dist::Debora::License - Read license files | ||||||||||||
| 138 | |||||||||||||
| 139 | =head1 VERSION | ||||||||||||
| 140 | |||||||||||||
| 141 | version 0.019 | ||||||||||||
| 142 | |||||||||||||
| 143 | =head1 SYNOPSIS | ||||||||||||
| 144 | |||||||||||||
| 145 | use CPANPLUS::Dist::Debora::License; | ||||||||||||
| 146 | |||||||||||||
| 147 | my $license = CPANPLUS::Dist::Debora::License->new({ | ||||||||||||
| 148 | package => $package, | ||||||||||||
| 149 | holder => $holder, | ||||||||||||
| 150 | year => $year, | ||||||||||||
| 151 | }); | ||||||||||||
| 152 | |||||||||||||
| 153 | print $license->license; | ||||||||||||
| 154 | |||||||||||||
| 155 | =head1 DESCRIPTION | ||||||||||||
| 156 | |||||||||||||
| 157 | This L<Software::License> subclass reads license texts from files and Pod | ||||||||||||
| 158 | documents. | ||||||||||||
| 159 | |||||||||||||
| 160 | =head1 SUBROUTINES/METHODS | ||||||||||||
| 161 | |||||||||||||
| 162 | =head2 new | ||||||||||||
| 163 | |||||||||||||
| 164 | my $license = CPANPLUS::Dist::Debora::License->new({ | ||||||||||||
| 165 | package => $package, | ||||||||||||
| 166 | holder => $holder, | ||||||||||||
| 167 | }); | ||||||||||||
| 168 | |||||||||||||
| 169 | Creates a new object. The L<CPANPLUS::Dist::Debora::Package> object parameter | ||||||||||||
| 170 | and the copyright holder are mandatory. | ||||||||||||
| 171 | |||||||||||||
| 172 | =head2 name | ||||||||||||
| 173 | |||||||||||||
| 174 | Returns "Unknown license". | ||||||||||||
| 175 | |||||||||||||
| 176 | =head2 url | ||||||||||||
| 177 | |||||||||||||
| 178 | Returns the undefined value. | ||||||||||||
| 179 | |||||||||||||
| 180 | =head2 meta_name | ||||||||||||
| 181 | |||||||||||||
| 182 | Returns "restrictive". | ||||||||||||
| 183 | |||||||||||||
| 184 | =head2 meta2_name | ||||||||||||
| 185 | |||||||||||||
| 186 | Returns "restricted". | ||||||||||||
| 187 | |||||||||||||
| 188 | =head2 spdx_expression | ||||||||||||
| 189 | |||||||||||||
| 190 | Returns a short license name or "Unknown". | ||||||||||||
| 191 | |||||||||||||
| 192 | =head2 license | ||||||||||||
| 193 | |||||||||||||
| 194 | Returns the license text or the empty string. | ||||||||||||
| 195 | |||||||||||||
| 196 | =head1 DIAGNOSTICS | ||||||||||||
| 197 | |||||||||||||
| 198 | None. | ||||||||||||
| 199 | |||||||||||||
| 200 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||
| 201 | |||||||||||||
| 202 | None. | ||||||||||||
| 203 | |||||||||||||
| 204 | =head1 DEPENDENCIES | ||||||||||||
| 205 | |||||||||||||
| 206 | Requires the module L<Software::License> from CPAN. | ||||||||||||
| 207 | |||||||||||||
| 208 | =head1 INCOMPATIBILITIES | ||||||||||||
| 209 | |||||||||||||
| 210 | None. | ||||||||||||
| 211 | |||||||||||||
| 212 | =head1 BUGS AND LIMITATIONS | ||||||||||||
| 213 | |||||||||||||
| 214 | None known. | ||||||||||||
| 215 | |||||||||||||
| 216 | =head1 AUTHOR | ||||||||||||
| 217 | |||||||||||||
| 218 | Andreas Vögele E<lt>voegelas@cpan.orgE<gt> | ||||||||||||
| 219 | |||||||||||||
| 220 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 221 | |||||||||||||
| 222 | Copyright (C) 2026 Andreas Vögele | ||||||||||||
| 223 | |||||||||||||
| 224 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||
| 225 | the same terms as Perl itself. | ||||||||||||
| 226 | |||||||||||||
| 227 | =cut | ||||||||||||
| 228 | |||||||||||||
| 229 | __DATA__ | ||||||||||||