| 1 | 2 | ▶ | use 5.14.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: PkgVersion for block packages | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | package Dist::Zilla::Plugin::PkgVersion::Block { | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.0200'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | with('Dist::Zilla::Role::FileMunger', | |||||||||||||||||||||||||||
| 12 | 'Dist::Zilla::Role::FileFinderUser' => { default_finders => [':InstallModules', ':ExecFiles'] }, | ||||||||||||||||||||||||||||
| 13 | 'Dist::Zilla::Role::PPI' | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use PPI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use MooseX::Types::Perl qw/StrictVersionStr/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub munge_files { | ||||||||||||||||||||||||||
|
Subroutine
munge_files: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | if(!StrictVersionStr->check($self->zilla->version)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | Carp::croak('Version ' . $self->zilla->version . ' does not conform to the strict version string format.') ; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 1 | $self->munge_file($_) for @{ $self->found_files }; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | sub munge_file { | ||||||||||||||||||||||||||
|
Subroutine
munge_file: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 5 | my $file = shift; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if($file->is_bytes) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $self->log_debug([ "%s has 'bytes' encoding, skipping...", $file->name ]); | |||||||||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 5 | return $self->munge_perl($file); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub munge_perl { | ||||||||||||||||||||||||||
|
Subroutine
munge_perl: called CC=21 SCAR=32.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 5 | my $file = shift; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | my $document = $self->ppi_document_for_file($file); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 5 | my $package_statements = $document->find('PPI::Statement::Package'); | |||||||||||||||||||||||||||
| 47 | 5 | ▶ | if(!$package_statements) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $self->log_debug([ 'skipping %s: no package statement found', $file->name ]); | |||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | ▶ | if($self->document_assigns_to_variable($document, '$VERSION')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->log_fatal([ 'existing assignment to $VERSION in %s', $file->name ]); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | my %seen; | |||||||||||||||||||||||||||
| 57 | 5 | my $munged = 0; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | STATEMENT: | ||||||||||||||||||||||||||||
| 60 | 5 | for my $stmt (@{ $package_statements }) { | |||||||||||||||||||||||||||
| 61 | 6 | my $package = $stmt->namespace; | |||||||||||||||||||||||||||
| 62 | 6 | ▶ | if($seen{ $package }++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $self->log([ 'skipping package re-declaration for %s', $package ]); | |||||||||||||||||||||||||||
| 64 | 0 | next STATEMENT; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 6 | ▶ | if($stmt->content =~ m{ package \s* (?:\#.*)? \n \s* \Q$package}x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 1 | $self->log([ 'skipping private package %s in %s', $package, $file->name] ); | |||||||||||||||||||||||||||
| 68 | 1 | next STATEMENT; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 5 | ▶ | if($package =~ m{\P{ASCII}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $self->log('non-ASCII package name is likely to cause problems'); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | my $count = 0; | |||||||||||||||||||||||||||
| 75 | 5 | my $name_token = undef; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | TOKEN: | ||||||||||||||||||||||||||||
| 78 | 5 | foreach my $token ($stmt->tokens) { | |||||||||||||||||||||||||||
| 79 | 24 | ++$count; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 24 | ▶ | last TOKEN if $count == 1 && $token ne 'package'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count == 1 and $token ne "package"
MC/DC0%0/2
$count == 1 and $token ne "package"
$count == 1
$token ne "package"
Truth table66%2/3
A and B
A= $count == 1B= $token ne "package"
| |||||||||||||||||||||||||||||
| 82 | 24 | ▶ | last TOKEN if $count == 2 && $token !~ m{\s+}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count == 2 and not $token =~ /\s+/u
MC/DC0%0/2
$count == 2 and not $token =~ /\s+/u
$count == 2
not $token =~ /\s+/u
Truth table66%2/3
A and not(B)
A= $count == 2B= not $token =~ /\s+/u
| |||||||||||||||||||||||||||||
| 83 | 24 | ▶ | last TOKEN if $count == 3 && $token !~ m{\w+(::\w+)*}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count == 3 and not $token =~ /\w+(::\w+)*/u
MC/DC0%0/2
$count == 3 and not $token =~ /\w+(::\w+)*/u
$count == 3
not $token =~ /\w+(::\w+)*/u
Truth table66%2/3
A and not(B)
A= $count == 3B= not $token =~ /\w+(::\w+)*/u
| |||||||||||||||||||||||||||||
| 84 | 24 | ▶ | $name_token = $token if $count == 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 24 | ▶ | last TOKEN if $count == 4 && $token !~ m{\s+}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count == 4 and not $token =~ /\s+/u
MC/DC100%2/2
$count == 4 and not $token =~ /\s+/u
$count == 4
not $token =~ /\s+/u
Truth table100%3/3
A and not(B)
A= $count == 4B= not $token =~ /\s+/u
| |||||||||||||||||||||||||||||
| 86 | 23 | ▶ | last TOKEN if $count == 5 && $token ne '{'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count == 5 and $token ne "{"
MC/DC100%2/2
$count == 5 and $token ne "{"
$count == 5
$token ne "{"
Truth table100%3/3
A and B
A= $count == 5B= $token ne "{"
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 22 | ▶ | if($count == 5) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 3 | my $version_token = PPI::Token::Comment->new(" " . $self->zilla->version); | |||||||||||||||||||||||||||
| 90 | 3 | $name_token->insert_after($version_token); | |||||||||||||||||||||||||||
| 91 | 3 | $munged = 1; | |||||||||||||||||||||||||||
| 92 | 3 | $self->log([ 'adding version to %s in %s', $package, $file->name ]); | |||||||||||||||||||||||||||
| 93 | 3 | last TOKEN; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 5 | ▶ | $self->save_ppi_document_to_file($document, $file) if $munged; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||