line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::PodPurler; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Dist::Zilla::Plugin::PodPurler::VERSION = '0.093401'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: like PodWeaver, but more erratic and amateurish |
6
|
1
|
|
|
1
|
|
1573
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Moose::Autobox 0.08; |
8
|
|
|
|
|
|
|
use List::MoreUtils qw(any); |
9
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileMunger'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use namespace::autoclean; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Pod::Elemental 0.092930; |
14
|
|
|
|
|
|
|
use Pod::Elemental::Selectors -all; |
15
|
|
|
|
|
|
|
use Pod::Elemental::Transformer::Pod5; |
16
|
|
|
|
|
|
|
use Pod::Elemental::Transformer::Nester; |
17
|
|
|
|
|
|
|
use Pod::Elemental::Transformer::Gatherer; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub munge_file { |
21
|
|
|
|
|
|
|
my ($self, $file) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $self->munge_pod($file) |
24
|
|
|
|
|
|
|
if $file->name =~ /\.(?:pm|pod)$/i |
25
|
|
|
|
|
|
|
and ($file->name !~ m{/} or $file->name =~ m{^lib/}); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub munge_perl_string { |
31
|
|
|
|
|
|
|
my ($self, $doc, $arg) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $document = $doc->{pod}; |
34
|
|
|
|
|
|
|
Pod::Elemental::Transformer::Pod5->new->transform_node($document); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $nester = Pod::Elemental::Transformer::Nester->new({ |
37
|
|
|
|
|
|
|
top_selector => s_command([ qw(head1 method attr) ]), |
38
|
|
|
|
|
|
|
content_selectors => [ |
39
|
|
|
|
|
|
|
s_flat, |
40
|
|
|
|
|
|
|
s_command( [ qw(head2 head3 head4 over item back) ]), |
41
|
|
|
|
|
|
|
], |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$nester->transform_node($document); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
for my $pair ( |
47
|
|
|
|
|
|
|
[ method => 'METHODS' ], |
48
|
|
|
|
|
|
|
[ attr => 'ATTRIBUTES' ], |
49
|
|
|
|
|
|
|
) { |
50
|
|
|
|
|
|
|
my $sel = s_command($pair->[0]); |
51
|
|
|
|
|
|
|
if ($document->children->grep($sel)->length) { |
52
|
|
|
|
|
|
|
my $gatherer = Pod::Elemental::Transformer::Gatherer->new({ |
53
|
|
|
|
|
|
|
gather_selector => $sel, |
54
|
|
|
|
|
|
|
container => Pod::Elemental::Element::Nested->new({ |
55
|
|
|
|
|
|
|
command => 'head1', |
56
|
|
|
|
|
|
|
content => "$pair->[1]\n", |
57
|
|
|
|
|
|
|
}), |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$gatherer->transform_node($document); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$gatherer->container->children->grep($sel)->each_value(sub { |
63
|
|
|
|
|
|
|
$_->command('head2'); |
64
|
|
|
|
|
|
|
}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
unless ( |
69
|
|
|
|
|
|
|
$document->children->grep(sub { |
70
|
|
|
|
|
|
|
s_command('head1', $_) and $_->content eq "VERSION\n" |
71
|
|
|
|
|
|
|
})->length |
72
|
|
|
|
|
|
|
) { |
73
|
|
|
|
|
|
|
my $version_section = Pod::Elemental::Element::Nested->new({ |
74
|
|
|
|
|
|
|
command => 'head1', |
75
|
|
|
|
|
|
|
content => "VERSION\n", |
76
|
|
|
|
|
|
|
children => [ |
77
|
|
|
|
|
|
|
Pod::Elemental::Element::Pod5::Ordinary->new({ |
78
|
|
|
|
|
|
|
content => sprintf "version %s\n", $self->zilla->version, |
79
|
|
|
|
|
|
|
}), |
80
|
|
|
|
|
|
|
], |
81
|
|
|
|
|
|
|
}); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$document->children->unshift($version_section); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
unless ( |
87
|
|
|
|
|
|
|
$document->children->grep(sub { |
88
|
|
|
|
|
|
|
s_command('head1', $_) and $_->content eq "NAME\n" |
89
|
|
|
|
|
|
|
})->length |
90
|
|
|
|
|
|
|
) { |
91
|
|
|
|
|
|
|
Carp::croak "couldn't find package declaration in " . $arg->{filename} |
92
|
|
|
|
|
|
|
unless my $pkg_node = $doc->{ppi}->find_first('PPI::Statement::Package'); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $package = $pkg_node->namespace; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->log("couldn't find abstract in " . $arg->{filename}) |
97
|
|
|
|
|
|
|
unless my ($abstract) = $doc->{ppi} =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $name = $package; |
100
|
|
|
|
|
|
|
$name .= " - $abstract" if $abstract; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $name_section = Pod::Elemental::Element::Nested->new({ |
103
|
|
|
|
|
|
|
command => 'head1', |
104
|
|
|
|
|
|
|
content => "NAME\n", |
105
|
|
|
|
|
|
|
children => [ |
106
|
|
|
|
|
|
|
Pod::Elemental::Element::Pod5::Ordinary->new({ |
107
|
|
|
|
|
|
|
content => "$name\n", |
108
|
|
|
|
|
|
|
}), |
109
|
|
|
|
|
|
|
], |
110
|
|
|
|
|
|
|
}); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$document->children->unshift($name_section); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
unless ( |
116
|
|
|
|
|
|
|
$document->children->grep(sub { |
117
|
|
|
|
|
|
|
s_command('head1', $_) and $_->content =~ /\AAUTHORS?\n\z/ |
118
|
|
|
|
|
|
|
})->length |
119
|
|
|
|
|
|
|
) { |
120
|
|
|
|
|
|
|
my @authors = $self->zilla->authors->flatten; |
121
|
|
|
|
|
|
|
my $name = @authors > 1 ? 'AUTHORS' : 'AUTHOR'; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $author_section = Pod::Elemental::Element::Nested->new({ |
124
|
|
|
|
|
|
|
command => 'head1', |
125
|
|
|
|
|
|
|
content => "$name\n", |
126
|
|
|
|
|
|
|
children => [ |
127
|
|
|
|
|
|
|
Pod::Elemental::Element::Pod5::Ordinary->new({ |
128
|
|
|
|
|
|
|
content => join("\n", @authors) . "\n" |
129
|
|
|
|
|
|
|
}), |
130
|
|
|
|
|
|
|
], |
131
|
|
|
|
|
|
|
}); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$document->children->push($author_section); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
unless ( |
137
|
|
|
|
|
|
|
$document->children->grep(sub { |
138
|
|
|
|
|
|
|
s_command('head1', $_) and $_->content =~ /\A(?:COPYRIGHT|LICENSE)\n\z/ |
139
|
|
|
|
|
|
|
})->length |
140
|
|
|
|
|
|
|
) { |
141
|
|
|
|
|
|
|
my $legal_section = Pod::Elemental::Element::Nested->new({ |
142
|
|
|
|
|
|
|
command => 'head1', |
143
|
|
|
|
|
|
|
content => "COPYRIGHT AND LICENSE\n", |
144
|
|
|
|
|
|
|
children => [ |
145
|
|
|
|
|
|
|
Pod::Elemental::Element::Pod5::Ordinary->new({ |
146
|
|
|
|
|
|
|
content => $self->zilla->license->notice |
147
|
|
|
|
|
|
|
}), |
148
|
|
|
|
|
|
|
], |
149
|
|
|
|
|
|
|
}); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$document->children->push($legal_section); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
return { |
155
|
|
|
|
|
|
|
pod => $document, |
156
|
|
|
|
|
|
|
ppi => $doc->{ppi}, |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub munge_pod { |
161
|
|
|
|
|
|
|
my ($self, $file) = @_; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my $content = $file->content; |
164
|
|
|
|
|
|
|
my $new_content = $self->munge_perl_string( |
165
|
|
|
|
|
|
|
$content, |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
filename => $file->name, |
168
|
|
|
|
|
|
|
}, |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$file->content($new_content); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
with 'Pod::Elemental::PerlMunger'; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
177
|
|
|
|
|
|
|
no Moose; |
178
|
|
|
|
|
|
|
1; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
__END__ |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=pod |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 NAME |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Dist::Zilla::Plugin::PodPurler - like PodWeaver, but more erratic and amateurish |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 VERSION |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
version 0.093401 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 DESCRIPTION |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
PodPurler ress, which rips apart your kinda-POD and reconstructs it as boring |
195
|
|
|
|
|
|
|
old real POD. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 WARNING |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This library has been superceded by L<Pod::Weaver> and |
200
|
|
|
|
|
|
|
L<Dist::Zilla::Plugin::PodWeaver>. It is unlikely to be updated again unless |
201
|
|
|
|
|
|
|
there are serious security problems (!?) or someone gives me some money. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@cpan.org> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Ricardo SIGNES. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
212
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |