Skip to content

Commit 889d4fc

Browse files
committed
fix for issues Perl-Toolchain-Gang#27
honors meta 1.4 Oslo no more ambigious resources.license: compatable with Software::License data dies on unknown meta_name plus some tests to support above
1 parent bc6ac33 commit 889d4fc

21 files changed

+1201
-62
lines changed

lib/Module/Install.pod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ version scanning tools.
202202

203203
The C<license> command specifies the license for the distribution.
204204

205-
Most often this value will be C<'perl'>, meaning I<"the same as for Perl
206-
itself">. Other allowed values include C<'gpl'>, C<'lgpl'>, C<'bsd'>,
207-
C<'MIT'>, and C<'artistic'>.
205+
Most often this value will be C<'perl'>, meaning I<"the same terms as the perl 5 programming language system itself">. Other allowed values include C<'apache'>, C<'artistic'>, C<'artistic_2'>, C<'bsd'>, C<'gpl'>, C<'lgpl'>, C<'mit'> and C<'mozilla'>.
208206

209207
This value is always considered a summary, and it is normal for authors
210208
to include a F<LICENSE> file in the distribution, containing the full

lib/Module/Install/Metadata.pm

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -452,55 +452,42 @@ sub author_from {
452452

453453
#Stolen from M::B
454454
my %license_urls = (
455-
open_source => undef,
456-
unrestricted => undef,
457-
restrictive => undef,
458-
unknown => undef,
459-
460-
## from Software-License - should we be using S-L instead ?
461-
# duplicates commeted out, see hack above ^^
462-
# open_source => 'http://www.gnu.org/licenses/agpl-3.0.txt',
463-
# apache => 'http://www.apache.org/licenses/LICENSE-1.1',
464-
apache => 'http://www.apache.org/licenses/LICENSE-2.0.txt',
455+
456+
#from MI v1.06
457+
apache => undef,
465458
artistic => 'http://www.perlfoundation.org/artistic_license_1_0',
466459
artistic_2 => 'http://www.perlfoundation.org/artistic_license_2_0',
467460
bsd => 'http://opensource.org/licenses/BSD-3-Clause',
468-
# unrestricted => 'http://creativecommons.org/publicdomain/zero/1.0/',
469-
# open_source => 'http://www.freebsd.org/copyright/freebsd-license.html',
470-
# open_source => 'http://www.gnu.org/licenses/fdl-1.2.txt',
471-
# open_source => 'http://www.gnu.org/licenses/fdl-1.3.txt',
472-
# gpl => 'http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt',
473-
# gpl => 'http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt',
474-
gpl => 'http://www.gnu.org/licenses/gpl-3.0.txt',
475-
# lgpl => 'http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt',
476-
lgpl => 'http://www.gnu.org/licenses/lgpl-3.0.txt',
461+
gpl => undef,
462+
lgpl => undef,
477463
mit => 'http://www.opensource.org/licenses/mit-license.php',
478-
# mozilla => 'http://www.mozilla.org/MPL/MPL-1.0.txt',
479-
# mozilla => 'http://www.mozilla.org/MPL/MPL-1.1.txt',
480-
mozilla => 'http://www.mozilla.org/MPL/2.0/index.txt',
481-
# restrictive => '',
482-
# open_source => 'http://www.openssl.org/source/license.html',
464+
mozilla => undef,
465+
open_source => undef,
483466
perl => 'http://dev.perl.org/licenses/',
484-
# open_source => 'http://www.opensource.org/licenses/postgresql',
485-
# open_source => 'http://trolltech.com/products/qt/licenses/licensing/qpl',
486-
# unrestricted => 'http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html',
487-
# open_source => 'http://www.openoffice.org/licenses/sissl_license.html',
488-
# open_source => 'http://www.zlib.net/zlib_license.html',
467+
unrestricted => undef,
468+
restrictive => undef,
469+
# unknown => undef,
489470
);
490471

472+
491473
sub license {
492474
my $self = shift;
493475
return $self->{values}->{license} unless @_;
494476
my $license = shift or die(
495477
'Did not provide a value to license()'
496478
);
497479
$license = __extract_license($license) || lc $license;
480+
481+
# test for valid meta license name
482+
_valid_license($license);
483+
498484
$self->{values}->{license} = $license;
499485

500486
# Automatically fill in license URLs
501487
if ( $license_urls{$license} ) {
502488
$self->resources( license => $license_urls{$license} );
503-
}
489+
return 1;
490+
}
504491

505492
return 1;
506493
}
@@ -524,14 +511,6 @@ sub _extract_license {
524511
sub __extract_license {
525512
my $license_text = shift or return;
526513
my @phrases = (
527-
'(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
528-
'(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
529-
530-
# the following are relied on by the test system even if they are wrong :(
531-
'(?:Free)?BSD license' => 'bsd', 1,
532-
'Artistic license 2\.0' => 'artistic_2', 1,
533-
'LGPL' => 'lgpl', 1,
534-
'MIT' => 'mit', 1,
535514

536515
## from Software-License
537516
'The GNU Affero General Public License, Version 3, November 2007' => 'open_source', 1,
@@ -540,7 +519,7 @@ sub __extract_license {
540519
'The Artistic License 1.0' => 'artistic', 1,
541520
'The Artistic License 2.0 (GPL Compatible)' => 'artistic_2', 1,
542521
'The (three-clause) BSD License' => 'bsd', 1,
543-
'CC0 License' => 'unrestricted', 1,
522+
'CC0 License' => 'unrestricted', 1,
544523
'The (two-clause) FreeBSD License' => 'open_source', 1,
545524
'GNU Free Documentation License v1.2' => 'open_source', 1,
546525
'GNU Free Documentation License v1.3' => 'open_source', 1,
@@ -565,7 +544,10 @@ sub __extract_license {
565544

566545
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
567546
$pattern =~ s#\s+#\\s+#gs;
568-
if ( $license_text =~ /\b$pattern\b/i ) {
547+
$pattern =~ s#\(#\\(\\s*#gs;
548+
$pattern =~ s#\)#\\)\\s*#gs;
549+
550+
if ( $license_text =~ m/\b$pattern\b/i ) {
569551
return $license;
570552
}
571553
}
@@ -582,6 +564,31 @@ sub license_from {
582564
}
583565
}
584566

567+
sub _valid_license {
568+
my $license = shift;
569+
570+
my %meta_licenses = (
571+
apache => 1,
572+
artistic => 1,
573+
artistic_2 => 1,
574+
bsd => 1,
575+
gpl => 1,
576+
lgpl => 1,
577+
mit => 1,
578+
mozilla => 1,
579+
open_source => 1,
580+
perl => 1,
581+
unrestricted => 1,
582+
restrictive => 1,
583+
);
584+
585+
if (not $meta_licenses{$license}) {
586+
die("ERROR: license is not a recognised meta name - $license\n");
587+
return 0;
588+
}
589+
return 1,;
590+
}
591+
585592
sub _extract_bugtracker {
586593
my @links = $_[0] =~ m#L<(
587594
https?\Q://rt.cpan.org/\E[^>]+|

t/09_read.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Foo Bar
3232
=head1 COPYRIGHT
3333
3434
This program is free software; you can redistribute it and/or
35-
modify it under the same terms as Perl itself.
35+
modify it under the same terms as the perl 5 programming language system itself.
3636
3737
END_POD
3838

t/10_test.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ no_index 'directory' => qw{ t xt share inc };
2626
install_share 'eg';
2727
keywords 'kw1','kw 2';
2828
keywords 'kw3';
29-
license 'apache';
29+
license 'artistic_2';
3030
3131
WriteAll;
3232
END_DSL
@@ -73,8 +73,8 @@ END_TEST
7373
"no_index: @{ $meta->{no_index}->{directory} }"
7474
);
7575

76-
is($meta->{license},'apache','license');
77-
is($meta->{resources}->{license},'http://www.apache.org/licenses/LICENSE-2.0.txt','license URL');
76+
is($meta->{license},'artistic_2','license');
77+
is($meta->{resources}->{license},'http://www.perlfoundation.org/artistic_license_2_0','license URL');
7878

7979
my $makefile = makefile();
8080
ok( -f $makefile, 'Makefile created' );

t/11_extraction.t

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/perl
1+
#!perl
22

33
use strict;
44
BEGIN {
55
$| = 1;
66
$^W = 1;
77
}
88

9-
use Test::More tests => 16;
9+
use Test::More tests => 26;
1010

1111
require_ok( 'Module::Install::Metadata' );
1212

@@ -80,7 +80,7 @@ SCOPE: {
8080

8181

8282
SCOPE: {
83-
my $l=Module::Install::Metadata::_extract_license("=head1 Copyright\nunder the same terms as the perl programming language\n=cut\n");
83+
my $l=Module::Install::Metadata::_extract_license("=head1 Copyright\nunder the same terms as the perl 5 programming language system itself\n=cut\n");
8484
is($l, 'perl', 'Perl license detected',
8585
);
8686
}
@@ -89,7 +89,7 @@ SCOPE: {
8989
my $text="=head1 LICENSE
9090
9191
This is free software, you may use it and distribute it under
92-
the same terms as Perl itself.
92+
the same terms as the perl 5 programming language system itself.
9393
9494
=head1 SEE ALSO
9595
@@ -105,7 +105,7 @@ test
105105
SCOPE: {
106106
my $text="=head1 COPYRIGHTS
107107
108-
This module is distributed under the same terms as Perl itself.
108+
This module is distributed under the same terms as the perl 5 programming language system itself.
109109
110110
=cut
111111
";
@@ -115,8 +115,14 @@ This module is distributed under the same terms as Perl itself.
115115
}
116116

117117
SCOPE: {
118-
my $l=Module::Install::Metadata::_extract_license("=head1 COPYRIGHT\nAs LGPL license\n=cut\n");
119-
is($l, 'lgpl', 'LGPL detected',
118+
my $l=Module::Install::Metadata::_extract_license("=head1 COPYRIGHT\nThe GNU Lesser General Public License, Version 2.1, February 1999\n=cut\n");
119+
is($l, 'lgpl', 'LGPL license detected',
120+
);
121+
}
122+
123+
SCOPE: {
124+
my $l=Module::Install::Metadata::_extract_license("=head1 COPYRIGHT\nThe GNU Lesser General Public License, Version 3, June 2007\n=cut\n");
125+
is($l, 'lgpl', 'LGPL license detected',
120126
);
121127
}
122128

@@ -125,7 +131,7 @@ SCOPE: {
125131
=head1 COPYRIGHT AND LICENCE
126132
127133
... is free software; you can redistribute it and/or modify it under
128-
the terms of Perl itself, that is to say, under the terms of either:
134+
the same terms as the perl 5 programming language system itself, that is to say, under the terms of either:
129135
130136
=over 4
131137
@@ -147,22 +153,75 @@ EOT
147153
);
148154
}
149155

156+
SCOPE: {
157+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENSE\nThe Artistic License 1.0\n=cut\n");
158+
is($l, 'artistic', 'Artistic license detected',
159+
);
160+
}
161+
150162

151163
SCOPE: {
152164
my $text=<<'EOT';
153165
=head1 COPYRIGHT AND LICENCE
154166
155167
Copyright (C) 2010
156168
157-
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://opensource.org/licenses/artistic-license-2.0.php.
169+
This library is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0 (GPL Compatible) For details, see the full text of the license at http://opensource.org/licenses/artistic-license-2.0.php.
158170
159171
=cut
160172
EOT
161173
my $l=Module::Install::Metadata::_extract_license($text);
162-
is($l, 'artistic_2', 'Artistic 2.0 license detected',
174+
is($l, 'artistic_2', 'Artistic license detected',
175+
);
176+
}
177+
178+
SCOPE: {
179+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENCE\nThe (three-clause) BSD License\n=cut\n");
180+
is($l, 'bsd', 'BSD license detected',
181+
);
182+
}
183+
184+
SCOPE: {
185+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENCE\nThe GNU General Public License, Version 1, February 1989\n=cut\n");
186+
is($l, 'gpl', 'GNU license detected',
187+
);
188+
}
189+
190+
SCOPE: {
191+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENsE\nThe GNU General Public License, Version 2, June 1991\n=cut\n");
192+
is($l, 'gpl', 'GNU license detected',
163193
);
164194
}
165195

196+
SCOPE: {
197+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENCE\nThe GNU General Public License, Version 3, June 2007\n=cut\n");
198+
is($l, 'gpl', 'GNU license detected',
199+
);
200+
}
201+
202+
SCOPE: {
203+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENCE\nThe MIT (X11) License\n=cut\n");
204+
is($l, 'mit', 'MIT license detected',
205+
);
206+
}
207+
208+
SCOPE: {
209+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENCE\nThe Mozilla Public License 1.0\n=cut\n");
210+
is($l, 'mozilla', 'Mozilla license detected',
211+
);
212+
}
213+
214+
SCOPE: {
215+
my $l=Module::Install::Metadata::_extract_license("=head1 LICENSE\nThe Mozilla Public License 1.1\n=cut\n");
216+
is($l, 'mozilla', 'Mozilla license detected',
217+
);
218+
}
219+
220+
SCOPE: {
221+
my $l=Module::Install::Metadata::_extract_license("=head1 Copyright\nMozilla Public License Version 2.0\n=cut\n");
222+
is($l, 'mozilla', 'Mozilla license detected',
223+
);
224+
}
166225

167226

168227
SCOPE: {

t/24_multiple_license_blocks.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BEGIN {
99
use Test::More tests => 3;
1010
use Module::Install::Metadata;
1111

12+
1213
my %p = _setup();
1314

1415
for (
@@ -67,9 +68,8 @@ POD
6768
=head1 LICENCE
6869
6970
This module is free software; you can redistribute it and/or modify it
70-
under the
71-
same terms as Perl itself, i.e. under the terms of either the GNU
72-
General Public
71+
under the same terms as the perl 5 programming language system itself,
72+
i.e. under the terms of either the GNU General Public
7373
License or the Artistic License, as specified in the F<LICENCE> file.
7474
7575
POD

t/27_build_requires_and_include.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/perl
1+
#!perl
22

33
use strict;
44
BEGIN {

0 commit comments

Comments
 (0)