File Coverage

blib/lib/Dist/Zilla/PluginBundle/Author/AJNN/Readme.pm
Criterion Covered Total %
statement 68 69 98.5
branch 5 6 83.3
condition 4 6 66.6
subroutine 18 18 100.0
pod 0 1 0.0
total 95 100 95.0


line stmt bran cond sub pod time code
1 2     2   1179 use 5.026;
  2         7  
2 2     2   12 use warnings;
  2         21  
  2         94  
3              
4             # ABSTRACT: Build a README file for AJNN's distributions
5             $Dist::Zilla::PluginBundle::Author::AJNN::Readme::VERSION = '0.02';
6              
7             use Dist::Zilla;
8 2     2   10 use Dist::Zilla::File::FromCode;
  2         4  
  2         43  
9 2     2   788 use Encode;
  2         119462  
  2         66  
10 2     2   15 use Moose;
  2         6  
  2         187  
11 2     2   16 use namespace::autoclean;
  2         4  
  2         10  
12 2     2   10962 use Pod::Elemental;
  2         4  
  2         12  
13 2     2   652 use Pod::Text;
  2         453873  
  2         36  
14 2     2   1799  
  2         59595  
  2         145  
15             use Pod::Weaver::PluginBundle::Author::AJNN::License;
16 2     2   464  
  2         7  
  2         1364  
17             with 'Dist::Zilla::Role::FileGatherer';
18              
19              
20             my ($self, $arg) = @_;
21            
22 1     1 0 376670 $self->add_file(
23             Dist::Zilla::File::FromCode->new(
24             name => 'README',
25             code => sub { $self->_readme },
26             ),
27 1     1   36483 );
28 1         29 }
29              
30              
31             my ($self) = @_;
32            
33             return join "\n\n", (
34 1     1   3 $self->_readme_header,
35             $self->_readme_install,
36 1         5 $self->_readme_license,
37             );
38             }
39              
40              
41             my ($self) = @_;
42            
43             my $main_module = $self->_main_module_name;
44             my $dist_version = $self->zilla->version;
45 1     1   2 my $dist_name = $self->zilla->name;
46             my $trial_rel = $self->zilla->is_trial ? " (TRIAL RELEASE)" : "";
47 1         5
48 1         25 my $description = $self->_main_module_description;
49 1         49 $description =~ s/\n\n.*$//; # only keep the first paragraph
50 1 50       48
51             return <<END;
52 1         37 $main_module $dist_version$trial_rel
53 1         816  
54             $description
55 1         9  
56             More information about this software:
57             https://metacpan.org/release/$dist_name
58             END
59             }
60              
61              
62             my ($self) = @_;
63            
64             my $main_module = $self->_main_module_name;
65            
66             return <<END;
67 1     1   4 INSTALLATION
68              
69 1         3 The recommended way to install this Perl module distribution is directly
70             from CPAN with whichever tool you use to manage your installation of Perl.
71 1         5 For example:
72              
73             cpanm $main_module
74              
75             If you already have downloaded the distribution, you can alternatively
76             point your tool directly at the archive file or the directory:
77              
78             cpanm .
79              
80             You can also install the module manually by following these steps:
81              
82             perl Makefile.PL
83             make
84             make test
85             make install
86              
87             See https://www.cpan.org/modules/INSTALL.html for general information
88             on installing CPAN modules.
89             END
90             }
91              
92              
93             my ($self) = @_;
94            
95             my $notice = Pod::Weaver::PluginBundle::Author::AJNN::License->notice_maybe_mangled(
96             $self->zilla->license,
97             $self->zilla->authors,
98             );
99 1     1   3 return "COPYRIGHT AND LICENSE\n\n" . $notice;
100             }
101 1         24  
102              
103             my ($self) = @_;
104            
105 1         13 my $name = $self->zilla->main_module->name;
106             $name =~ s{^lib/|\.pm$}{}g;
107             $name =~ s{/}{::}g;
108             return $name;
109             }
110 2     2   5  
111            
112 2         52 my ($self) = @_;
113 2         165
114 2         5 my $pod = $self->zilla->main_module->content;
115 2         6 $pod = Encode::encode( 'UTF-8', $pod, Encode::FB_CROAK );
116             my $document = Pod::Elemental->read_string( $pod );
117             my $desc_found;
118             for my $element ($document->children->@*) {
119             if ($desc_found) {
120 1     1   3 next unless $element->isa('Pod::Elemental::Element::Generic::Text');
121             my $parser = Pod::Text->new( indent => 0 );
122 1         23 $parser->output_string( \( my $text ) );
123 1         88 $parser->parse_string_document( "=pod\n\n" . $element->content );
124 1         59 $text =~ s/^\s+//;
125 1         8585 $text =~ s/\s+$//;
126 1         26 return $text || $self->zilla->abstract;
127 16 100       174 }
128 2 100       9 $desc_found = $element->isa('Pod::Elemental::Element::Generic::Command')
129 1         11 && $element->command eq 'head1'
130 1         182 && $element->content =~ m/\s*DESCRIPTION\s*/;
131 1         956 }
132 1         821
133 1         6 return $self->zilla->abstract;
134 1   33     49 }
135              
136 14   100     158  
137             __PACKAGE__->meta->make_immutable;
138              
139             1;
140              
141 0            
142             =pod
143              
144             =encoding UTF-8
145              
146             =head1 NAME
147              
148             Dist::Zilla::PluginBundle::Author::AJNN::Readme - Build a README file for AJNN's distributions
149              
150             =head1 VERSION
151              
152             version 0.02
153              
154             =head1 DESCRIPTION
155              
156             Provides a F<README> file which only contains the most important information
157             for someone who may have extracted the distribution archive, but is unsure
158             what it is and what to do with it.
159              
160             In particular, the following content is included in the F<README>:
161              
162             =over
163              
164             =item * main module name
165              
166             =item * distribution version number
167              
168             =item * first paragraph of the distribution POD's description section
169             (or the abstract, if the description can't be found or is empty)
170              
171             =item * URL of the distribution's home page on MetaCPAN
172              
173             =item * installation instructions (for both tools and manual)
174              
175             =item * author identification
176              
177             =item * license statement
178              
179             =back
180              
181             It may be assumed that people who are already familiar with Perl and
182             its ecosystem won't usually read the F<README> accompanying a CPAN
183             distribution. They typically get all they need to know from MetaCPAN,
184             and are accustomed to C<cpanm> and other tools. Non-Perl people, however,
185             might not know how to install a Perl distribution or how to access the
186             documentation. In my opinion, I<this> is the information a CPAN distro
187             F<README> really needs to provide.
188              
189             Identification of the module, on the other hand, may be kept very brief.
190             A license file is included with the distribution, so stating the license
191             is generally not required; however, this plugin will pick up any mangling
192             done by L<Pod::Weaver::PluginBundle::Author::AJNN::License>.
193              
194             =head1 SEE ALSO
195              
196             L<Dist::Zilla::PluginBundle::Author::AJNN>
197              
198             L<Pod::Weaver::PluginBundle::Author::AJNN::License>
199              
200             L<Dist::Zilla::Plugin::Readme>
201              
202             L<Dist::Zilla::Plugin::Readme::Brief>
203              
204             =head1 AUTHOR
205              
206             Arne Johannessen <ajnn@cpan.org>
207              
208             If you contact me by email, please make sure you include the word
209             "Perl" in your subject header to help beat the spam filters.
210              
211             =head1 COPYRIGHT AND LICENSE
212              
213             Arne Johannessen has dedicated the work to the Commons by waiving all of his
214             or her rights to the work worldwide under copyright law and all related or
215             neighboring legal rights he or she had in the work, to the extent allowable by
216             law.
217              
218             Works under CC0 do not require attribution. When citing the work, you should
219             not imply endorsement by the author.
220              
221             =cut