File Coverage

blib/lib/Dist/Zilla/Plugin/Pod2Readme.pm
Criterion Covered Total %
statement 30 30 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 38 40 95.0


line stmt bran cond sub pod time code
1 1     1   2094703 use 5.008;
  1         3  
2 1     1   5 use strict;
  1         0  
  1         22  
3 1     1   3 use warnings;
  1         1  
  1         53  
4              
5             package Dist::Zilla::Plugin::Pod2Readme;
6             # ABSTRACT: Generate README from Pod, as simply as possible
7              
8             our $VERSION = '0.003'; # TRIAL
9              
10 1     1   4 use Dist::Zilla 5 ();
  1         16  
  1         15  
11              
12 1     1   3 use Moose;
  1         1  
  1         6  
13             with 'Dist::Zilla::Role::FileGatherer';
14              
15             #pod =attr filename
16             #pod
17             #pod Name for the generated README. Defaults to 'README'.
18             #pod
19             #pod =cut
20              
21             has filename => (
22             is => 'ro',
23             isa => 'Str',
24             default => 'README'
25             );
26              
27             #pod =attr source_filename
28             #pod
29             #pod The file from which to extract POD for the content of the README. Defaults to
30             #pod the main module of the distribution.
31             #pod
32             #pod =cut
33              
34             has source_filename => (
35             is => 'ro',
36             isa => 'Str',
37             lazy => 1,
38             default => sub { $_[0]->zilla->main_module->name }
39             );
40              
41             sub gather_files {
42 2     2 0 86328 my $self = shift;
43              
44 2         528 require Dist::Zilla::File::FromCode;
45 2         49714 require Pod::Text;
46 2         22937 require List::Util;
47              
48             $self->add_file(
49             Dist::Zilla::File::FromCode->new(
50             {
51             name => $self->filename,
52             code => sub {
53 2     2   44660 my $parser = Pod::Text->new();
54 2         301 $parser->output_string( \( my $text ) );
55 2         1015 my $filename = $self->source_filename;
56 2         10 my $source = List::Util::first { $_->name eq $filename } @{ $self->zilla->files };
  5         150  
  2         49  
57 2 50       65 $self->log_fatal("File $filename not found to extract readme")
58             unless defined $source;
59 2         9 my $pod = $source->content;
60 2         757 $parser->parse_string_document($pod);
61 2         2545 return $text;
62             },
63             }
64             )
65 2         90 );
66              
67 2         985 return;
68             }
69              
70             1;
71              
72              
73             # vim: ts=4 sts=4 sw=4 et tw=75:
74              
75             __END__
76              
77             =pod
78              
79             =encoding UTF-8
80              
81             =head1 NAME
82              
83             Dist::Zilla::Plugin::Pod2Readme - Generate README from Pod, as simply as possible
84              
85             =head1 VERSION
86              
87             version 0.003
88              
89             =head1 SYNOPSIS
90              
91             # in dist.ini
92             [Pod2Readme]
93              
94             =head1 DESCRIPTION
95              
96             This module generates a text F<README> file from the POD of your
97             main module.
98              
99             =head1 ATTRIBUTES
100              
101             =head2 filename
102              
103             Name for the generated README. Defaults to 'README'.
104              
105             =head2 source_filename
106              
107             The file from which to extract POD for the content of the README. Defaults to
108             the main module of the distribution.
109              
110             =for Pod::Coverage gather_files
111              
112             =head1 SEE ALSO
113              
114             =over 4
115              
116             =item *
117              
118             L<Dist::Zilla::Plugin::Readme> - bare bones boilerplate README
119              
120             =item *
121              
122             L<Dist::Zilla::Plugin::ReadmeFromPod> - overly complex version of this
123              
124             =item *
125              
126             L<Dist::Zilla::Plugin::ReadmeAnyFromPod> - overly complex, but does multiple file types
127              
128             =back
129              
130             =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
131              
132             =head1 SUPPORT
133              
134             =head2 Bugs / Feature Requests
135              
136             Please report any bugs or feature requests through the issue tracker
137             at L<https://github.com/dagolden/Dist-Zilla-Plugin-Pod2Readme/issues>.
138             You will be notified automatically of any progress on your issue.
139              
140             =head2 Source Code
141              
142             This is open source software. The code repository is available for
143             public review and contribution under the terms of the license.
144              
145             L<https://github.com/dagolden/Dist-Zilla-Plugin-Pod2Readme>
146              
147             git clone https://github.com/dagolden/Dist-Zilla-Plugin-Pod2Readme.git
148              
149             =head1 AUTHOR
150              
151             David Golden <dagolden@cpan.org>
152              
153             =head1 CONTRIBUTORS
154              
155             =for stopwords Dan Book David Golden
156              
157             =over 4
158              
159             =item *
160              
161             Dan Book <grinnz@grinnz.com>
162              
163             =item *
164              
165             David Golden <xdg@xdg.me>
166              
167             =back
168              
169             =head1 COPYRIGHT AND LICENSE
170              
171             This software is Copyright (c) 2014 by David Golden.
172              
173             This is free software, licensed under:
174              
175             The Apache License, Version 2.0, January 2004
176              
177             =cut