File Coverage

blib/lib/Dist/Zilla/Plugin/PodVersion.pm
Criterion Covered Total %
statement 35 35 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 45 49 91.8


line stmt bran cond sub pod time code
1             # ABSTRACT: add a VERSION head1 to each Perl document
2              
3             use Moose;
4 9     9   6685 with(
  9         22  
  9         73  
5             'Dist::Zilla::Role::FileMunger',
6             'Dist::Zilla::Role::FileFinderUser' => {
7             default_finders => [ ':InstallModules', ':ExecFiles' ],
8             },
9             );
10              
11             use Dist::Zilla::Pragmas;
12 9     9   61289  
  9         23  
  9         109  
13             use namespace::autoclean;
14 9     9   74  
  9         31  
  9         100  
15             #pod =head1 DESCRIPTION
16             #pod
17             #pod This plugin adds a C<=head1 VERSION> section to most perl files in the
18             #pod distribution, indicating the version of the dist being built. This section is
19             #pod added after C<=head1 NAME>. If there is no such section, the version section
20             #pod will not be added.
21             #pod
22             #pod Note that this plugin is not useful if you are using the
23             #pod L<[PodWeaver]|Dist::Zilla::Plugin::PodWeaver> plugin, as it also adds a
24             #pod C<=head1 VERSION> section (via the L<[Version]|Pod::Weaver::Section::Version>
25             #pod section).
26             #pod
27             #pod =cut
28              
29             my ($self) = @_;
30              
31 9     9 0 2481 $self->munge_file($_) for @{ $self->found_files };
32             }
33 9         25  
  9         60  
34             my ($self, $file) = @_;
35              
36             return $self->munge_pod($file);
37 13     13 0 422 }
38              
39 13         53 my ($self, $file) = @_;
40              
41             my @content = split /\n/, $file->content;
42              
43 13     13 0 34 require List::Util;
44             List::Util->VERSION('1.33');
45 13         53 if (List::Util::any(sub { $_ =~ /^=head1 VERSION\b/ }, @content)) {
46             $self->log($file->name . ' already has a VERSION section in POD');
47 13         104 return;
48 13         236 }
49 13 100   149   114  
  149         272  
50 1         7 for (0 .. $#content) {
51 1         246 next until $content[$_] =~ /^=head1 NAME/;
52              
53             $_++; # move past the =head1 line itself
54 12         69 $_++ while $content[$_] =~ /^\s*$/;
55 106         260  
56             $_++ while $content[$_] !~ /^\s*$/; # move past the abstract
57 4         8 $_++ while $content[$_] =~ /^\s*$/;
58 4         30  
59             splice @content, $_ - 1, 0, (
60 4         28 q{},
61 4         25 "=head1 VERSION",
62             q{},
63 4         137 "version " . $self->zilla->version . q{},
64             );
65              
66             $self->log_debug([ 'adding VERSION Pod section to %s', $file->name ]);
67              
68             my $content = join "\n", @content;
69             $content .= "\n" if length $content;
70 4         20 $file->content($content);
71             return;
72 4         412 }
73 4 50       29  
74 4         18 $self->log([
75 4         30 "couldn't find '=head1 NAME' in %s, not adding '=head1 VERSION'",
76             $file->name,
77             ]);
78             }
79 8         742  
80             __PACKAGE__->meta->make_immutable;
81             1;
82              
83             #pod =head1 SEE ALSO
84             #pod
85             #pod Core Dist::Zilla plugins:
86             #pod L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
87             #pod L<AutoVersion|Dist::Zilla::Plugin::AutoVersion>,
88             #pod L<NextRelease|Dist::Zilla::Plugin::NextRelease>.
89             #pod
90             #pod =cut
91              
92              
93             =pod
94              
95             =encoding UTF-8
96              
97             =head1 NAME
98              
99             Dist::Zilla::Plugin::PodVersion - add a VERSION head1 to each Perl document
100              
101             =head1 VERSION
102              
103             version 6.028
104              
105             =head1 DESCRIPTION
106              
107             This plugin adds a C<=head1 VERSION> section to most perl files in the
108             distribution, indicating the version of the dist being built. This section is
109             added after C<=head1 NAME>. If there is no such section, the version section
110             will not be added.
111              
112             Note that this plugin is not useful if you are using the
113             L<[PodWeaver]|Dist::Zilla::Plugin::PodWeaver> plugin, as it also adds a
114             C<=head1 VERSION> section (via the L<[Version]|Pod::Weaver::Section::Version>
115             section).
116              
117             =head1 PERL VERSION
118              
119             This module should work on any version of perl still receiving updates from
120             the Perl 5 Porters. This means it should work on any version of perl released
121             in the last two to three years. (That is, if the most recently released
122             version is v5.40, then this module should work on both v5.40 and v5.38.)
123              
124             Although it may work on older versions of perl, no guarantee is made that the
125             minimum required version will not be increased. The version may be increased
126             for any reason, and there is no promise that patches will be accepted to lower
127             the minimum required perl.
128              
129             =head1 SEE ALSO
130              
131             Core Dist::Zilla plugins:
132             L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
133             L<AutoVersion|Dist::Zilla::Plugin::AutoVersion>,
134             L<NextRelease|Dist::Zilla::Plugin::NextRelease>.
135              
136             =head1 AUTHOR
137              
138             Ricardo SIGNES 😏 <cpan@semiotic.systems>
139              
140             =head1 COPYRIGHT AND LICENSE
141              
142             This software is copyright (c) 2022 by Ricardo SIGNES.
143              
144             This is free software; you can redistribute it and/or modify it under
145             the same terms as the Perl 5 programming language system itself.
146              
147             =cut