| 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
| |||||||||||
| 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
| |||||||||||
| 56 | |||||||||||
| 57 | 4 | $_++; # move past the =head1 line itself | |||||||||
| 58 | 4 | ▶ | $_++ while $content[$_] =~ /^\s*$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 4 | ▶ | $_++ while $content[$_] !~ /^\s*$/; # move past the abstract | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 4 | ▶ | $_++ while $content[$_] =~ /^\s*$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||