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

filter: Statementstmt 100% 38 / 38 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 93.3% 56 / 60 CC 9 SCAR 15.8
CC
9
Cov
98%
munge_pod
8.0
munge_files
2.0
BEGIN
1.0
CRAP 4.9
« blib/lib/Dist/Zilla/Role/PPI.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/MetaResources.pm »
1 package Dist::Zilla::Plugin::PodVersion 6.040;
2 # ABSTRACT: add a VERSION head1 to each Perl document
3  
4 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 with(
6 'Dist::Zilla::Role::FileMunger',
7 'Dist::Zilla::Role::FileFinderUser' => {
8 default_finders => [ ':InstallModules', ':ExecFiles' ],
9 },
10 );
11  
12 9 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #pod =head1 DESCRIPTION
17 #pod
18 #pod This plugin adds a C<=head1 VERSION> section to most perl files in the
19 #pod distribution, indicating the version of the dist being built. This section is
20 #pod added after C<=head1 NAME>. If there is no such section, the version section
21 #pod will not be added.
22 #pod
23 #pod Note that this plugin is not useful if you are using the
24 #pod L<[PodWeaver]|Dist::Zilla::Plugin::PodWeaver> plugin, as it also adds a
25 #pod C<=head1 VERSION> section (via the L<[Version]|Pod::Weaver::Section::Version>
26 #pod section).
27 #pod
28 #pod =cut
29  
30 9 ▶sub munge_files {
Subroutine munge_files: called CC=2 SCAR=6.9
Pod undocumented
31 9 my ($self) = @_;
32  
33 9 $self->munge_file($_) for @{ $self->found_files };
34 }
35  
36 13 ▶sub munge_file {
Subroutine munge_file: called CC=1 SCAR=0.0
Pod undocumented
37 13 my ($self, $file) = @_;
38  
39 13 return $self->munge_pod($file);
40 }
41  
42 13 ▶sub munge_pod {
Subroutine munge_pod: called CC=8 SCAR=20.8
Pod undocumented
43 13 my ($self, $file) = @_;
44  
45 13 my @content = split /\n/, $file->content;
46  
47 13 require List::Util;
48 13 List::Util->VERSION('1.33');
49 13 ▶ if (List::Util::any(sub { $_ =~ /^=head1 VERSION\b/ }, @content)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::any(sub { $_ =~ /^=head1 VERSION\b/u; } , @content)) 1 12 13
50 1 $self->log($file->name . ' already has a VERSION section in POD');
51 1 return;
52 }
53  
54 12 for (0 .. $#content) {
55 106 ▶ next until $content[$_] =~ /^=head1 NAME/;
Branch: 1 branch
BranchTrueFalseTotal
$content[$_] =~ /^=head1 NAME/u or do { next } 4 102 106
56  
57 4 $_++; # move past the =head1 line itself
58 4 ▶ $_++ while $content[$_] =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
$content[$_] =~ /^\s*$/u and do { ++$_ } 4 4 8
59  
60 4 ▶ $_++ while $content[$_] !~ /^\s*$/; # move past the abstract
Branch: 1 branch
BranchTrueFalseTotal
$content[$_] =~ /^\s*$/u or do { ++$_ } 4 5 9
61 4 ▶ $_++ while $content[$_] =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
$content[$_] =~ /^\s*$/u and do { ++$_ } 4 4 8
62  
63 4 splice @content, $_ - 1, 0, (
64 q{},
65 "=head1 VERSION",
66 q{},
67 "version " . $self->zilla->version . q{},
68 );
69  
70 4 $self->log_debug([ 'adding VERSION Pod section to %s', $file->name ]);
71  
72 4 my $content = join "\n", @content;
73 4 ▶ $content .= "\n" if length $content;
Branch: 1 branch
BranchTrueFalseTotal
if length $content 4 0 4
74 4 $file->content($content);
75 4 return;
76 }
77  
78 $self->log([
79 8 "couldn't find '=head1 NAME' in %s, not adding '=head1 VERSION'",
80 $file->name,
81 ]);
82 }
83  
84 9 __PACKAGE__->meta->make_immutable;
85 9 1;
86  
87 #pod =head1 SEE ALSO
88 #pod
89 #pod Core Dist::Zilla plugins:
90 #pod L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
91 #pod L<AutoVersion|Dist::Zilla::Plugin::AutoVersion>,
92 #pod L<NextRelease|Dist::Zilla::Plugin::NextRelease>.
93 #pod
94 #pod =cut
95  
96 __END__
« blib/lib/Dist/Zilla/Role/PPI.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/MetaResources.pm »