blib/lib/Dist/Zilla/Plugin/PkgVersion/Block.pm

filter: Statementstmt 86.9% 60 / 69 Branchbran 70.0% 21 / 30 Conditioncond 80.0% 12 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 77.7% 105 / 135 CC 24 SCAR 28.5
CC
24
Cov
82%
munge_perl
24.5
munge_files
3.2
munge_file
2.2
CRAP 17.2
↑ Summary
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
BranchTrueFalseTotal
unless (StrictVersionStr()->check($self->zilla->version)) 0 1 1
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
BranchTrueFalseTotal
if ($file->is_bytes) 0 5 5
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
BranchTrueFalseTotal
unless ($package_statements) 0 5 5
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
BranchTrueFalseTotal
if ($self->document_assigns_to_variable($document, "\$VERSION")) 0 5 5
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
BranchTrueFalseTotal
if ($seen{$package}++) 0 6 6
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
BranchTrueFalseTotal
if ($stmt->content =~ / package \s* (?:\#.*)? \n \s* \Q$package\E/ux) 1 5 6
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
BranchTrueFalseTotal
if ($package =~ /\P{ASCII}/u) 0 5 5
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
BranchTrueFalseTotal
if $count == 1 and $token ne "package" 0 24 24
Condition66%2/3
$count == 1 and $token ne "package"
!ll&&!rl&&r
1950
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"
ABresult
0X0
100
111
82 24 ▶ last TOKEN if $count == 2 && $token !~ m{\s+};
Branch: 1 branch
BranchTrueFalseTotal
if $count == 2 and not $token =~ /\s+/u 0 24 24
Condition66%2/3
$count == 2 and not $token =~ /\s+/u
!ll&&!rl&&r
1950
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
ABresult
0X0
100
111
83 24 ▶ last TOKEN if $count == 3 && $token !~ m{\w+(::\w+)*};
Branch: 1 branch
BranchTrueFalseTotal
if $count == 3 and not $token =~ /\w+(::\w+)*/u 0 24 24
Condition66%2/3
$count == 3 and not $token =~ /\w+(::\w+)*/u
!ll&&!rl&&r
1950
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
ABresult
0X0
100
111
84 24 ▶ $name_token = $token if $count == 3;
Branch: 1 branch
BranchTrueFalseTotal
if $count == 3 5 19 24
85 24 ▶ last TOKEN if $count == 4 && $token !~ m{\s+};
Branch: 1 branch
BranchTrueFalseTotal
if $count == 4 and not $token =~ /\s+/u 1 23 24
Condition100%3/3
$count == 4 and not $token =~ /\s+/u
!ll&&!rl&&r
1941
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
ABresult
0X0
100
111
86 23 ▶ last TOKEN if $count == 5 && $token ne '{';
Branch: 1 branch
BranchTrueFalseTotal
if $count == 5 and $token ne "{" 1 22 23
Condition100%3/3
$count == 5 and $token ne "{"
!ll&&!rl&&r
1931
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 "{"
ABresult
0X0
100
111
87  
88 22 ▶ if($count == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 5) 3 19 22
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
BranchTrueFalseTotal
if $munged 2 3 5
98 }
99 }
100  
101 2 1;
102  
103 __END__
↑ Summary