blib/lib/App/Project/Doctor/Check/License.pm

filter: Statementstmt 100% 52 / 52 Branchbran 86.3% 19 / 22 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 91.5% 98 / 107 CC 15 SCAR 19.6
CC
15
Cov
93%
check
13.2
_meta_license_id
3.0
BEGIN
1.0
CRAP 7.1
↑ Summary blib/lib/App/Project/Doctor/Report.pm »
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
BranchTrueFalseTotal
unless ref $ctx 0 6 6
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
BranchTrueFalseTotal
$ctx->has_file('LICENSE') ? : 3 3 6
$ctx->has_file('LICENCE') ? : 1 2 3
37 : $ctx->has_file('LICENCE') ? 'LICENCE'
38 : undef;
39  
40 6 ▶ unless ($lic_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lic_file) 2 4 6
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
BranchTrueFalseTotal
if ($lic_file and $meta_file) 2 4 6
Condition100%3/3
$lic_file and $meta_file
!ll&&!rl&&r
222
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($meta_id and $meta_id ne "unknown") 2 0 2
Condition33%1/3
$meta_id and $meta_id ne "unknown"
!ll&&!rl&&r
002
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"
ABresult
0X0
100
111
53 2 my $pattern = $LICENSE_KEYWORD{$meta_id};
54 2 ▶ if ($pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern) 2 0 2
55 2 my $content = $ctx->slurp($lic_file);
56 2 ▶ unless ($content =~ $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content =~ /$pattern/is) 1 1 2
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
BranchTrueFalseTotal
unless (@findings) 3 3 6
67 3 ▶ push @findings, _f(
Branch: 1 branch
BranchTrueFalseTotal
$meta_file ? : 1 2 3
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
BranchTrueFalseTotal
if $@ or not $meta 1 2 3
Condition66%2/3
$@ or not $meta
l!l&&r!l&&!r
102
MC/DC50%1/2
$@ or not $meta
$@ not $meta
Truth table66%2/3
A or not(B)
A= $@B= not $meta
ABresult
1X1
011
000
87 2 return $meta->license;
88 }
89  
90 2 1;
91  
92 __END__
↑ Summary blib/lib/App/Project/Doctor/Report.pm »