line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Readme::Plugin; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
2919
|
use v5.10.1; |
|
5
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
26
|
use Moo::Role; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v1.2.1'; |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
4170
|
use Class::Method::Modifiers qw/ fresh /; |
|
5
|
|
|
|
|
7323
|
|
|
5
|
|
|
|
|
292
|
|
10
|
5
|
|
|
5
|
|
2353
|
use Hash::Util qw/ lock_keys /; |
|
5
|
|
|
|
|
14079
|
|
|
5
|
|
|
|
|
31
|
|
11
|
5
|
|
|
5
|
|
1173
|
use Try::Tiny; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
236
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
31
|
use Pod::Readme::Types qw/ Indentation /; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
4132
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Pod::Readme::Plugin - Plugin role for Pod::Readme |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
L v1.0 and later supports plugins that extend the |
22
|
|
|
|
|
|
|
capabilities of the module. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 WRITING PLUGINS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Writing plugins is straightforward. Plugins are L modules |
27
|
|
|
|
|
|
|
in the C namespace. For example, |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Pod::Readme::Plugin::myplugin; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Moo::Role; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub cmd_myplugin { |
34
|
|
|
|
|
|
|
my ($self, @args) = @_; |
35
|
|
|
|
|
|
|
my $res = $self->parse_cmd_args( [qw/ arg1 arg2 /], @args ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
... |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
When L encounters POD with |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=for readme plugin myplugin arg1 arg2 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
the plugin role will be loaded, and the C method will be |
45
|
|
|
|
|
|
|
run. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Note that you do not need to specify a C method. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Any method prefixed with "cmd_" will be a command that can be called |
50
|
|
|
|
|
|
|
using the C<=for readme command> syntax. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
A plugin parses arguments using the L method and |
53
|
|
|
|
|
|
|
writes output using the write methods noted above. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
See some of the included plugins, such as |
56
|
|
|
|
|
|
|
L for examples. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Any attributes in the plugin should be prefixed with the name of the |
59
|
|
|
|
|
|
|
plugin, to avoid any conflicts with attribute and method names from |
60
|
|
|
|
|
|
|
other plugins, e.g. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Types::Standard qw/ Int /; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has 'myplugin_heading_level' => ( |
65
|
|
|
|
|
|
|
is => 'rw', |
66
|
|
|
|
|
|
|
isa => Int, |
67
|
|
|
|
|
|
|
default => 1, |
68
|
|
|
|
|
|
|
lazy => 1, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Attributes should be lazy to ensure that their defaults are properly |
72
|
|
|
|
|
|
|
set. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Be aware that changing default values of an attribute based on |
75
|
|
|
|
|
|
|
arguments means that the next time a plugin method is run, the |
76
|
|
|
|
|
|
|
defaults will be changed. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Custom types in L may be useful for attributes |
79
|
|
|
|
|
|
|
when writing plugins, e.g. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use Pod::Readme::Types qw/ File HeadingLevel /; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has 'myplugin_file' => ( |
84
|
|
|
|
|
|
|
is => 'rw', |
85
|
|
|
|
|
|
|
isa => File, |
86
|
|
|
|
|
|
|
coerce => sub { File->coerce(@_) }, |
87
|
|
|
|
|
|
|
default => 'Changes', |
88
|
|
|
|
|
|
|
lazy => 1, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# We add this file to the list of dependencies |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
around 'depends_on' => sub { |
94
|
|
|
|
|
|
|
my ($orig, $self) = @_; |
95
|
|
|
|
|
|
|
return ($self->myplugin_file, $self->$orig); |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 C |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
The number of columns to indent a verbatim paragraph. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
has verbatim_indent => ( |
107
|
|
|
|
|
|
|
is => 'ro', |
108
|
|
|
|
|
|
|
isa => Indentation, |
109
|
|
|
|
|
|
|
default => 2, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _parse_arguments { |
117
|
26
|
|
|
26
|
|
72
|
my ( $self, $line ) = @_; |
118
|
26
|
|
|
|
|
70
|
my @args = (); |
119
|
|
|
|
|
|
|
|
120
|
26
|
|
|
|
|
39
|
my $i = 0; |
121
|
26
|
|
|
|
|
41
|
my $prev; |
122
|
26
|
|
|
|
|
46
|
my $in_quote = ''; |
123
|
26
|
|
|
|
|
45
|
my $arg_buff = ''; |
124
|
26
|
|
|
|
|
75
|
while ( $i < length($line) ) { |
125
|
|
|
|
|
|
|
|
126
|
643
|
|
|
|
|
890
|
my $curr = substr( $line, $i, 1 ); |
127
|
643
|
100
|
100
|
|
|
1544
|
if ( $curr !~ m/\s/ || $in_quote ) { |
|
|
100
|
|
|
|
|
|
128
|
547
|
|
|
|
|
714
|
$arg_buff .= $curr; |
129
|
547
|
100
|
66
|
|
|
953
|
if ( $curr =~ /["']/ && $prev ne "\\" ) { |
130
|
13
|
100
|
|
|
|
32
|
$in_quote = ( $curr eq $in_quote ) ? '' : $curr; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
elsif ( $arg_buff ne '' ) { |
134
|
70
|
|
|
|
|
119
|
push @args, $arg_buff; |
135
|
70
|
|
|
|
|
92
|
$arg_buff = ''; |
136
|
|
|
|
|
|
|
} |
137
|
643
|
|
|
|
|
749
|
$prev = $curr; |
138
|
643
|
|
|
|
|
1005
|
$i++; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
26
|
100
|
|
|
|
65
|
if ( $arg_buff ne '' ) { |
142
|
1
|
|
|
|
|
3
|
push @args, $arg_buff; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
26
|
|
|
|
|
148
|
return @args; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 C |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $hash_ref = $self->parse_cmd_args( \@allowed_keys, @args); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This command parses arguments for a plugin and returns a hash |
153
|
|
|
|
|
|
|
reference containing the argument values. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The C<@args> parameter is a list of arguments passed to the command |
156
|
|
|
|
|
|
|
method by L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
If an argument contains an equals sign, then it is assumed to take a |
159
|
|
|
|
|
|
|
string. (Strings containing whitespace should be surrounded by |
160
|
|
|
|
|
|
|
quotes.) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Otherwise, an argument is assumed to be boolean, which defaults to |
163
|
|
|
|
|
|
|
true. If the argument is prefixed by "no-" or "no_" then it is given a |
164
|
|
|
|
|
|
|
false value. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
If the C<@allowed_keys> parameter is given, then it will reject |
167
|
|
|
|
|
|
|
argument keys that are not in that list. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
For example, |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $res = $self->parse_cmd_args( |
172
|
|
|
|
|
|
|
undef, |
173
|
|
|
|
|
|
|
'arg1', |
174
|
|
|
|
|
|
|
'no-arg2', |
175
|
|
|
|
|
|
|
'arg3="This is a string"', |
176
|
|
|
|
|
|
|
'arg4=value', |
177
|
|
|
|
|
|
|
); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
will return a hash reference containing |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
{ |
182
|
|
|
|
|
|
|
arg1 => 1, |
183
|
|
|
|
|
|
|
arg2 => 0, |
184
|
|
|
|
|
|
|
arg3 => 'This is a string', |
185
|
|
|
|
|
|
|
arg4 => 'value', |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub parse_cmd_args { |
191
|
14
|
|
|
14
|
1
|
12669
|
my ( $self, $allowed, @args ) = @_; |
192
|
|
|
|
|
|
|
|
193
|
14
|
|
|
|
|
29
|
my ( $key, $val, %res ); |
194
|
14
|
|
|
|
|
46
|
while ( my $arg = shift @args ) { |
195
|
|
|
|
|
|
|
|
196
|
20
|
|
|
|
|
45
|
state $eq = qr/=/; |
197
|
|
|
|
|
|
|
|
198
|
20
|
100
|
|
|
|
85
|
if ( $arg =~ $eq ) { |
199
|
13
|
|
|
|
|
55
|
( $key, $val ) = split $eq, $arg; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# TODO - better way to remove surrounding quotes |
202
|
13
|
100
|
66
|
|
|
92
|
if ( ( $val =~ /^(['"])(.*)(['"])$/ ) && ( $1 eq $3 ) ) { |
203
|
8
|
|
50
|
|
|
35
|
$val = $2 // ''; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
7
|
|
|
|
|
14
|
$val = 1; |
209
|
7
|
100
|
|
|
|
42
|
if ( ($key) = ( $arg =~ /^no[_-](\w+(?:[-_]\w+)*)$/ ) ) { |
210
|
4
|
|
|
|
|
11
|
$val = 0; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else { |
213
|
3
|
|
|
|
|
6
|
$key = $arg; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
20
|
|
|
|
|
70
|
$res{$key} = $val; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
14
|
100
|
|
|
|
46
|
if ($allowed) { |
221
|
|
|
|
|
|
|
try { |
222
|
13
|
|
|
13
|
|
985
|
lock_keys( %res, @{$allowed} ); |
|
13
|
|
|
|
|
56
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
catch { |
225
|
3
|
50
|
|
3
|
|
1782
|
if (/Hash has key '(.+)' which is not in the new key set/) { |
226
|
3
|
|
|
|
|
35
|
die sprintf( "Invalid argument key '\%s'\n", $1 ); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
else { |
229
|
0
|
|
|
|
|
0
|
die "Unknown error checking argument keys\n"; |
230
|
|
|
|
|
|
|
} |
231
|
13
|
|
|
|
|
105
|
}; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
11
|
|
|
|
|
563
|
return \%res; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 C |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
$self->write_verbatim($text); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
A utility method to write verbatim text, indented by |
242
|
|
|
|
|
|
|
L. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub write_verbatim { |
247
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $text ) = @_; |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
0
|
my $indent = ' ' x ( $self->verbatim_indent ); |
250
|
0
|
|
|
|
|
0
|
$text =~ s/^/${indent}/mg; |
251
|
0
|
|
|
|
|
0
|
$text =~ s/([^\n])\n?$/$1\n\n/; |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
0
|
$self->write($text); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=begin :internal |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 C<_write_cmd> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
$self->_write_cmd('=head1 SECTION'); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
An internal utility method to write a command line. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=end :internal |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=cut |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub _write_cmd { |
269
|
52
|
|
|
52
|
|
84
|
my ( $self, $text ) = @_; |
270
|
52
|
|
|
|
|
287
|
$text =~ s/([^\n])\n?$/$1\n\n/; |
271
|
|
|
|
|
|
|
|
272
|
52
|
|
|
|
|
142
|
$self->write($text); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 C |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
$self->write_para('This is a paragraph'); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Utility method to write a POD paragraph. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=cut |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
sub write_para { |
284
|
10
|
|
|
10
|
1
|
1100
|
my ( $self, $text ) = @_; |
285
|
10
|
|
50
|
|
|
22
|
$text //= ''; |
286
|
10
|
|
|
|
|
36
|
$self->write( $text . "\n\n" ); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head2 C |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head2 C |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 C |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head2 C |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head2 C |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head2 C |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 C |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head2 C |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head2 C |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head2 C |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head2 C |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head2 C |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=head2 C |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$self->write_head1($text); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Utility methods to write POD specific commands to the C. |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
These methods ensure the POD commands have extra newlines for |
320
|
|
|
|
|
|
|
compatibility with older POD parsers. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=cut |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
{ |
325
|
|
|
|
|
|
|
foreach my $cmd ( |
326
|
|
|
|
|
|
|
qw/ head1 head2 head3 head4 |
327
|
|
|
|
|
|
|
over item begin end for encoding / |
328
|
|
|
|
|
|
|
) |
329
|
|
|
|
|
|
|
{ |
330
|
|
|
|
|
|
|
fresh( |
331
|
|
|
|
|
|
|
"write_${cmd}" => sub { |
332
|
48
|
|
|
48
|
|
229
|
my ( $self, $text ) = @_; |
333
|
48
|
|
50
|
|
|
86
|
$text //= ''; |
334
|
48
|
|
|
|
|
144
|
$self->_write_cmd( '=' . $cmd . ' ' . $text ); |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
foreach my $cmd (qw/ pod back cut /) { |
340
|
|
|
|
|
|
|
fresh( |
341
|
|
|
|
|
|
|
"write_${cmd}" => sub { |
342
|
4
|
|
|
4
|
|
8
|
my ($self) = @_; |
343
|
4
|
|
|
|
|
13
|
$self->_write_cmd( '=' . $cmd ); |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
); |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
5
|
|
|
5
|
|
40
|
use namespace::autoclean; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
33
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
1; |