| 1 | package Dist::Zilla::Plugin::CoalescePod; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: merge .pod files into their .pm counterparts | ||||||||||
| 4 | 2 | $Dist::Zilla::Plugin::CoalescePod::VERSION = '1.0.0'; | |||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | with qw( | |||||||||
| 11 | Dist::Zilla::Role::FileMunger | ||||||||||
| 12 | Dist::Zilla::Role::FilePruner | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | has _pod_files => ( | ||||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => 'ArrayRef', | ||||||||||
| 18 | 1 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ); | |||||||||
| 20 | |||||||||||
| 21 | 8 | ▶ | sub munge_file { | ||||||||
|
Subroutine
munge_file: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 22 | 8 | my ( $self, $file ) = @_; | |||||||||
| 23 | |||||||||||
| 24 | # only look under /lib | ||||||||||
| 25 | 8 | ▶ | return unless $file->name =~ m#^lib/.*\.pm$#; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 2 | ( my $podname = $file->name ) =~ s/\.pm$/.pod/; | |||||||||
| 28 | |||||||||||
| 29 | 4 | my ( $podfile ) = grep { $_->name eq $podname } | |||||||||
| 30 | 2 | ▶ | @{ $self->_pod_files } or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 2 | $self->log( "merged " . $podfile->name . " into " . $file->name ); | |||||||||
| 33 | |||||||||||
| 34 | 2 | my @content = ( $file->content ); | |||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | push @content, $1 if $content[0] =~ s/(^__DATA__.*)//ms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | # inject the pod | ||||||||||
| 39 | 2 | splice @content, 1, 0, $podfile->content; | |||||||||
| 40 | |||||||||||
| 41 | 2 | $file->content( join "\n\n", @content ); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | sub prune_files { | ||||||||
|
Subroutine
prune_files: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 45 | 1 | my ($self) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 1 | my @files = @{ $self->zilla->files }; | |||||||||
| 48 | |||||||||||
| 49 | 1 | foreach my $file ( @files ) { | |||||||||
| 50 | 11 | ▶ | next unless $file->name =~ m/\.pod$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 3 | ▶ | next if $file->name =~ /t\/corpus/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 3 | my $pm = $file->name =~ s/\.pod$/.pm/r; | |||||||||
| 54 | |||||||||||
| 55 | # only deal with pod files with associated pm files | ||||||||||
| 56 | 3 | ▶ | next unless grep { $_->name eq $pm } @files; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | |||||||||||
| 58 | 2 | push @{ $self->_pod_files }, $file; | |||||||||
| 59 | 2 | $self->zilla->prune_file($file); | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 2 | 1; | |||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | #PODNAME: Foo | ||||||||||
| 67 | |||||||||||
| 68 | __END__ | ||||||||||