blib/lib/ShipIt/Step/Readme.pm

filter: Statementstmt 69.7% 30 / 43 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 66.6% 42 / 63 CC 7 SCAR 15.1
CC
7
Cov
64%
run
12.0
_get_instructions
3.3
_add_install_instructions
3.0
CRAP 4.5
↑ Summary
1 package ShipIt::Step::Readme;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Pod::Readme;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use ShipIt::Util qw(slurp write_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use base 'ShipIt::Step';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.03';
10 3 $VERSION = eval $VERSION;
11  
12 ################################################################################
13 # no check for dry run, because we quit anyway if we encounter an
14 # INSTALL / INSTALLATION section in Pod
15 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
16 0 my ($self, $state) = @_;
17 0 $state->pt->current_version; #should create $self->{ver_from} for us
18  
19 # change Distribution Module
20 0 my $dist_file = $state->pt->{ver_from};
21 0 ▶ die "no file for distribution found", $self->{ver_from} unless ($dist_file);
Branch: 1 branch
BranchTrueFalseTotal
unless $dist_file 0 0 0
22  
23 0 my $dist_content = slurp($dist_file);
24 0 ▶ if ($dist_content !~ /^=head1 INSTALL/mi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dist_content =~ /^=head1 INSTALL/im) 0 0 0
25 0 $dist_content = $self->_add_install_instructions($dist_content);
26 0 write_file($dist_file, $dist_content);
27 }
28  
29 0 my $parser = Pod::Readme->new();
30 0 $parser->parse_from_file($dist_file, 'README');
31  
32 0 return 1;
33 }
34  
35 ################################################################################
36 # put into extra sub made testing easier
37 3 ▶sub _add_install_instructions {
Subroutine _add_install_instructions: called CC=3 SCAR=11.0
38 3 my ($self, $dist_content) = @_;
39 3 my $install = $self->_get_instructions;
40 3 ▶ return $dist_content if ($dist_content =~ s/(^=head\d VERSION.*?(?=^=))/$1$install/sm);
Branch: 1 branch
BranchTrueFalseTotal
if $dist_content =~ s/(^=head\d VERSION.*?(?=^=))/$1$install/ms 1 2 3
41 2 ▶ return $dist_content if ($dist_content =~ s/(^=head\d NAME.*?(?=^=))/$1$install/sm);
Branch: 1 branch
BranchTrueFalseTotal
if $dist_content =~ s/(^=head\d NAME.*?(?=^=))/$1$install/ms 1 1 2
42 1 die ('trying to add pod Install section after VERSION or NAME Section, but there is none');
43 }
44  
45 ################################################################################
46 sub _build_instructions () {q~
47 perl Build.PL
48 ./Build
49 ./Build test
50 ./Build install
51 ~;}
52  
53 ################################################################################
54 sub _make_instructions () {q~
55 perl Makefile.PL
56 make
57 make test
58 make install
59 ~;}
60  
61 ################################################################################
62 3 ▶sub _get_instructions {
Subroutine _get_instructions: called CC=3 SCAR=11.9
63 3 my ($self) = @_;
64 3 my $instructions;
65 3 ▶ if (-e 'Build.PL') {
Branch: 2 branches
BranchTrueFalseTotal
if (-e 'Build.PL') { } 3 0 3
elsif (-e 'Makefile.PL') { } 0 0 0
66 3 $instructions = $self->_build_instructions ;
67 } elsif (-e 'Makefile.PL') {
68 0 $instructions = $self->_make_instructions;
69 } else {
70 0 die ('only Build.PL and Makefile.PL are supported, but none was found');
71 }
72  
73 # little bit awkward, but Pod-Parsers don't check for Pod inside strings
74 3 my $pod = "=begin readme\n\n";
75 3 $pod .= "=head1 INSTALLATION\n\n";
76 3 $pod .= "To install this module, run the following commands:\n";
77 3 $pod .= "$instructions\n";
78 3 $pod .= "=end readme\n\n";
79  
80 3 return $pod;
81 }
82  
83 3 1;
84  
85 =head1 NAME
86  
87 ShipIt::Step::Readme - Automatically create README for your Perl Package before releasing
88  
89 =head1 VERSION
90  
91 Version 0.03
92  
93 =begin readme
94  
95 =head1 INSTALLATION
96  
97 To install this module, run the following commands:
98  
99 perl Build.PL
100 ./Build
101 ./Build test
102 ./Build install
103  
104 =end readme
105  
106 =head1 SYNOPSIS
107  
108 Just add it to the ShipIt config, after all steps, that edit Pod, because
109 the README file is generated from the Pod of the distris' main file.
110  
111 steps = FindVersion, ChangeVersion, ChangePodVersion, Readme, ...
112  
113 And make sure you have a VERSION or a NAME section in your Pod. The README pod,
114 which is not visible on CPAN, is added after any of them.
115  
116 =head1 DESCRIPTION
117  
118 This ShipIt::Step autogenerates a README-file from your distris' main package.
119  
120 Therefore it adds a Pod INSTALLATION section, but only if it does not exist yet.
121 It contains installation instructions, for either an installation via ./Build or
122 an installation via make, depending on the existence of a Build.PL or a
123 Makefile.PL. If neither is found, we die.
124  
125 The Pod INSTALLATION section is added after the Pod VERSION section, or in case
126 it does not exist, after the Pod NAME section. If neither is found, we die.
127 This section won't be visible on CPAN, and will only appear in your README.
128  
129 B<Run this after any ShipIt::Step, that edits Pod.> For example
130 L<ShipIt::Step::ChangePodVersion> does that to add a Pod VERSION section
131 to your module. Otherwise the changes made won't be reflected in your README.
132  
133 =head1 CONFIG
134  
135 Nothing to configure. Drop me an EMail if you have any wishes for configuration.
136  
137 =head1 WARNING
138  
139 This is not really tested with distris, which dont't use Build.PL. But from
140 a logic point of view, there shouldn't be any problem. However, contact me if
141 you encounter any problems.
142  
143 =head1 AUTHOR
144  
145 Thomas Mueller, C<< <tmueller at cpan.org> >>
146  
147 =head1 BUGS
148  
149 Please report any bugs or feature requests to C<bug-shipit-step-readme at rt.cpan.org>, or through
150 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ShipIt-Step-Readme>. I will be notified, and then you'll
151 automatically be notified of progress on your bug as I make changes.
152  
153 =head1 SUPPORT
154  
155 You can find documentation for this module with the perldoc command.
156  
157 perldoc ShipIt::Step::Readme
158  
159  
160 You can also look for information at:
161  
162 =over 4
163  
164 =item * RT: CPAN's request tracker
165  
166 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ShipIt-Step-Readme>
167  
168 =item * AnnoCPAN: Annotated CPAN documentation
169  
170 L<http://annocpan.org/dist/ShipIt-Step-Readme>
171  
172 =item * CPAN Ratings
173  
174 L<http://cpanratings.perl.org/d/ShipIt-Step-Readme>
175  
176 =item * Search CPAN
177  
178 L<http://search.cpan.org/dist/ShipIt-Step-Readme/>
179  
180 =back
181  
182 =head1 LICENSE AND COPYRIGHT
183  
184 Copyright 2010 Thomas Mueller.
185  
186 This program is free software; you can redistribute it and/or modify it
187 under the terms of either: the GNU General Public License as published
188 by the Free Software Foundation; or the Artistic License.
189  
190 See http://dev.perl.org/licenses/ for more information.
191  
192  
193 =cut
↑ Summary