line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::ReadmeFromPod; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:FAYLAND'; |
3
|
|
|
|
|
|
|
$Dist::Zilla::Plugin::ReadmeFromPod::VERSION = '0.37'; |
4
|
1
|
|
|
1
|
|
99088
|
use Moose; |
|
1
|
|
|
|
|
479013
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
7731
|
use List::Util 1.33 qw( first ); |
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
115
|
|
6
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::InstallTool' => { -version => 5 }; # after PodWeaver |
7
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FilePruner'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
719
|
use IO::String; |
|
1
|
|
|
|
|
3929
|
|
|
1
|
|
|
|
|
41
|
|
10
|
1
|
|
|
1
|
|
559
|
use Pod::Readme 'v1.2.0'; |
|
1
|
|
|
|
|
289718
|
|
|
1
|
|
|
|
|
57
|
|
11
|
1
|
|
|
1
|
|
11
|
use Path::Tiny 0.004; |
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
852
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has filename => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'Str', |
16
|
|
|
|
|
|
|
lazy => 1, |
17
|
|
|
|
|
|
|
builder => '_build_filename', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_filename { |
21
|
0
|
|
|
0
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
# copied from Dist::Zilla::Plugin::ReadmeAnyFromPod |
23
|
0
|
|
|
|
|
|
my $pm = $self->zilla->main_module->name; |
24
|
0
|
|
|
|
|
|
(my $pod = $pm) =~ s/\.pm$/\.pod/; |
25
|
0
|
0
|
|
|
|
|
return -e $pod ? $pod : $pm; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has type => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
default => 'text', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %FORMATS = ( |
35
|
|
|
|
|
|
|
'gfm' => { class => 'Pod::Markdown::Github' }, |
36
|
|
|
|
|
|
|
'github' => { class => 'Pod::Markdown::Github' }, |
37
|
|
|
|
|
|
|
'html' => { class => 'Pod::Simple::HTML' }, |
38
|
|
|
|
|
|
|
'markdown' => { class => 'Pod::Markdown' }, |
39
|
|
|
|
|
|
|
'pod' => { class => undef }, |
40
|
|
|
|
|
|
|
'rtf' => { class => 'Pod::Simple::RTF' }, |
41
|
|
|
|
|
|
|
'text' => { class => 'Pod::Simple::Text' }, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has pod_class => ( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
47
|
|
|
|
|
|
|
lazy => 1, |
48
|
|
|
|
|
|
|
builder => '_build_pod_class', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_pod_class { |
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
53
|
0
|
0
|
|
|
|
|
my $fmt = $FORMATS{$self->type} |
54
|
|
|
|
|
|
|
or $self->log_fatal("Unsupported type: " . $self->type); |
55
|
0
|
|
|
|
|
|
$fmt->{class}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has readme => ( |
59
|
|
|
|
|
|
|
is => 'ro', |
60
|
|
|
|
|
|
|
isa => 'Str', |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub prune_files { |
64
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
65
|
0
|
|
|
0
|
|
|
my $readme_file = first { $_->name =~ m{^README\z} } @{ $self->zilla->files }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if ($readme_file and $readme_file->added_by =~ /Dist::Zilla::Plugin::Readme/) { |
67
|
0
|
|
|
|
|
|
$self->log_debug([ 'pruning %s', $readme_file->name ]); |
68
|
0
|
|
|
|
|
|
$self->zilla->prune_file($readme_file); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub setup_installer { |
73
|
0
|
|
|
0
|
0
|
|
my ($self, $arg) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $pod_class = $self->pod_class; |
76
|
0
|
|
|
|
|
|
my $readme_name = $self->readme; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
## guess pod_class from exisiting file, like GitHub will have README.md created |
79
|
0
|
|
|
|
|
|
my $readme_file; |
80
|
0
|
0
|
|
|
|
|
if (not $readme_name) { |
81
|
0
|
|
|
|
|
|
my %ext = ( |
82
|
|
|
|
|
|
|
'md' => 'markdown', |
83
|
|
|
|
|
|
|
'mkdn' => 'markdown', |
84
|
|
|
|
|
|
|
'markdown' => 'markdown', |
85
|
|
|
|
|
|
|
'html' => 'html', |
86
|
|
|
|
|
|
|
'htm' => 'html', |
87
|
|
|
|
|
|
|
'rtf' => 'rtf', |
88
|
|
|
|
|
|
|
'txt' => 'text', |
89
|
|
|
|
|
|
|
'' => 'text', |
90
|
|
|
|
|
|
|
'pod' => 'pod' |
91
|
|
|
|
|
|
|
); |
92
|
0
|
|
|
|
|
|
foreach my $e (keys %ext) { |
93
|
0
|
0
|
|
|
|
|
my $test_readme_file = path($self->zilla->root)->child($e ? "README.$e" : 'README'); |
94
|
0
|
0
|
|
|
|
|
if (-e "$test_readme_file") { |
95
|
0
|
|
|
|
|
|
$readme_file = $test_readme_file; |
96
|
0
|
|
|
|
|
|
$pod_class = $FORMATS{ $ext{$e} }->{class}; |
97
|
0
|
|
|
|
|
|
last; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $content; |
103
|
0
|
|
|
|
|
|
my $prf = Pod::Readme->new( |
104
|
|
|
|
|
|
|
input_file => $self->filename, |
105
|
|
|
|
|
|
|
translate_to_fh => IO::String->new($content), |
106
|
|
|
|
|
|
|
translation_class => $pod_class, |
107
|
|
|
|
|
|
|
force => 1, |
108
|
|
|
|
|
|
|
zilla => $self->zilla, |
109
|
|
|
|
|
|
|
); |
110
|
0
|
|
|
|
|
|
$prf->run(); |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ($readme_file) { |
113
|
0
|
|
|
|
|
|
return $readme_file->spew_raw($content); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
0
|
|
|
|
$readme_name ||= $prf->default_readme_file; |
117
|
0
|
|
|
0
|
|
|
my $file = first { $_->name eq $readme_name } @{ $self->zilla->files }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( $file ) { |
119
|
0
|
|
|
|
|
|
$file->content( $content ); |
120
|
0
|
|
|
|
|
|
$self->zilla->log("Override README from [ReadmeFromPod]"); |
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
|
|
|
|
|
require Dist::Zilla::File::InMemory; |
123
|
0
|
|
|
|
|
|
$file = Dist::Zilla::File::InMemory->new({ |
124
|
|
|
|
|
|
|
content => $content, |
125
|
|
|
|
|
|
|
name => "${readme_name}", # stringify, as it may be Path::Tiny |
126
|
|
|
|
|
|
|
}); |
127
|
0
|
|
|
|
|
|
$self->add_file($file); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
1
|
|
10
|
no Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
134
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 NAME |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Dist::Zilla::Plugin::ReadmeFromPod - dzil plugin to generate README from POD |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SYNOPSIS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# dist.ini |
145
|
|
|
|
|
|
|
[ReadmeFromPod] |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# or |
148
|
|
|
|
|
|
|
[ReadmeFromPod] |
149
|
|
|
|
|
|
|
filename = lib/XXX.pod |
150
|
|
|
|
|
|
|
type = markdown |
151
|
|
|
|
|
|
|
readme = READTHIS.md |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 DESCRIPTION |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This plugin generates the F<README> from C<main_module> (or specified) |
156
|
|
|
|
|
|
|
by L<Pod::Readme>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 Options |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The following options are supported: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head3 C<filename> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
The name of the file to extract the F<README> from. This defaults to |
165
|
|
|
|
|
|
|
the main module of the distribution. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head3 C<type> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The type of F<README> you want to generate. This defaults to "text". |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Other options are "html", "pod", "markdown" and "rtf". |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head3 C<pod_class> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is the L<Pod::Simple> class used to translate a file to the |
176
|
|
|
|
|
|
|
format you want. The default is based on the L</type> setting, but if |
177
|
|
|
|
|
|
|
you want to generate an alternative type, you can set this option |
178
|
|
|
|
|
|
|
instead. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head3 C<readme> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
The name of the file, which defaults to one based on the L</type>. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 Conflicts with Other Plugins |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
We will remove the README created by L<Dist::Zilla::Plugin::Readme> automatically. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHORS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Fayland Lam <fayland@gmail.com> and |
191
|
|
|
|
|
|
|
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Robert Rothenberg <rrwo@cpan.org> modified this plugin to use |
194
|
|
|
|
|
|
|
L<Pod::Readme>. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright 2010-2014 Fayland Lam <fayland@gmail.com> and E<AElig>var |
199
|
|
|
|
|
|
|
ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify |
202
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |