/usr/share/perl5/Module/CPANTS/Kwalitee/License.pm is in libmodule-cpants-analyse-perl 0.95-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | package Module::CPANTS::Kwalitee::License;
use warnings;
use strict;
use File::Spec::Functions qw(catfile);
use Software::LicenseUtils;
our $VERSION = '0.95';
$VERSION = eval $VERSION; ## no critic
sub order { 100 }
##################################################################
# Analyse
##################################################################
sub analyse {
my $class=shift;
my $me=shift;
my $distdir=$me->distdir;
# check META.yml
my $yaml=$me->d->{meta_yml};
$me->d->{license} = '';
if ($yaml) {
if ($yaml->{license} and $yaml->{license} ne 'unknown') {
$me->d->{license_from_yaml} = $yaml->{license};
$me->d->{license} = $yaml->{license}.' defined in META.yml';
}
}
# use "files_array" to exclude files listed in "no_index".
my $files = $me->d->{files_array} || [];
# check if there's a LICEN[CS]E file
if (my ($file) = grep {$_ =~ /^(?:LICEN[CS]E|COPYING)$/} @$files) {
$me->d->{license} .= " defined in $file";
$me->d->{external_license_file}=$file;
}
# check pod
my %licenses;
foreach my $file (grep { /\.p(m|od|l)$/ } sort @$files ) {
my $path = catfile($distdir, $file);
next unless -r $path; # skip if not readable
open my $fh, '<', $path or next;
my $in_pod = 0;
my $pod = '';
my $pod_head = '';
my @possible_licenses;
my @unknown_license_texts;
while(<$fh>) {
if (/^=head\d\s+.*\b(?i:LICEN[CS]E|LICEN[CS]ING|COPYRIGHT|LEGAL)\b/) {
$me->d->{license_in_pod} = 1;
$me->d->{license} ||= "defined in POD ($file)";
if ($in_pod) {
my @guessed = Software::LicenseUtils->guess_license_from_pod("=head1 LICENSE\n$pod\n\n=cut\n");
if (@guessed) {
push @possible_licenses, @guessed;
} else {
push @unknown_license_texts, "$pod_head$pod";
}
}
$in_pod = 1;
$pod_head = $_;
$pod = '';
}
elsif (/^=(?:head\d\s+|cut)\b/) {
if ($in_pod) {
my @guessed = Software::LicenseUtils->guess_license_from_pod("=head1 LICENSE\n$pod\n\n=cut\n");
if (@guessed) {
push @possible_licenses, @guessed;
} else {
push @unknown_license_texts, "$pod_head$pod";
}
}
$in_pod = 0;
$pod = '';
}
elsif ($in_pod) {
$pod .= $_;
}
}
if ($pod) {
my @guessed = Software::LicenseUtils->guess_license_from_pod("=head1 LICENSE\n$pod\n\n=cut\n");
if (@guessed) {
push @possible_licenses, @guessed;
} else {
push @unknown_license_texts, "$pod_head$pod";
}
}
if (@possible_licenses) {
@possible_licenses = map { s/^Software::License:://; $_ } @possible_licenses;
push @{$licenses{$_} ||= []}, $file for @possible_licenses;
$me->d->{files_hash}{$file}{license} = join ',', @possible_licenses;
} else {
$me->d->{unknown_license_texts}{$file} = join "\n", @unknown_license_texts if @unknown_license_texts;
}
}
if (%licenses) {
$me->d->{licenses} = \%licenses;
my @possible_licenses = keys %licenses;
if (@possible_licenses == 1) {
my ($type) = @possible_licenses;
$me->d->{license_type} = $type;
$me->d->{license_file} = join ',', @{$licenses{$type}};
}
}
return;
}
##################################################################
# Kwalitee Indicators
##################################################################
sub kwalitee_indicators{
return [
{
name=>'meta_yml_has_license',
error=>q{This distribution does not have a license defined in META.yml.},
remedy=>q{Define the license if you are using in Build.PL. If you are using MakeMaker (Makefile.PL) you should upgrade to ExtUtils::MakeMaker version 6.31.},
is_extra=>1,
code=>sub {
my $d=shift;
my $yaml=$d->{meta_yml};
($yaml->{license} and $yaml->{license} ne 'unknown') ? 1 : 0 },
details=>sub {
my $d = shift;
my $yaml = $d->{meta_yml};
return "No META.yml." unless $yaml;
return "No license was found in META.yml." unless $yaml->{license};
return "Unknown license was found in META.yml.";
},
},
{
name=>'has_human_readable_license',
error=>q{This distribution does not have a license defined in the documentation or in a file called LICENSE},
remedy=>q{Add a section called "LICENSE" to the documentation, or add a file named LICENSE to the distribution.},
code=>sub {
my $d = shift;
return $d->{external_license_file} || $d->{license_in_pod} ? 1 : 0;
},
details=>sub {
my $d = shift;
return "Neither LICENSE file nor LICENSE section in pod was found.";
},
},
{
name=>'has_separate_license_file',
error=>q{This distribution does not have a LICENSE or LICENCE file in its root directory.},
remedy=>q{This is not a critical issue. Currently mainly informative for the CPANTS authors. It might be removed later.},
is_experimental=>1,
code=>sub { shift->{external_license_file} ? 1 : 0 },
details=>sub {
my $d = shift;
return "LICENSE file was found.";
},
},
# {
# name=>'has_known_license_in_external_license_file',
# error=>q{This distribution has a LICENSE or LICENCE file in its root directory but the license in it was not recognized by CPANTS.},
# remedy=>q{Either CPANTS needs to be fixed or your LICENSE file.},
# is_experimental=>1,
# code=>sub {
# my $d = shift;
# return 1 if not $d->{external_license_file};
# return $d->{license_from_external_license_file} ? 1 : 0;
# },
# },
{
name=>'has_license_in_source_file',
error=>q{Does not have license information in any of its source files},
remedy=>q{Add =head1 LICENSE and the text of the license to the main module in your code.},
code=>sub {
my $d = shift;
return $d->{license_in_pod} ? 1 : 0;
},
details=>sub {
my $d = shift;
return "LICENSE section was not found in the pod.";
},
},
{
name=>'has_known_license_in_source_file',
error=>q{Does not have license information in any of its source files, or the information is not recognized by Software::License},
remedy=>q{Add =head1 LICENSE and/or the proper text of the well-known license to the main module in your code.},
is_extra => 1,
code=>sub {
my $d = shift;
return 0 unless $d->{license_in_pod};
my @files_with_licenses = grep {$d->{files_hash}{$_}{license}} keys %{$d->{files_hash}};
return @files_with_licenses ? 1 : 0;
},
details=>sub {
my $d = shift;
return "LICENSE section was not found in the pod, or the license information was not recognized by Software::License.";
},
},
];
}
q{Favourite record of the moment:
Lili Allen - Allright, still};
__END__
=encoding UTF-8
=head1 NAME
Module::CPANTS::Kwalitee::License - Checks if there is a license
=head1 SYNOPSIS
Checks if the distribution specifies a license.
=head1 DESCRIPTION
=head2 Methods
=head3 order
Defines the order in which Kwalitee tests should be run.
Returns C<100>.
=head3 analyse
C<MCK::License> checks if there's a C<license> field C<META.yml>. Additionally, it looks for a file called LICENSE and a POD section named LICENSE
=head3 kwalitee_indicators
Returns the Kwalitee Indicators datastructure.
=over
=item * meta_yml_has_license
=item * has_known_license_in_source_file
=item * has_license_in_source_file
=item * has_human_readable_license
=item * has_separate_license_file
=back
=head2 License information
Places where the license information is taken from:
Has a LICENSE file file_license 1|0
Content of LICENSE file matches License X from Software::License
License in META.yml
License in META.yml matches one of the known licenses
License in source files recognized by Software::LicenseUtils
For each file keep where is was it recognized.
Has license or copyright entry in pod (that might not be recognized by Software::LicenseUtils)
# has_license
=head1 SEE ALSO
L<Module::CPANTS::Analyse>
=head1 AUTHOR
L<Thomas Klausner|https://metacpan.org/author/domm>
and L<Gábor Szabó|https://metacpan.org/author/szabgab>
=head1 COPYRIGHT AND LICENSE
Copyright © 2003–2009 L<Thomas Klausner|https://metacpan.org/author/domm>
Copyright © 2006–2008 L<Gábor Szabó|https://metacpan.org/author/szabgab>
You may use and distribute this module according to the same terms
that Perl is distributed under.
|