blib/lib/Dist/Zilla/Plugin/OverridePkgVersion.pm

filter: Statementstmt 42.6% 29 / 68 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 32.4% 37 / 114 CC 17 SCAR 51.2
CC
17
Cov
30%
munge_file
272.0
munge_files
6.0
BEGIN
1.0
CRAP 168.2
↑ Summary
1 package Dist::Zilla::Plugin::OverridePkgVersion;
2 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.002'; # VERSION
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 with (
10 'Dist::Zilla::Role::FileMunger',
11 'Dist::Zilla::Role::FileFinderUser' => {
12 default_finders => [ ':InstallModules', ':ExecFiles' ],
13 },
14 );
15  
16 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use MooseX::Types::Perl qw( LaxVersionStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub munge_files {
Subroutine munge_files: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my $self = shift;
23 0 $self->munge_file($_) for @{ $self->found_files };
24 0 return;
25 }
26  
27 1 my $comment_regex = qr{
28 ^
29 (\# \s+) (?:TRIAL\s+)?
30 VERSION \b
31 ( [ [:print:] \s ]* )
32 $
33 }x;
34 1 my $assign_regex = qr{
35 ^
36 our \s* \$VERSION \s* = \s* '$version::LAX';
37 $
38 }x;
39  
40 0 ▶sub munge_file {
Subroutine munge_file: not called CC=16 SCAR=56.1
Pod undocumented
41 0 my ( $self, $file ) = @_;
42  
43 0 ▶ if ( $file->name =~ m/\.pod$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->name =~ /\.pod$/) 0 0 0
44 0 $self->log_debug([ 'Skipping: "%s" is pod only', $file->name ]);
45 0 return;
46 }
47  
48 0 my $version = $self->zilla->version;
49  
50 0 ▶ confess 'invalid characters in version'
Branch: 1 branch
BranchTrueFalseTotal
unless LaxVersionStr()->check($version) 0 0 0
51 unless LaxVersionStr->check( $version );
52  
53 0 my $content = $file->content;
54  
55 0 ▶ my $doc = PPI::Document->new(\$content)
Branch: 1 branch
BranchTrueFalseTotal
my $doc = "PPI::Document"->new(\$content) or $self->log(["Skipping: \"%s\" error with PPI: %s", $file->name, "PPI::Document"->errstr]) 0 0 0
56 or $self->log([ 'Skipping: "%s" error with PPI: %s', $file->name, PPI::Document->errstr ]);
57 0 $doc->index_locations;
58  
59 0 ▶ return unless defined $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $doc 0 0 0
60 0 my $indexed;
61  
62 0 my $comments = $doc->find('PPI::Token::Comment');
63  
64 0 my $munged_version = 0;
65 0 ▶ if ( ref $comments eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $comments eq "ARRAY") 0 0 0
66 0 for my $comment ( @$comments ) {
67 0 ▶ if ( $comment =~ $comment_regex ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment =~ /$comment_regex/) 0 0 0
68 0 my ($prelude, $remains) = ($1, $2);
69 0 my $prev = $comment->sprevious_sibling;
70 0 ▶ if ($prev && $comment->line_number == $prev->line_number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $comment->line_number == $prev->line_number) 0 0 0
Condition0%0/3
$prev and $comment->line_number == $prev->line_number
!ll&&!rl&&r
000
MC/DC0%0/2
$prev and $comment->line_number == $prev->line_number
$prev $comment->line_number == $prev->line_number
Truth table0%0/3
A and B
A= $prevB= $comment->line_number == $prev->line_number
ABresult
0X0
100
111
71 0 ▶ if ($prev->isa('PPI::Statement::Variable') && $prev =~ $assign_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->isa('PPI::Statement::Variable') and $prev =~ /$assign_regex/) { } 0 0 0
Condition0%0/3
$prev->isa("PPI::Statement::Variable") and $prev =~ /$assign_regex/
!ll&&!rl&&r
000
MC/DC0%0/2
$prev->isa("PPI::Statement::Variable") and $prev =~ /$assign_regex/
$prev->isa("PPI::Statement::Variable") $prev =~ /$assign_regex/
Truth table0%0/3
A and B
A= $prev->isa("PPI::Statement::Variable")B= $prev =~ /$assign_regex/
ABresult
0X0
100
111
72 0 ▶ while (my $next = $prev->next_sibling) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $prev->next_sibling) 0 0 0
73 0 ▶ last if $next == $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $next == $comment 0 0 0
74 0 $prelude = $next . $prelude;
75 0 $next->delete;
76 }
77 0 $prev->delete;
78 }
79 else {
80 0 next;
81 }
82 }
83 0 $prelude =~ s/^ //;
84 0 ▶ my $code
Branch: 1 branch
BranchTrueFalseTotal
$self->zilla->is_trial ? : 0 0 0
85 = q[our $VERSION = '] . $version. q['; ]
86 . $prelude
87 . ($self->zilla->is_trial ? 'TRIAL ' : '')
88 . 'VERSION' . $remains;
89 0 $comment->set_content($code);
90 0 $file->content( $doc->serialize );
91 0 $munged_version++;
92 }
93 }
94 }
95  
96 0 ▶ if ( $munged_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($munged_version) { } 0 0 0
97 0 $self->log_debug([ 'adding $VERSION assignment to %s', $file->name ]);
98 }
99 else {
100 0 $self->log([ 'Skipping: "%s" has no "# VERSION" comment', $file->name ]);
101 }
102 0 return;
103 }
104 1 __PACKAGE__->meta->make_immutable;
105 1 1;
106 # ABSTRACT: Override existing VERSION in a module
107  
108 __END__
↑ Summary