File Coverage

blib/lib/Dist/Zilla/Plugin/SurgicalPodWeaver.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::SurgicalPodWeaver;
2             # git description: 7a6aee5
3              
4             # ABSTRACT: Surgically apply PodWeaver
5             $Dist::Zilla::Plugin::SurgicalPodWeaver::VERSION = '0.0022';
6              
7 1     1   52897 use Moose;
  0            
  0            
8             extends qw/ Dist::Zilla::Plugin::PodWeaver /;
9              
10             sub parse_hint {
11             my $self = shift;
12             my $content = shift;
13              
14             my %hint;
15             if ( $content =~ m/^\s*#+\s*(?:Dist::Zilla):\s*(.+)$/m ) {
16             %hint = map {
17             m/^([\+\-])(.*)$/ ?
18             ( $1 eq '+' ? ( $2 => 1 ) : ( $2 => 0 ) ) :
19             ()
20             } split m/\s+/, $1;
21             }
22              
23             return \%hint;
24             }
25              
26             around munge_pod => sub {
27             my $inner = shift;
28             my ( $self, $file ) = @_;
29              
30             my $content = $file->content;
31              
32             my $yes = 0;
33             if ( my $hint = __PACKAGE__->parse_hint( $content ) ) {
34             if ( exists $hint->{PodWeaver} ) {
35             return unless $hint->{PodWeaver};
36             $yes = 1;
37             }
38             }
39              
40             if ( $yes || $content =~ m/^\s*#+\s*(?:ABSTRACT):\s*(.+)$/m ) { }
41             else { return }
42              
43             return $inner->( @_ )
44             };
45              
46             __PACKAGE__->meta->make_immutable;
47             no Moose;
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =head1 NAME
55              
56             Dist::Zilla::Plugin::SurgicalPodWeaver - Surgically apply PodWeaver
57              
58             =head1 VERSION
59              
60             version 0.0022
61              
62             =head1 SYNOPSIS
63              
64             In your L<Dist::Zilla> C<dist.ini>:
65              
66             [SurgicalPodWeaver]
67              
68             To hint that you want to apply PodWeaver:
69              
70             package Xyzzy;
71             # Dist::Zilla: +PodWeaver
72              
73             ...
74              
75             =head1 DESCRIPTION
76              
77             Dist::Zilla::Plugin::SurgicalPodWeaver will only PodWeaver a .pm if:
78              
79             1. There exists an # ABSTRACT: ...
80             2. The +PodWeaver hint is present
81              
82             If either condition is satisfied, PodWeavering will be done.
83              
84             You can forcefully disable PodWeaver on a .pm by using the C<-PodWeaver> hint
85              
86             =head1 AUTHORS
87              
88             =over 4
89              
90             =item *
91              
92             Robert Krimen <robertkrimen@gmail.com>
93              
94             =item *
95              
96             Dave Rolsky <autarch@urth.org>
97              
98             =back
99              
100             =head1 CONTRIBUTOR
101              
102             =for stopwords Robert Krimen
103              
104             Robert Krimen <rokr@cpan.org>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             This software is copyright (c) 2014 by Robert Krimen.
109              
110             This is free software; you can redistribute it and/or modify it under
111             the same terms as the Perl 5 programming language system itself.
112              
113             =cut