/usr/share/perl5/App/Licensecheck.pm is in licensecheck 3.0.29-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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | package App::Licensecheck;
use utf8;
use strictures 2;
use autodie;
use version;
use Path::Iterator::Rule;
use Path::Tiny;
use Fcntl qw/:seek/;
use Encode;
use Regexp::Pattern::License;
use String::Copyright 0.003 {
format => sub { join ' ', $_->[0] || (), $_->[1] || () }
};
use String::Copyright 0.003 {
threshold_after => 5,
format => sub { join ' ', $_->[0] || (), $_->[1] || () },
},
'copyright' => { -as => 'copyright_optimistic' };
use Moo;
use experimental "switch";
use namespace::clean;
=head1 NAME
App::Licensecheck - functions for a simple license checker for source files
=head1 VERSION
Version v3.0.29
=cut
our $VERSION = version->declare("v3.0.29");
=head1 SYNOPSIS
use App::Licensecheck;
my $app = App::Licensecheck->new;
$app->lines(0); # Speedup parsing - our file is not huge
printf "License: %s\nCopyright: %s\n", $app->parse( 'some-file' );
=head1 DESCRIPTION
L<App::Licensecheck> is the core of L<licensecheck> script
to check for licenses of source files.
See the script for casual usage.
=cut
my $under_terms_of
= qr/(?:(?:Licensed|released) under|(?:according to|under) the (?:conditions|terms) of)/i;
my $any_of = qr/(?:any|one or more) of the following/i;
my $or_option_re = qr/(?:and|or)(?: ?\(?at your (?:choice|option)\)?)?/i;
my $default_check_regex = q!
/[\w-]+$ # executable scripts or README like file
|\.( # search for file suffix
c(c|pp|xx)? # c and c++
|h(h|pp|xx)? # header files for c and c++
|S
|css|less # HTML css and similar
|f(77|90)?
|go
|groovy
|lisp
|scala
|clj
|p(l|m)?6?|t|xs|pod6? # perl5 or perl6
|sh
|php
|py(|x)
|rb
|java
|js
|vala
|el
|sc(i|e)
|cs
|pas
|inc
|dtd|xsl
|mod
|m
|md|markdown
|tex
|mli?
|(c|l)?hs
)$
!;
# From dpkg-source
my $default_ignore_regex = q!
# Ignore general backup files
~$|
# Ignore emacs recovery files
(?:^|/)\.#|
# Ignore vi swap files
(?:^|/)\..*\.swp$|
# Ignore baz-style junk files or directories
(?:^|/),,.*(?:$|/.*$)|
# File-names that should be ignored (never directories)
(?:^|/)(?:DEADJOE|\.cvsignore|\.arch-inventory|\.bzrignore|\.gitignore)$|
# File or directory names that should be ignored
(?:^|/)(?:CVS|RCS|\.pc|\.deps|\{arch\}|\.arch-ids|\.svn|\.hg|_darcs|\.git|
\.shelf|_MTN|\.bzr(?:\.backup|tags)?)(?:$|/.*$)
!;
has check_regex => (
is => 'rw',
lazy => 1,
coerce => sub {
my $value = shift;
return qr/$default_check_regex/x
if $value eq 'common source files';
return $value if ref $value eq 'Regexp';
return qr/$value/;
},
default => sub {qr/$default_check_regex/x},
);
has ignore_regex => (
is => 'rw',
lazy => 1,
coerce => sub {
my $value = shift;
return qr/$default_ignore_regex/x
if $value eq 'some backup and VCS files';
return $value if ref $value eq 'Regexp';
return qr/$value/;
},
default => sub {qr/$default_ignore_regex/x},
);
has recursive => (
is => 'rw',
);
has lines => (
is => 'rw',
default => sub {60},
);
has tail => (
is => 'rw',
default => sub {5000}, # roughly 60 lines of 80 chars
);
has encoding => (
is => 'rw',
coerce => sub {
find_encoding( $_[0] ) unless ref( $_[0] ) eq 'OBJECT';
},
);
has verbose => (
is => 'rw',
);
has skipped => (
is => 'rw',
);
has deb_fmt => (
is => 'rw',
lazy => 1,
default => sub { $_[0]->deb_machine },
);
has deb_machine => (
is => 'rw',
);
sub find
{
my ( $self, @paths ) = @_;
my $check_re = $self->check_regex;
my $ignore_re = $self->ignore_regex;
my $rule = Path::Iterator::Rule->new;
my %options = (
follow_symlinks => 0,
);
$rule->max_depth(1)
unless $self->recursive;
$rule->not( sub {/$ignore_re/} );
$rule->file->nonempty;
if ( @paths >> 1 ) {
if ( $self->skipped ) {
my $skipped = $rule->clone->not( sub {/$check_re/} );
for ( $skipped->all( @paths, \%options ) ) {
warn "skipped file $_\n";
}
}
$rule->and( sub {/$check_re/} );
}
return $rule->all( @paths, \%options );
}
sub parse
{
my $self = shift;
my $file = path(shift);
if ( $self->lines == 0 ) {
return ( $self->parse_file($file) );
}
else {
return ( $self->parse_lines($file) );
}
}
sub parse_file
{
my $self = shift;
my $file = path(shift);
my $content;
given ( $self->encoding ) {
when (undef) { $content = $file->slurp_raw }
when ('utf8') { $content = $file->slurp_utf8 }
default {
$content
= $file->slurp(
{ binmode => sprintf ':encoding(%s)', $self->encoding->name }
)
}
}
print qq(----- $file content -----\n$content----- end content -----\n\n)
if $self->verbose;
my $cleaned_content = clean_comments($content);
return (
$self->parse_license( clean_cruft_and_spaces($cleaned_content) )
|| "UNKNOWN",
copyright( clean_cruft($cleaned_content) ),
);
}
sub parse_lines
{
my $self = shift;
my $file = path(shift);
my $content = '';
my $fh;
my $st = $file->stat;
given ( $self->encoding ) {
when (undef) { $fh = $file->openr_raw }
when ('utf8') { $fh = $file->openr_utf8 }
default {
$fh = $file->openr(
sprintf ':encoding(%s)',
$self->encoding->name
)
}
}
while ( my $line = $fh->getline ) {
last if ( $fh->input_line_number > $self->lines );
$content .= $line;
}
print qq(----- $file header -----\n$content----- end header -----\n\n)
if $self->verbose;
my $cleaned_content = clean_comments($content);
my $license
= $self->parse_license( clean_cruft_and_spaces($cleaned_content) );
my $copyrights = copyright_optimistic( clean_cruft($cleaned_content) );
if ( not $copyrights and $license eq 'UNKNOWN' ) {
my $position = $fh->tell; # See IO::Seekable
my $jump = $st->size - $self->tail;
$jump = $position if $jump < $position;
my $tail = '';
if ( $self->tail and $jump < $st->size ) {
$fh->seek( $jump, SEEK_SET ); # also IO::Seekable
$tail .= join( '', $fh->getlines );
}
print qq(----- $file tail -----\n$tail----- end tail -----\n\n)
if $self->verbose;
my $cleaned_tail = clean_comments($tail);
$copyrights = copyright_optimistic( clean_cruft($cleaned_tail) );
$license
= $self->parse_license( clean_cruft_and_spaces($cleaned_tail) );
}
$fh->close;
return ( $license || "UNKNOWN", $copyrights );
}
sub clean_comments
{
local $_ = shift or return q{};
# Remove generic comments: look for 4 or more lines beginning with
# regular comment pattern and trim it. Fall back to old algorithm
# if no such pattern found.
my @matches = m/^\s*((?:[^a-zA-Z0-9\s]{1,3}|\bdnl\b|\bREM\b))\s\w/mg;
if ( @matches >= 4 ) {
my $comment_re = qr/\s*[\Q$matches[0]\E]{1,3}\s*/;
s/^$comment_re//mg;
}
# Remove other side of "boxed" comments
s/\s*[*#]\s*$//gm;
# Remove Fortran comments
s/^[cC] //gm;
# Remove C / C++ comments
s#(\*/|/[/*])##g;
return $_;
}
sub clean_cruft
{
local $_ = shift or return q{};
# TODO: decode latin1/UTF-8/HTML data instead
s/\xcb\x97|\xe2\x80[\x90-\x95|\xe2\x81\x83|\xe2\x88\x92|\xef\x89\xa3|\xef\xbc\x8d]|[&](?:ndash|mdash|horbar|minus|[#](?:727|820[8-9]|821[0-3]|8259|8722|65123|65293|x727|z201[0-5]|x2043|x2212|xFE63|xFF0D))[;]/-/gm;
s/\x58\xa9|\xc2\xa9|\xe2\x92\x9e|\xe2\x92\xb8|\xe2\x93\x92|\xf0\x9f\x84\x92|\xf0\x9f\x84\xab|\xf0\x9f\x85\x92|[&](?:copy|[#](?:169|9374|9400|9426|127250|127275|127314|x0A9|x249E|x24b8|x24D2|x0F112|x0F12B|x0F152))[;]/©/gm;
# TODO: decode nroff files specifically instead
s/\\//gm; # de-cruft nroff files
return $_;
}
sub clean_cruft_and_spaces
{
local $_ = shift or return q{};
tr/\t\r\n/ /;
# this also removes quotes
tr% A-Za-z.,@;0-9\(\)/-%%cd;
tr/ //s;
return $_;
}
sub licensepatterns
{
my $org = shift;
my %list;
while ( my ( $key, $val ) = each %Regexp::Pattern::License::RE ) {
if ($org) {
$list{name}{$key} = $val->{ 'name.alt.org.' . $org };
$list{caption}{$key} = $val->{ 'caption.alt.org.' . $org };
}
$list{name}{$key} ||= $val->{name} || $key;
$list{caption}{$key} ||= $val->{caption} || $val->{name} || $key;
$list{re}{$key} = $val->{pat};
}
# TODO: use Regexp::Common
$list{re}{version}{'-keep'}
= qr/$list{re}{version_prefix}?($list{re}{version_number})/i;
$list{re}{xgpl}{'-keep'} = qr/(?:the )?(?:GNU )?([AL]?GPL)/i;
return %list;
}
sub parse_license
{
my $self = shift;
my ($licensetext) = @_;
my $gplver = "";
my $extrainfo = "";
my $license = "";
my @spdx_gplver;
# TODO: make naming scheme configurable
my %L = licensepatterns('debian');
# @spdx_license contains identifiers from https://spdx.org/licenses/
# it would be more efficient to store license info only in this
# array and then convert it to legacy formulation, but there are
# corner case (like extrainfo) that would not fit. So the old storage scheme
# is kept with the new (spdx/dep-5) scheme to keep backward compat.
my @spdx_license;
my $spdx_extra;
my $gen_spdx = sub {
my @ret
= @spdx_gplver ? ( map { "$_[0]-$_"; } @spdx_gplver ) : ( $_[0] );
push @ret, $spdx_extra if $spdx_extra;
return @ret;
};
my $gen_license = sub {
my ( $id, $v, $later, $id2, $v2, $later2 ) = @_;
my @spdx;
my $name = $L{name}{$id} || $id;
my $desc = $L{caption}{$id} || $id;
if ($v) {
push @spdx, $later ? "$name-$v+" : "$name-$v";
$v .= ' or later' if ($later);
}
else {
push @spdx, $name;
}
my ( $name2, $desc2 );
if ($id2) {
$name2 = $L{name}{$id2} || $id2;
$desc2 = $L{caption}{$id2} || $id2;
if ($v2) {
push @spdx, $later2 ? "$name2-$v2+" : "$name2-$v2";
$v2 .= ' or later' if ($later2);
}
else {
push @spdx, $name2;
}
}
my $legacy = join(
' ',
$desc,
$v ? "(v$v)" : (),
$desc2 ? "or $desc2" : (),
$v2 ? "(v$v2)" : (),
);
push @spdx_license, join( ' or ', @spdx );
$license = join( ' ', $L{caption}{$legacy} || $legacy, $license );
};
#<<< do not let perltidy touch this (keep long regex on one line)
# version of AGPL/GPL
given ($licensetext) {
when ( /version ($L{re}{version_number})[.,]? (?:\(?only\)?.? )?(?:of $L{re}{gnu}|(as )?published by the Free Software Foundation)/i ) {
$gplver = " (v$1)";
@spdx_gplver = ($1)
}
when ( /$L{re}{gnu}\b[;,] $L{re}{version}{-keep}\b[.,]? /i ) {
$gplver = " (v$1)";
@spdx_gplver = ($1);
}
when ( /either $L{re}{version}{-keep}(?: of the License)?,? $L{re}{version_later_postfix}/ ) {
$gplver = " (v$1 or later)";
@spdx_gplver = ( $1 . '+' );
}
when ( /GPL as published by the Free Software Foundation, version ($L{re}{version_number})/i ) {
$gplver = " (v$1)";
@spdx_gplver = ($1)
}
}
# address in AGPL/GPL/LGPL
given ($licensetext) {
when ( /(?:675 Mass Ave|59 Temple Place|51 Franklin Steet|02139|02111-1307)/i ) {
$extrainfo = " (with incorrect FSF address)$extrainfo";
}
}
# exception for AGPL/GPL/LGPL
given ($licensetext) {
when ( /permission (?:is (also granted|given))? to link (the code of )?this program with (any edition of )?(Qt|the Qt library)/i ) {
$extrainfo = " (with Qt exception)$extrainfo";
$spdx_extra = 'with Qt exception';
}
}
# generated file
given ($licensetext) {
# exclude blurb found in boost license text
when ( /unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor/ ) {
break;
}
when ( /(All changes made in this file will be lost|DO NOT ((?:HAND )?EDIT|delete this file|modify)|edit the original|Generated (automatically|by|from|data|with)|generated.*file|auto[- ]generated)/i ) {
$license = "GENERATED FILE";
}
}
# multi-licensing
given ($licensetext) {
my @multilicenses;
# same sentence
when ( /$under_terms_of $any_of(?:[^.]|\.\S)* $L{re}{lgpl}(?:[,;:]? ?$L{re}{version}{-keep}(?: of the License)?($L{re}{version_later})?)?/i ) {
push @multilicenses, 'lgpl', $1, $2;
continue;
}
when ( /$under_terms_of $any_of(?:[^.]|\.\S)* $L{re}{gpl}(?:[,;:]? ?$L{re}{version}{-keep}(?: of the License)?($L{re}{version_later})?)?/i ) {
push @multilicenses, 'gpl', $1, $2;
continue;
}
$gen_license->( @multilicenses ) if (@multilicenses);
}
# LGPL
given ($licensetext) {
# LGPL, among several
when ( /$under_terms_of $any_of(?:[^.]|\.\S)* $L{re}{lgpl}(?:[,;:]? ?$L{re}{version}{-keep}(?: of the License)?($L{re}{version_later})?)?/i ) {
break; # handled in multi-licensing loop
}
# AFL or LGPL
when ( /either $L{re}{afl}(?:[,;]? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?, or $L{re}{lgpl}(?:[,;]? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
break; # handled in AFL loop
}
# GPL or LGPL
when ( /either $L{re}{gpl}(?:[,;]? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?: \((?:the )?"?GPL"?\))?, or $L{re}{lgpl}/i ) {
break; # handled in GPL loop
}
# LGPL, version first
when ( /$under_terms_of $L{re}{version}{-keep}( $L{re}{version_later_postfix})? of $L{re}{lgpl}/i ) {
$gen_license->( 'lgpl', $1, $2 );
}
# LGPL, dual versions last
when ( /$under_terms_of $L{re}{lgpl}\b[,;:]?(?: either)? ?$L{re}{version}{-keep}(?: of the License)?,? $or_option_re $L{re}{version}{-keep}/i ) {
$license = "LGPL (v$1 or v$2) $license";
push @spdx_license, "LGPL-$1 or LGPL-$2";
}
# LGPL, version last
when ( /$under_terms_of $L{re}{lgpl}(?:[,;:]?(?: either)? ?$L{re}{version}{-keep}(?: of the License)?($L{re}{version_later})?)?/i ) {
$gen_license->( 'lgpl', $1, $2 );
}
}
# AGPL
given ($licensetext) {
when ( /is free software.? you can redistribute (it|them) and[ \/]or modify (it|them) under the terms of $L{re}{agpl}/i ) {
$license = "AGPL$gplver$extrainfo $license";
push @spdx_license, $gen_spdx->('AGPL');
}
# exclude CeCILL-2.1 license
when ( /GNU Affero General Public License dans/i ) {
break;
}
# exclude GPL-3 license
when ( /GNU Affero General Public License into/i ) {
break;
}
# exclude MPL-2.0 license
when ( /means either ([^.]+$L{re}{version_number})+, the GNU Affero General Public License/i ) {
break;
}
when ( /AFFERO GENERAL PUBLIC LICENSE(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'agpl', $1, $2 );
}
}
# GPL
given ($licensetext) {
# exclude GPL fulltext (rarely if ever used as grant)
when ( /Copyright \(C\) (?:19|yy)yy <?name of author>?\s+This program is free software/ ) {
break;
}
# exclude LGPL-3 fulltext (rarely if ever used as grant)
when ( /under the GNU GPL,? with none of the additional permissions of this License/ ) {
break;
}
# exclude AGPL-3 license
when ( /GNU Affero General Public License/ ) {
break;
}
# exclude Perl combo license
when ( /Terms of the Perl programming language system itself/ ) {
break;
}
# exclude CeCILL-1.1 license
when ( /COMPATIBILITY WITH THE GPL LICENSE/i ) {
break;
}
# GPL, among several
when ( /$under_terms_of $any_of(?:[^.]|\.\S)* $L{re}{gpl}(?:[,;:]? ?$L{re}{version}{-keep}(?: of the License)?($L{re}{version_later})?)?/i ) {
break; # handled in multi-licensing loop
}
# GPL or LGPL
when ( /either $L{re}{gpl}(?:[,;]? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?: \((?:the )?"?GPL"?\))?, or $L{re}{lgpl}(?:[,;]? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'gpl', $1, $2, 'lgpl', $3, $4 );
}
if ( $gplver or $extrainfo ) {
when ( /under (?:the terms of )?(?:version \S+ (?:\(?only\)? )?of )?$L{re}{gpl}/i ) {
$license = "GPL$gplver$extrainfo $license";
push @spdx_license, $gen_spdx->('GPL');
}
}
when ( /under (?:the terms of )?(?:version \S+ (?:\(?only\)? )?of )?$L{re}{gpl}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'gpl', $1, $2 );
}
}
# CC
given ($licensetext) {
foreach my $id (qw<cc_by cc_by_nc cc_by_nc_nd cc_by_nc_sa cc_by_nd cc_by_sa cc_cc0>) {
when ( /$L{re}{$id}(?i: version)? ($L{re}{version_number}) or ($L{re}{version_number})/i ) {
$license = "$L{caption}{$id} (v$1 or v$2) $license";
push @spdx_license, "$L{name}{$id}-$1 or $L{name}{$id}-$1";
}
when ( /$L{re}{$id}(?: $L{re}{version}{-keep}?)(?: License)?($L{re}{version_later})?(?:,? (?:and|or) $L{re}{xgpl}{-keep}(?:-?($L{re}{version_number})(,? $L{re}{version_later_postfix})?)?)?/i ) {
$gen_license->( $id, $1, $2, $3, $4 );
}
}
}
# NTP
given ($licensetext) {
when ( /$L{re}{dsdp}/) {
$gen_license->('dsdp');
}
when ( /$L{re}{ntp_disclaimer}/) {
$gen_license->('ntp_disclaimer');
}
when ( /$L{re}{ntp}/) {
$gen_license->('ntp');
}
}
# BSD
if ( $licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY/ ) {
given ($licensetext) {
when ( /$L{re}{clause_advertising}/i ) {
$gen_license->('bsd_4_clause');
}
when ( /$L{re}{clause_non_endorsement}/i ) {
$gen_license->('bsd_3_clause');
}
when ( /$L{re}{clause_reproduction}/i ) {
$gen_license->('bsd_2_clause');
}
default {
$gen_license->('bsd');
}
}
}
elsif ( $licensetext =~ /licen[sc]e:? ?bsd-(\d)-clause/i ) {
$gen_license->("bsd_${1}_clause");
}
elsif ( $licensetext =~ /licen[sc]e:? ?bsd\b/i ) {
$gen_license->('bsd');
}
# Artistic
given ($licensetext) {
when ( /$L{re}{perl}/ ) {
$gen_license->('perl');
}
when ( /$L{re}{artistic}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/ ) {
$gen_license->('artistic', $1, $2);
}
}
# Apache
given ($licensetext) {
# skip referenced license
when (/$L{re}{rpsl}/) {
break;
}
when ( /$L{re}{apache}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]+\))*,? or $L{re}{gpl}(?: $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'apache', $1, $2, 'gpl', $3, $4 );
}
when ( /$L{re}{apache}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]\))*,? or(?: the)? bsd(?:[ -](\d)-clause)?\b/i ) {
$gen_license->( 'apache', $1, $2, "bsd_${3}_clause" );
}
when ( /$L{re}{apache}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]\))*,? or $L{re}{mit_new}\b/i ) {
$gen_license->( 'apache', $1, $2, 'mit_new', $3, $4 );
}
when ( /$L{re}{apache}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?(?:(?: or)? [^ ,]*?apache[^ ,]*| \([^(),]\))*,? or $L{re}{mit}\b/i ) {
$gen_license->( 'apache', $1, $2, 'mit', $3, $4 );
}
when ( /$L{re}{apache}(?:,? $L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'apache', $1, $2 );
}
when ( m<https?www.apache.org/licenses(?:/LICENSE-($L{re}{version_number}))?>i ) {
$gen_license->( 'apache', $1 );
}
}
# FSFUL
given ($licensetext) {
when ( /$L{re}{fsful}/i ) {
$gen_license->('fsful');
}
when ( /This (\w+)(?: (?:file|script))? is free software; $L{re}{fsf_unlimited}/i ) {
$license = "FSF Unlimited ($1 derivation) $license";
push @spdx_license, "FSFUL~$1";
}
}
# FSFULLR
given ($licensetext) {
when ( /$L{re}{fsfullr}/i ) {
$gen_license->('fsfullr');
}
when ( /This (\w+)(?: (?:file|script))? is free software; $L{re}{fsf_unlimited_retention}/i ) {
$license = "FSF Unlimited (with Retention, $1 derivation) $license";
push @spdx_license, "FSFULLR~$1";
}
}
# JSON
given ($licensetext) {
when ( /The Software shall be used for Good, not Evil/ ) {
$gen_license->('JSON');
}
}
# PHP
given ($licensetext) {
when ( /This source file is subject to version ($L{re}{version_number}) of the PHP license/ ) {
$gen_license->( 'PHP', $1 );
}
}
# CECILL
given ($licensetext) {
when ( /$L{re}{cecill_1}/ ) {
$gen_license->('cecill_1');
}
when ( /$L{re}{cecill_1_1}/ ) {
$gen_license->('cecill_1_1');
}
when ( /$L{re}{cecill_2}/ ) {
$gen_license->('cecill_2');
}
when ( /$L{re}{cecill_2_1}/ ) {
$gen_license->('cecill_2_1');
}
when ( /$L{re}{cecill_b}/ ) {
$gen_license->('cecill_b');
}
when ( /$L{re}{cecill_c}/ ) {
$gen_license->('cecill_c');
}
when ( /$L{re}{cecill}(?:(?:-|\s*$L{re}{version_prefix})($L{re}{version_number}))?/ ) {
$gen_license->( 'cecill', $1 );
}
}
# CDDL
given ($licensetext) {
when ( /$L{re}{cddl}(?:,?\s+$L{re}{version}{-keep})?/ ) {
$gen_license->( 'cddl', $1 );
}
}
# public-domain
given ($licensetext) {
when ( /is in $L{re}{public_domain}/i ) {
$gen_license->('public_domain');
}
}
given ($licensetext) {
# AFL or LGPL
when ( /either $L{re}{afl}(?:,? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?, or $L{re}{lgpl}(?:,? ?$L{re}{version}{-keep}(,? $L{re}{version_later_postfix})?)?/i ) {
$gen_license->( 'afl', $1, $2, 'lgpl', $3, $4 );
}
# AFL
when ( /Licensed under $L{re}{afl}(?: $L{re}{version}{-keep})?/ ) {
$gen_license->( 'afl', $1 );
}
}
# EPL
given ($licensetext) {
when ( /This program and the accompanying materials are made available under the terms of $L{re}{epl}(?:[ ,-]+$L{re}{version}{-keep})?/ ) {
$gen_license->( 'epl', $1 );
}
}
# BSL
given ($licensetext) {
when ( /Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license \(the Software\)/ ) {
$gen_license->('BSL');
}
when ( /Boost Software License(?:[ ,-]+ $L{re}{version}{-keep})?/i ) {
$gen_license->( 'BSL', $1, $2 );
}
}
#>>>
given ($licensetext) {
# simple-versioned
foreach my $id (qw<mpl ofl python qpl rpsl sgi_b wtfpl>) {
when (/$L{re}{$id}\W*\(?$L{re}{version}{-keep}\)?/) {
# skip referenced license
if ( 'mpl' eq $id and $licensetext =~ /$L{re}{rpsl}/ ) {
continue;
}
$gen_license->( $id, $1 );
continue;
}
}
# unversioned
foreach my $id (
qw(
adobe_2006 adobe_glyph aladdin apafml
beerware cube curl eurosym fsfap ftl icu isc libpng llgpl
mit_advertising mit_cmu mit_cmu_warranty
mit_enna mit_feh mit_new mit_old
mit_oldstyle mit_oldstyle_disclaimer mit_oldstyle_permission
ms_pl ms_rl postgresql unicode_strict unicode_tou
zlib zlib_acknowledgement)
)
{
when (/$L{re}{$id}/) {
# skip embedded license
if ( 'zlib' eq $id and $licensetext =~ /$L{re}{cube}/ ) {
continue;
}
$gen_license->($id);
continue;
}
}
}
# Remove trailing spaces.
$license =~ s/\s+$//;
return $self->deb_fmt ? join( ' and/or ', sort @spdx_license ) : $license;
}
=encoding UTF-8
=head1 AUTHOR
Jonas Smedegaard C<< <dr@jones.dk> >>
=head1 COPYRIGHT AND LICENSE
This program is based on the script "licensecheck" from the KDE SDK,
originally introduced by Stefan Westerfeld C<< <stefan@space.twc.de> >>.
Copyright © 2007, 2008 Adam D. Barratt
Copyright © 2012 Francesco Poli
Copyright © 2016 Jonas Smedegaard
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/>.
=cut
1;
|