line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::ReadmeAddDevInfo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Dist::Zilla::Plugin::ReadmeAddDevInfo - add info how to contribute to the project |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
17122873
|
use v5.10; |
|
5
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
34
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
166
|
|
8
|
5
|
|
|
5
|
|
34
|
use warnings; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
180
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
46
|
use Moose; |
|
5
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
43
|
|
11
|
5
|
|
|
5
|
|
35157
|
use Moose::Util::TypeConstraints qw(enum role_type); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
51
|
|
12
|
5
|
|
|
5
|
|
2798
|
use namespace::autoclean; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
50
|
|
13
|
5
|
|
|
5
|
|
413
|
use Dist::Zilla::File::OnDisk; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
177
|
|
14
|
5
|
|
|
5
|
|
39
|
use Dist::Zilla::File::InMemory; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
129
|
|
15
|
5
|
|
|
5
|
|
29
|
use Path::Tiny; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
6836
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# same as Dist::Zilla::Plugin::ReadmeAnyFromPod |
20
|
|
|
|
|
|
|
with qw( |
21
|
|
|
|
|
|
|
Dist::Zilla::Role::AfterBuild |
22
|
|
|
|
|
|
|
Dist::Zilla::Role::AfterRelease |
23
|
|
|
|
|
|
|
Dist::Zilla::Role::FileMunger |
24
|
|
|
|
|
|
|
Dist::Zilla::Role::FileInjector |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has _file_obj => ( |
28
|
|
|
|
|
|
|
is => 'rw', isa => role_type('Dist::Zilla::Role::File'), |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has phase => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => enum([qw(build release filemunge)]), |
34
|
|
|
|
|
|
|
default => 'build', |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has before => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
isa => 'Str', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has add_contribution_file => ( |
43
|
|
|
|
|
|
|
is => 'ro', |
44
|
|
|
|
|
|
|
isa => 'Str', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has contribution_file => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
lazy => 1, |
50
|
|
|
|
|
|
|
default => sub { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my @candidates = qw/ CONTRIBUTING.md CONTRIBUTING /; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# only for the filemunge phase do we look |
55
|
|
|
|
|
|
|
# in the slurped files |
56
|
|
|
|
|
|
|
if( $self->phase eq 'filemunge' ) { |
57
|
|
|
|
|
|
|
for my $file ( @{ $self->zilla->files } ) { |
58
|
|
|
|
|
|
|
return $file if grep { $file->name eq $_ } @candidates; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
|
|
|
|
|
|
# for the other phases we look on disk |
63
|
|
|
|
|
|
|
my $root = path($self->zilla->root); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return Dist::Zilla::File::OnDisk->new( |
66
|
|
|
|
|
|
|
name => "$_", |
67
|
|
|
|
|
|
|
content => $_->slurp_raw, |
68
|
|
|
|
|
|
|
encoding => 'bytes', |
69
|
|
|
|
|
|
|
) for grep { -f $_ } map { $root->child($_) } @candidates |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if ( $self->add_contribution_file ) { |
73
|
|
|
|
|
|
|
my $file = Dist::Zilla::File::InMemory->new( |
74
|
|
|
|
|
|
|
content => '', |
75
|
|
|
|
|
|
|
name => 'CONTRIBUTING.md', |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$self->add_file( $self->_file_obj( $file ) ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return $file; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has readme_file => ( |
86
|
|
|
|
|
|
|
is => 'ro', |
87
|
|
|
|
|
|
|
lazy => 1, |
88
|
|
|
|
|
|
|
default => sub { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
my @candidates = qw/ README.md README.mkdn README.markdown /; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# only for the filemunge phase do we look |
93
|
|
|
|
|
|
|
# in the slurped files |
94
|
|
|
|
|
|
|
if( $self->phase eq 'filemunge' ) { |
95
|
|
|
|
|
|
|
for my $file ( @{ $self->zilla->files } ) { |
96
|
|
|
|
|
|
|
return $file if grep { $file->name eq $_ } @candidates; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
|
|
|
|
|
|
# for the other phases we look on disk |
101
|
|
|
|
|
|
|
my $root = path($self->zilla->root); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return Dist::Zilla::File::OnDisk->new( |
104
|
|
|
|
|
|
|
name => "$_", |
105
|
|
|
|
|
|
|
content => $_->slurp_raw, |
106
|
|
|
|
|
|
|
encoding => 'bytes', |
107
|
|
|
|
|
|
|
) for grep { -f $_ } map { $root->child($_) } @candidates |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$self->log_fatal('README file not found') if !$self->{contributing_file_only}; |
111
|
|
|
|
|
|
|
}, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub after_build { |
115
|
11
|
|
|
11
|
1
|
325244
|
my ($self) = @_; |
116
|
11
|
100
|
|
|
|
523
|
$self->add_info if $self->phase eq 'build'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub after_release { |
120
|
8
|
|
|
8
|
1
|
838580
|
my ($self) = @_; |
121
|
8
|
100
|
|
|
|
596
|
$self->add_info if $self->phase eq 'release'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub munge_files { |
125
|
11
|
|
|
11
|
1
|
1283294
|
my $self = shift; |
126
|
|
|
|
|
|
|
|
127
|
11
|
100
|
|
|
|
485
|
$self->add_info if $self->phase eq 'filemunge'; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub add_info { |
131
|
11
|
|
|
11
|
1
|
44
|
my $self = shift; |
132
|
|
|
|
|
|
|
|
133
|
11
|
|
|
|
|
378
|
my $distname = $self->zilla->name; |
134
|
11
|
|
|
|
|
794
|
my $distmeta = $self->zilla->distmeta; |
135
|
11
|
|
|
|
|
28848
|
my $repository = $distmeta->{resources}->{repository}->{url}; |
136
|
|
|
|
|
|
|
|
137
|
11
|
100
|
|
|
|
62
|
return if !$repository; |
138
|
|
|
|
|
|
|
|
139
|
10
|
|
|
|
|
239
|
my ($base_url, $user_name, $repository_name) = ($repository =~ m{^\w+://(.*)/([^\/]+)/(.*?)(\.git|\/|$)}); |
140
|
|
|
|
|
|
|
|
141
|
10
|
100
|
|
|
|
95
|
return if !$repository_name; |
142
|
|
|
|
|
|
|
|
143
|
9
|
100
|
|
|
|
92
|
if ( '.git' ne substr $repository, -4 ) { |
144
|
8
|
|
|
|
|
46
|
$repository .= '.git'; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
9
|
|
|
|
|
124
|
my $info = qq~ |
148
|
|
|
|
|
|
|
# Development |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
The distribution is contained in a Git repository, so simply clone the |
151
|
|
|
|
|
|
|
repository |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
``` |
154
|
|
|
|
|
|
|
\$ git clone $repository |
155
|
|
|
|
|
|
|
``` |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
and change into the newly-created directory. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
``` |
160
|
|
|
|
|
|
|
\$ cd $repository_name |
161
|
|
|
|
|
|
|
``` |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
The project uses [`Dist::Zilla`](https://metacpan.org/pod/Dist::Zilla) to |
164
|
|
|
|
|
|
|
build the distribution, hence this will need to be installed before |
165
|
|
|
|
|
|
|
continuing: |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
``` |
168
|
|
|
|
|
|
|
\$ cpanm Dist::Zilla |
169
|
|
|
|
|
|
|
``` |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
To install the required prequisite packages, run the following set of |
172
|
|
|
|
|
|
|
commands: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
``` |
175
|
|
|
|
|
|
|
\$ dzil authordeps --missing | cpanm |
176
|
|
|
|
|
|
|
\$ dzil listdeps --author --missing | cpanm |
177
|
|
|
|
|
|
|
``` |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The distribution can be tested like so: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
``` |
182
|
|
|
|
|
|
|
\$ dzil test |
183
|
|
|
|
|
|
|
``` |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
To run the full set of tests (including author and release-process tests), |
186
|
|
|
|
|
|
|
add the `--author` and `--release` options: |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
``` |
189
|
|
|
|
|
|
|
\$ dzil test --author --release |
190
|
|
|
|
|
|
|
``` |
191
|
|
|
|
|
|
|
~; |
192
|
|
|
|
|
|
|
|
193
|
9
|
100
|
|
|
|
504
|
if ( $self->add_contribution_file ) { |
194
|
5
|
|
|
|
|
202
|
my $contribution_file = $self->contribution_file; |
195
|
5
|
|
|
|
|
40
|
$contribution_file->content( $info ); |
196
|
|
|
|
|
|
|
|
197
|
5
|
100
|
|
|
|
1990
|
path( $contribution_file->name )->spew_raw( $contribution_file->encoded_content ) |
198
|
|
|
|
|
|
|
if $self->phase ne 'filemunge'; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
9
|
|
|
|
|
3389
|
my $readme = $self->readme_file; |
202
|
9
|
|
|
|
|
62
|
my $content = $readme->encoded_content; |
203
|
|
|
|
|
|
|
|
204
|
9
|
100
|
|
|
|
4832
|
if ( !$self->before ) { |
205
|
4
|
|
|
|
|
21
|
$content .= "\n\n$info"; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
5
|
|
|
|
|
207
|
my $before = $self->before; |
209
|
5
|
|
|
|
|
189
|
$content =~ s{^(\Q$before\E)}{\n$info\n$before}m; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
9
|
|
|
|
|
70
|
$readme->content($content); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# need to write it to disk if we're in a |
215
|
|
|
|
|
|
|
# phase that is not filemunge |
216
|
9
|
100
|
|
|
|
3394
|
path( $readme->name )->spew_raw( $readme->encoded_content ) |
217
|
|
|
|
|
|
|
if $self->phase ne 'filemunge'; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
__END__ |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=pod |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=encoding utf-8 |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 NAME |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Dist::Zilla::Plugin::ReadmeAddDevInfo - Dist::Zilla::Plugin::ReadmeAddDevInfo - add info how to contribute to the project |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 VERSION |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
version 0.03 |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 SYNOPSIS |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# in dist.ini |
239
|
|
|
|
|
|
|
[ReadmeAddDevInfo] |
240
|
|
|
|
|
|
|
phase = release |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 CONFIG |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 phase |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
[ReadmeAddDevInfo] |
247
|
|
|
|
|
|
|
phase = release |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Which Dist::Zilla phase to add the info: C<build>, C<release> or C<filemunge>. |
250
|
|
|
|
|
|
|
For the C<build> and C<release> phases, the README that is on disk will |
251
|
|
|
|
|
|
|
be modified, whereas for the C<filemunge> it's the internal zilla version of |
252
|
|
|
|
|
|
|
the README that will be modified. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
The default is C<build>. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 before |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
[ReadmeAddDevInfo] |
259
|
|
|
|
|
|
|
before = # AUTHOR |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Where to put the info in. In this example the info is added before the |
262
|
|
|
|
|
|
|
"AUTHOR" section. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 add_contribution_file |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
[ReadmeAddDevInfo] |
267
|
|
|
|
|
|
|
add_contribution_file = 1 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Also add the info as I<CONTRIBUTING.md>. The information from this file |
270
|
|
|
|
|
|
|
is shown in L<MetaCPAN|https://metacpan.org> under the "How to contribute" link. |
271
|
|
|
|
|
|
|
E.g. for this dist: L<How to contribute|https://metacpan.org/contributing-to/Dist-Zilla-Plugin-ReadmeAddDevInfo>. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 METHODS |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 add_info |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 after_build |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 after_release |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head2 munge_files |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 SEE ALSO |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
L<Minilla>, L<Dist::Zilla::Plugin::TravisCI::StatusBadge> |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 AUTHOR |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Renee Baecker <reneeb@cpan.org> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
This software is Copyright (c) 2018 by Renee Baecker. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
This is free software, licensed under: |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=cut |