lib/Dist/Zilla/Plugin/JSAN/PkgVersion.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 4 SCAR 24.0
CC
4
Cov
0%
munge_files
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
1 package Dist::Zilla::Plugin::JSAN::PkgVersion;
2 BEGIN {
3 $Dist::Zilla::Plugin::JSAN::PkgVersion::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: Embedd module version to sources
7  
8 use Moose;
9  
10 use Path::Class;
11  
12 with 'Dist::Zilla::Role::FileMunger';
13  
14  
15 has 'sources' => (
16 is => 'rw',
17
18 default => '^lib/.*\\.js$'
19 );
20  
21  
22  
23 sub munge_files {
24 my ($self) = @_;
25
26 my $sources = $self->sources;
27
28 my $regex = qr/$sources/;
29
30
31 for my $file (@{$self->zilla->files}) {
32
33 next unless $file->name =~ m/$regex/;
34
35 my $content = $file->content;
36 my $content_copy = $content;
37
38 pos $content = 0;
39
40
41 while ($content =~ m!
42 ( (\s*) /\* VERSION (?'comma',)? \*/)
43 !msxg) {
44
45 my $overall = $1;
46 my $overall_quoted = quotemeta $overall;
47
48 my $comma = $3 || '';
49 my $whitespace = $2;
50
51 my $version = $self->zilla->version;
52
53 $version = "'$version'" if $version !~ m/^\d+(\.\d+)?$/;
54
55 $content_copy =~ s!$overall_quoted!${whitespace}/*PKGVERSION*/VERSION : ${version}${comma}!;
56 }
57
58 $file->content($content_copy) if $content_copy ne $content;
59 }
60 }
61  
62  
63 no Moose;
64 __PACKAGE__->meta->make_immutable();
65  
66  
67 1;
68  
69  
70  
71  
72 __END__