File Coverage

lib/Dist/Zilla/Plugin/Author/SKIRMESS/InsertVersion.pm
Criterion Covered Total %
statement 20 34 58.8
branch 0 8 0.0
condition n/a
subroutine 7 8 87.5
pod 0 1 0.0
total 27 51 52.9


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::SKIRMESS::InsertVersion;
2              
3 1     1   1561 use 5.006;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         19  
5 1     1   4 use warnings;
  1         1  
  1         43  
6              
7             our $VERSION = '0.031';
8              
9 1     1   328 use Moose;
  1         394141  
  1         6  
10              
11             with qw(
12             Dist::Zilla::Role::FileMunger
13             );
14              
15 1     1   8069 use Carp;
  1         2  
  1         68  
16 1     1   725 use Path::Tiny;
  1         9488  
  1         117  
17              
18 1     1   432 use namespace::autoclean;
  1         6504  
  1         7  
19              
20             sub munge_file {
21 0     0 0   my ( $self, $file ) = @_;
22              
23 0           my $filename = $file->name;
24              
25             # stringify returns the path standardized with Unix-style / directory
26             # separators.
27 0 0         return if path($filename)->stringify() !~ m{ ^ (?: bin | lib | xt | t ) / }xsm;
28              
29 0           my $content = $file->content;
30              
31             # Skip files without pod
32 0 0         return if $content !~ m{ ^ =pod }xsm;
33              
34 0 0         if ( $content !~ m{ ^ =head1 \s+ VERSION $ }xsm ) {
35 0           $self->log("No VERSION section found in POD in file $filename. Skipping it.");
36 0           return;
37             }
38              
39             # Replace the existing VERSION section with the current version
40 0           my $version_section = "\n\n=head1 VERSION\n\nVersion " . $self->zilla->version . "\n\n";
41 0 0         if (
42             $content !~ s{
43             [\s\n]*
44             ^ =head1 \s+ VERSION [^\n]* $
45             .*?
46             ^ ( = (?: head | cut ) )
47             }{$version_section$1}xsm
48             )
49             {
50 0           $self->log_fatal("Unable to replace VERSION section in file $filename.");
51              
52             # log_fatal should die
53 0           croak 'internal error';
54             }
55              
56 0           $file->content($content);
57 0           return;
58             }
59              
60             __PACKAGE__->meta->make_immutable;
61              
62             1;
63              
64             # vim: ts=4 sts=4 sw=4 et: syntax=perl