| 1 | package App::Project::Doctor::Check::CpanReadiness; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use parent -norequire, 'App::Project::Doctor::Check::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp qw(croak carp); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | Readonly::Scalar my $VERSION_RE => qr/^\d+\.\d+(?:\.\d+)?(?:_\d+)?$/; | |||||||||||||||||||||||||||
| 15 | # Changes and MANIFEST must use these exact names; README accepts variants below. | ||||||||||||||||||||||||||||
| 16 | 3 | Readonly::Array my @REQUIRED_FILES => qw(Changes MANIFEST); | |||||||||||||||||||||||||||
| 17 | # CPAN and GitHub both accept any of these forms as the distribution README. | ||||||||||||||||||||||||||||
| 18 | 3 | Readonly::Array my @README_VARIANTS => qw(README README.md README.pod README.rst README.txt); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | sub name { 'CPAN Readiness' } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub description { 'Version format, Changes, MANIFEST, and a README variant are present.' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub can_fix { 0 } | ||||||||||||||||||||||||||
|
Subroutine
can_fix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub order { 90 } | ||||||||||||||||||||||||||
|
Subroutine
order: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 32 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 32 | my ($self, $ctx) = @_; | |||||||||||||||||||||||||||
| 27 | 32 | ▶ | croak 'check requires an App::Project::Doctor::Context' unless ref $ctx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 32 | my @findings; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Version format check. | ||||||||||||||||||||||||||||
| 32 | 32 | my $version = _read_version($ctx); | |||||||||||||||||||||||||||
| 33 | 32 | ▶ | if (defined $version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 25 | ▶ | if ($version !~ $VERSION_RE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 5 | push @findings, _f( | |||||||||||||||||||||||||||
| 36 | severity => 'error', | ||||||||||||||||||||||||||||
| 37 | message => "Version '$version' does not match CPAN format (X.YY or X.YY.ZZ).", | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||
| 41 | 7 | push @findings, _f( | |||||||||||||||||||||||||||
| 42 | severity => 'warning', | ||||||||||||||||||||||||||||
| 43 | message => 'Could not determine distribution version from any module.', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Required release files (exact names required by CPAN toolchain). | ||||||||||||||||||||||||||||
| 48 | 32 | for my $file (@REQUIRED_FILES) { | |||||||||||||||||||||||||||
| 49 | 64 | ▶ | unless ($ctx->has_file($file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 22 | push @findings, _f( | |||||||||||||||||||||||||||
| 51 | severity => 'error', | ||||||||||||||||||||||||||||
| 52 | message => "'$file' is missing from the distribution root.", | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # README is required but any common variant is acceptable. README.md is the | ||||||||||||||||||||||||||||
| 58 | # norm on GitHub; CPAN itself accepts all of these without complaint. | ||||||||||||||||||||||||||||
| 59 | 32 | ▶ | unless (grep { $ctx->has_file($_) } @README_VARIANTS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 12 | push @findings, _f( | |||||||||||||||||||||||||||
| 61 | severity => 'error', | ||||||||||||||||||||||||||||
| 62 | message => 'README is missing -- none of ' . join(', ', @README_VARIANTS) . ' found.', | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Changes file must have at least one version entry. | ||||||||||||||||||||||||||||
| 67 | 32 | ▶ | if ($ctx->has_file('Changes')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 21 | my $content = $ctx->slurp('Changes'); | |||||||||||||||||||||||||||
| 69 | 21 | ▶ | unless ($content =~ /^\d+\.\d+/m || $content =~ /^v\d+/m) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$content =~ /^\d+\.\d+/m or $content =~ /^v\d+/m
MC/DC50%1/2
$content =~ /^\d+\.\d+/m or $content =~ /^v\d+/m
$content =~ /^\d+\.\d+/m
$content =~ /^v\d+/m
Truth table66%2/3
A or B
A= $content =~ /^\d+\.\d+/mB= $content =~ /^v\d+/m
| |||||||||||||||||||||||||||||
| 70 | 1 | push @findings, _f( | |||||||||||||||||||||||||||
| 71 | severity => 'warning', | ||||||||||||||||||||||||||||
| 72 | message => 'Changes file has no version entries.', | ||||||||||||||||||||||||||||
| 73 | file => 'Changes', | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # MANIFEST stale-check requires 'make manifest' -- too invasive; just advise. | ||||||||||||||||||||||||||||
| 79 | 32 | ▶ | if ($ctx->has_file('MANIFEST')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 21 | push @findings, _f( | |||||||||||||||||||||||||||
| 81 | severity => 'info', | ||||||||||||||||||||||||||||
| 82 | message => "MANIFEST present -- run 'make manifest' to verify it is not stale.", | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Emit a pass only when there are no errors or warnings. | ||||||||||||||||||||||||||||
| 87 | 32 | my $has_problem = grep { $_->severity =~ /^(?:error|warning)$/ } @findings; | |||||||||||||||||||||||||||
| 88 | 32 | ▶ | unless ($has_problem) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 15 | push @findings, _f( | |||||||||||||||||||||||||||
| 90 | severity => 'pass', | ||||||||||||||||||||||||||||
| 91 | message => 'Distribution meets basic CPAN readiness requirements.', | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 32 | return @findings; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 99 | # Private helpers | ||||||||||||||||||||||||||||
| 100 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 83 | ▶ | sub _f { | ||||||||||||||||||||||||||
|
Subroutine
_f: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 103 | 83 | require App::Project::Doctor::Finding; | |||||||||||||||||||||||||||
| 104 | 83 | return App::Project::Doctor::Finding->new(check_name => 'CPAN Readiness', @_); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 33 | ▶ | sub _read_version { | ||||||||||||||||||||||||||
|
Subroutine
_read_version: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 108 | 33 | my $ctx = shift; | |||||||||||||||||||||||||||
| 109 | 33 | for my $mod (@{ $ctx->lib_modules }) { | |||||||||||||||||||||||||||
| 110 | 27 | ▶ | my $content = eval { $ctx->slurp($mod) } // next; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$ctx->slurp($mod)
}
} // (next)
MC/DC0%0/1
eval {
do {
$ctx->slurp($mod)
}
} // (next)
eval {
do {
$ctx->slurp($mod)
}
}
Truth table50%1/2
A
A= eval {
do {
$ctx->slurp($mod)
}
}
| |||||||||||||||||||||||||||||
| 111 | 27 | ▶ | if (my ($v) = $content =~ /^\s*our\s+\$VERSION\s*=\s*['"]?([^'";\s]+)['"]?/m) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 26 | return $v; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 7 | return undef; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 3 | 1; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||