File Coverage

blib/lib/Dist/Zilla/Plugin/PodnameFromClassname.pm
Criterion Covered Total %
statement 5 18 27.7
branch 0 2 0.0
condition n/a
subroutine 2 4 50.0
pod 0 2 0.0
total 7 26 26.9


line stmt bran cond sub pod time code
1 1     1   14211 use 5.10.1;
  1         3  
2              
3             our $VERSION = '0.1002'; # VERSION
4             # ABSTRACT: Insert PODNAME for Moops classes.
5              
6             package Dist::Zilla::Plugin::PodnameFromClassname;
7              
8 1     1   476 use Moose;
  1         320093  
  1         6  
9             with ('Dist::Zilla::Role::FileMunger', 'Dist::Zilla::Role::FileFinderUser' => { default_finders => [':InstallModules']});
10              
11             sub munge_files {
12 0     0 0   my $self = shift;
13 0           $self->munge_file($_) for @{ $self->found_files };
  0            
14             }
15              
16             sub munge_file {
17 0     0 0   my $self = shift;
18 0           my $file = shift;
19 0           my $content = $file->content;
20 0 0         if($content !~ m{\v\h*#\h+PODCLASSNAME:?\h*\v.*?\v\h*(?:(?:class)|(?:library)|(?:namespace)|(?:role)) +([a-zA-Z][a-zA-Z0-9_]*(?:::[a-zA-Z][a-zA-Z0-9_]*)*)}ms) {
21 0           $self->log_debug(["Skipping %s, no # PODCLASSNAME directive found", $file->name]);
22 0           return;
23             }
24              
25 0           my $classname = $1;
26              
27 0           $content =~ s{(\v\h*)(#\h+PODCLASSNAME:?)(?=\h*\v)}{$1# PODNAME: $classname};
28 0           $self->log(["Inserting podname for $classname"]);
29 0           $file->content($content);
30             }
31              
32             1;
33              
34             __END__
35              
36             =pod
37              
38             =encoding UTF-8
39              
40             =head1 NAME
41              
42             Dist::Zilla::Plugin::PodnameFromClassname - Insert PODNAME for Moops classes.
43              
44             =head1 VERSION
45              
46             Version 0.1002, released 2015-01-15.
47              
48             =head1 SYNOPSIS
49              
50             In dist.ini:
51              
52             [PodnameFromClassname]
53              
54             In a L<Moops> class:
55              
56             # PODCLASSNAME
57              
58             class My::Class { ... }
59              
60             Results in:
61              
62             # PODNAME: My::Class
63              
64             class My::Class { ... }
65              
66             =head1 DESCRIPTION
67              
68             Dist::Zilla::Plugin::PodnameFromClassname is useful together with L<Moops> and L<Pod::Weaver>. Since Moops classes generally don't also have a C<package> statement C<Pod::Weaver> can't pick up the module name.
69              
70             Using this plugin and adding a C<# PODCLASSNAME> directive fixes that. It replaces that directive with C<# PODNAME: $classname>.
71              
72             There are a few simple rules:
73              
74             =over 4
75              
76             =item *
77              
78             There must be at least one line (of anything) before the C<# PODCLASSNAME> directive.
79              
80             =item *
81              
82             There must be at least one line (of anything) between the C<# PODCLASSNAME> directive and the C<class> statement.
83              
84             =item *
85              
86             The C<# PODCLASSNAME> directive must be before the C<class> statement.
87              
88             =back
89              
90             =head1 SEE ALSO
91              
92             =over 4
93              
94             =item *
95              
96             L<Dist::Zilla::Plugin::PodnameFromFilename>
97              
98             =item *
99              
100             L<Dist::Zilla>
101              
102             =back
103              
104             =head1 SOURCE
105              
106             L<https://github.com/Csson/p5-Dist-Zilla-Plugin-PodnameFromClassname>
107              
108             =head1 HOMEPAGE
109              
110             L<https://metacpan.org/release/Dist-Zilla-Plugin-PodnameFromClassname>
111              
112             =head1 AUTHOR
113              
114             Erik Carlsson <info@code301.com>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut