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

filter: Statementstmt 100% 51 / 51 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 96.4% 82 / 85 CC 9 SCAR 15.3
CC
9
Cov
97%
check
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
« lib/App/Project/Doctor/Check/Pod.pm ↑ Summary blib/lib/App/Project/Doctor/Check/Dependencies.pm »
1 package App::Project::Doctor::Check::Meta;
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::Array my @REQUIRED_FIELDS => qw(name version author abstract license);
15 2 Readonly::Array my @META_FILES => qw(META.json META.yml MYMETA.json MYMETA.yml);
16  
17 2 ▶sub name { 'META' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
18 1 ▶sub description { 'META.yml or META.json is present, parseable, and complete.' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
19 2 ▶sub can_fix { 0 }
Subroutine can_fix: called CC=1 SCAR=0.0
Pod documented
20 2 ▶sub order { 30 }
Subroutine order: called CC=1 SCAR=0.0
Pod documented
21  
22 6 ▶sub check {
Subroutine check: called CC=9 SCAR=22.0
Pod documented
23 6 my ($self, $ctx) = @_;
24 6 ▶ croak 'check requires an App::Project::Doctor::Context' unless ref $ctx;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ctx 0 6 6
25  
26 6 my @findings;
27  
28 6 my ($meta_file) = grep { $ctx->has_file($_) } @META_FILES;
29  
30 6 ▶ unless ($meta_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta_file) 3 3 6
31 3 push @findings, _f(
32 severity => 'warning',
33 message => 'No META.{yml,json} -- run your builder to generate one.',
34 detail => 'CPAN indexers require META to discover name and version.',
35 );
36 # Fall back: at least confirm a builder file exists.
37 3 ▶ unless ($ctx->builder_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->builder_file) 1 2 3
38 1 push @findings, _f(
39 severity => 'error',
40 message => 'No Makefile.PL, Build.PL, or dist.ini found.',
41 );
42 }
43 3 return @findings;
44 }
45  
46 3 require CPAN::Meta;
47 3 my $meta = eval { CPAN::Meta->load_file($ctx->abs_path($meta_file)) };
48 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
49 1 return _f(
50 severity => 'error',
51 message => "Failed to parse $meta_file -- file may be malformed.",
52 file => $meta_file,
53 );
54 }
55  
56 2 my %data = %{ $meta->as_struct };
57 2 for my $field (@REQUIRED_FIELDS) {
58 10 ▶ next if defined $data{$field} && length $data{$field};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data{$field} and length $data{$field} 9 1 10
Condition66%2/3
defined $data{$field} and length $data{$field}
!ll&&!rl&&r
109
MC/DC50%1/2
defined $data{$field} and length $data{$field}
defined $data{$field} length $data{$field}
Truth table66%2/3
A and B
A= defined $data{$field}B= length $data{$field}
ABresult
0X0
100
111
59 1 push @findings, _f(
60 severity => 'error',
61 message => "META field '$field' is missing or empty in $meta_file.",
62 file => $meta_file,
63 );
64 }
65  
66 2 ▶ unless (@findings) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@findings) 1 1 2
67 1 push @findings, _f(
68 severity => 'pass',
69 message => "$meta_file is valid and all required fields are present.",
70 );
71 }
72  
73 2 return @findings;
74 }
75  
76 7 ▶sub _f {
Subroutine _f: called CC=1 SCAR=0.0
77 7 require App::Project::Doctor::Finding;
78 7 return App::Project::Doctor::Finding->new(check_name => 'META', @_);
79 }
80  
81 2 1;
82  
83 __END__
« lib/App/Project/Doctor/Check/Pod.pm ↑ Summary blib/lib/App/Project/Doctor/Check/Dependencies.pm »