| 1 | package App::Project::Doctor::Check::License; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use parent -norequire, 'App::Project::Doctor::Check::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak carp); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | Readonly::Hash my %LICENSE_KEYWORD => ( | |||||||||||||||||||||||||||
| 15 | perl_5 => qr/same terms as perl/i, | ||||||||||||||||||||||||||||
| 16 | gpl_2 => qr/GNU GENERAL PUBLIC LICENSE\s+Version 2/si, | ||||||||||||||||||||||||||||
| 17 | gpl_3 => qr/GNU GENERAL PUBLIC LICENSE\s+Version 3/si, | ||||||||||||||||||||||||||||
| 18 | lgpl_2 => qr/GNU LESSER GENERAL PUBLIC LICENSE\s+Version 2/si, | ||||||||||||||||||||||||||||
| 19 | mit => qr/Permission is hereby granted, free of charge/i, | ||||||||||||||||||||||||||||
| 20 | bsd => qr/Redistribution and use in source and binary forms/i, | ||||||||||||||||||||||||||||
| 21 | artistic => qr/The Artistic License/i, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub name { 'Licensing' } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub description { 'A LICENSE file is present and agrees with the META declaration.' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | sub can_fix { 0 } | ||||||||||||||||||||||||||
|
Subroutine
can_fix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | sub order { 45 } | ||||||||||||||||||||||||||
|
Subroutine
order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 6 | my ($self, $ctx) = @_; | |||||||||||||||||||||||||||
| 31 | 6 | ▶ | croak 'check requires an App::Project::Doctor::Context' unless ref $ctx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | my @findings; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # 1. LICENSE file must exist (accept both spellings). | ||||||||||||||||||||||||||||
| 36 | 6 | ▶ | my $lic_file = $ctx->has_file('LICENSE') ? 'LICENSE' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 37 | : $ctx->has_file('LICENCE') ? 'LICENCE' | ||||||||||||||||||||||||||||
| 38 | : undef; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | unless ($lic_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | push @findings, _f( | |||||||||||||||||||||||||||
| 42 | severity => 'error', | ||||||||||||||||||||||||||||
| 43 | message => 'No LICENSE (or LICENCE) file found.', | ||||||||||||||||||||||||||||
| 44 | detail => 'CPAN requires a license file for all distributions.', | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # 2. Cross-check META license field when both exist. | ||||||||||||||||||||||||||||
| 49 | 6 | my ($meta_file) = grep { $ctx->has_file($_) } qw(META.json META.yml MYMETA.json MYMETA.yml); | |||||||||||||||||||||||||||
| 50 | 6 | ▶ | if ($lic_file && $meta_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lic_file and $meta_file
MC/DC100%2/2
$lic_file and $meta_file
$lic_file
$meta_file
Truth table100%3/3
A and B
A= $lic_fileB= $meta_file
| |||||||||||||||||||||||||||||
| 51 | 2 | my $meta_id = _meta_license_id($ctx->abs_path($meta_file)); | |||||||||||||||||||||||||||
| 52 | 2 | ▶ | if ($meta_id && $meta_id ne 'unknown') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$meta_id and $meta_id ne "unknown"
MC/DC0%0/2
$meta_id and $meta_id ne "unknown"
$meta_id
$meta_id ne "unknown"
Truth table33%1/3
A and B
A= $meta_idB= $meta_id ne "unknown"
| |||||||||||||||||||||||||||||
| 53 | 2 | my $pattern = $LICENSE_KEYWORD{$meta_id}; | |||||||||||||||||||||||||||
| 54 | 2 | ▶ | if ($pattern) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | my $content = $ctx->slurp($lic_file); | |||||||||||||||||||||||||||
| 56 | 2 | ▶ | unless ($content =~ $pattern) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | push @findings, _f( | |||||||||||||||||||||||||||
| 58 | severity => 'warning', | ||||||||||||||||||||||||||||
| 59 | message => "LICENSE content does not match declared license '$meta_id' in $meta_file.", | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 6 | ▶ | unless (@findings) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 3 | ▶ | push @findings, _f( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | severity => 'pass', | ||||||||||||||||||||||||||||
| 69 | message => "LICENSE file present" | ||||||||||||||||||||||||||||
| 70 | . ($meta_file ? ' and consistent with META.' : '.'), | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 6 | return @findings; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 6 | ▶ | sub _f { | ||||||||||||||||||||||||||
|
Subroutine
_f: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 6 | require App::Project::Doctor::Finding; | |||||||||||||||||||||||||||
| 79 | 6 | return App::Project::Doctor::Finding->new(check_name => 'Licensing', @_); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | sub _meta_license_id { | ||||||||||||||||||||||||||
|
Subroutine
_meta_license_id: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 83 | 3 | my $path = shift; | |||||||||||||||||||||||||||
| 84 | 3 | require CPAN::Meta; | |||||||||||||||||||||||||||
| 85 | 3 | my $meta = eval { CPAN::Meta->load_file($path) }; | |||||||||||||||||||||||||||
| 86 | 3 | ▶ | return undef if $@ || !$meta; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or not $meta
MC/DC50%1/2
$@ or not $meta
$@
not $meta
Truth table66%2/3
A or not(B)
A= $@B= not $meta
| |||||||||||||||||||||||||||||
| 87 | 2 | return $meta->license; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||