line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Readme::Plugin; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
3330
|
use v5.10.1; |
|
5
|
|
|
|
|
20
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
30
|
use Moo::Role; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v1.2.2'; |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
4560
|
use Class::Method::Modifiers qw/ fresh /; |
|
5
|
|
|
|
|
8205
|
|
|
5
|
|
|
|
|
310
|
|
10
|
5
|
|
|
5
|
|
2706
|
use Hash::Util qw/ lock_keys /; |
|
5
|
|
|
|
|
13868
|
|
|
5
|
|
|
|
|
37
|
|
11
|
5
|
|
|
5
|
|
429
|
use Try::Tiny; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
254
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
32
|
use Pod::Readme::Types qw/ Indentation /; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
4721
|
|
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
|
|
69
|
my ( $self, $line ) = @_; |
118
|
26
|
|
|
|
|
83
|
my @args = (); |
119
|
|
|
|
|
|
|
|
120
|
26
|
|
|
|
|
52
|
my $i = 0; |
121
|
26
|
|
|
|
|
38
|
my $prev; |
122
|
26
|
|
|
|
|
55
|
my $in_quote = ''; |
123
|
26
|
|
|
|
|
51
|
my $arg_buff = ''; |
124
|
26
|
|
|
|
|
92
|
while ( $i < length($line) ) { |
125
|
|
|
|
|
|
|
|
126
|
643
|
|
|
|
|
908
|
my $curr = substr( $line, $i, 1 ); |
127
|
643
|
100
|
100
|
|
|
1681
|
if ( $curr !~ m/\s/ || $in_quote ) { |
|
|
100
|
|
|
|
|
|
128
|
547
|
|
|
|
|
776
|
$arg_buff .= $curr; |
129
|
547
|
100
|
66
|
|
|
1134
|
if ( $curr =~ /["']/ && $prev ne "\\" ) { |
130
|
13
|
100
|
|
|
|
32
|
$in_quote = ( $curr eq $in_quote ) ? '' : $curr; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
elsif ( $arg_buff ne '' ) { |
134
|
70
|
|
|
|
|
139
|
push @args, $arg_buff; |
135
|
70
|
|
|
|
|
100
|
$arg_buff = ''; |
136
|
|
|
|
|
|
|
} |
137
|
643
|
|
|
|
|
829
|
$prev = $curr; |
138
|
643
|
|
|
|
|
1072
|
$i++; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
26
|
100
|
|
|
|
88
|
if ( $arg_buff ne '' ) { |
142
|
1
|
|
|
|
|
3
|
push @args, $arg_buff; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
26
|
|
|
|
|
111
|
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
|
22426
|
my ( $self, $allowed, @args ) = @_; |
192
|
|
|
|
|
|
|
|
193
|
14
|
|
|
|
|
46
|
my ( $key, $val, %res ); |
194
|
14
|
|
|
|
|
55
|
while ( my $arg = shift @args ) { |
195
|
|
|
|
|
|
|
|
196
|
20
|
|
|
|
|
48
|
state $eq = qr/=/; |
197
|
|
|
|
|
|
|
|
198
|
20
|
100
|
|
|
|
92
|
if ( $arg =~ $eq ) { |
199
|
13
|
|
|
|
|
59
|
( $key, $val ) = split $eq, $arg; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# TODO - better way to remove surrounding quotes |
202
|
13
|
100
|
66
|
|
|
102
|
if ( ( $val =~ /^(['"])(.*)(['"])$/ ) && ( $1 eq $3 ) ) { |
203
|
8
|
|
50
|
|
|
37
|
$val = $2 // ''; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
7
|
|
|
|
|
15
|
$val = 1; |
209
|
7
|
100
|
|
|
|
43
|
if ( ($key) = ( $arg =~ /^no[_-](\w+(?:[-_]\w+)*)$/ ) ) { |
210
|
4
|
|
|
|
|
11
|
$val = 0; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
else { |
213
|
3
|
|
|
|
|
7
|
$key = $arg; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
20
|
|
|
|
|
79
|
$res{$key} = $val; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
14
|
100
|
|
|
|
43
|
if ($allowed) { |
221
|
|
|
|
|
|
|
try { |
222
|
13
|
|
|
13
|
|
1136
|
lock_keys( %res, @{$allowed} ); |
|
13
|
|
|
|
|
68
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
catch { |
225
|
3
|
50
|
|
3
|
|
1880
|
if (/Hash has key '(.+)' which is not in the new key set/) { |
226
|
3
|
|
|
|
|
36
|
die sprintf( "Invalid argument key '\%s'\n", $1 ); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
else { |
229
|
0
|
|
|
|
|
0
|
die "Unknown error checking argument keys\n"; |
230
|
|
|
|
|
|
|
} |
231
|
13
|
|
|
|
|
122
|
}; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
11
|
|
|
|
|
694
|
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
|
69
|
|
|
69
|
|
151
|
my ( $self, $text ) = @_; |
270
|
69
|
|
|
|
|
413
|
$text =~ s/([^\n])\n?$/$1\n\n/; |
271
|
|
|
|
|
|
|
|
272
|
69
|
|
|
|
|
223
|
$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
|
14
|
|
|
14
|
1
|
1368
|
my ( $self, $text ) = @_; |
285
|
14
|
|
50
|
|
|
37
|
$text //= ''; |
286
|
14
|
|
|
|
|
55
|
$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
|
63
|
|
|
63
|
|
294
|
my ( $self, $text ) = @_; |
333
|
63
|
|
50
|
|
|
133
|
$text //= ''; |
334
|
63
|
|
|
|
|
198
|
$self->_write_cmd( '=' . $cmd . ' ' . $text ); |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
foreach my $cmd (qw/ pod back cut /) { |
340
|
|
|
|
|
|
|
fresh( |
341
|
|
|
|
|
|
|
"write_${cmd}" => sub { |
342
|
6
|
|
|
6
|
|
16
|
my ($self) = @_; |
343
|
6
|
|
|
|
|
21
|
$self->_write_cmd( '=' . $cmd ); |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
); |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
5
|
|
|
5
|
|
42
|
use namespace::autoclean; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
35
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
1; |