line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Readme::Plugin::requires; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
634
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 'v1.2.1'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1048
|
use CPAN::Meta; |
|
1
|
|
|
|
|
25192
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
2456
|
use Module::CoreList; |
|
1
|
|
|
|
|
82852
|
|
|
1
|
|
|
|
|
486
|
|
9
|
1
|
|
|
1
|
|
78
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
10
|
1
|
|
|
1
|
|
8
|
use Types::Standard qw/ Bool Str /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
932
|
use Pod::Readme::Types qw/ File HeadingLevel /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
785
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Pod::Readme::Plugin::requires - Include requirements in README |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=for readme plugin requires |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This is a plugin for L that includes module requirements |
25
|
|
|
|
|
|
|
from the F file. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Because this depends on the F file, the F should be |
28
|
|
|
|
|
|
|
generated after that file has been updated. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 ARGUMENTS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 C |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=for readme plugin version from-file='MYMETA.yml' |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
By default, it will extract the version from the F file. If, |
37
|
|
|
|
|
|
|
for some reason, this file is in a non-standard location, then you |
38
|
|
|
|
|
|
|
should specify it here. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The file will be ignored if the C attribute is set, and instead |
41
|
|
|
|
|
|
|
obtain metadata from the L object (since the F |
42
|
|
|
|
|
|
|
file may not exist.) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 C |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
By default, core modules for the version of Perl specified in the |
47
|
|
|
|
|
|
|
F file are omitted from this list. If you prefer to lise |
48
|
|
|
|
|
|
|
all requirements, then specify this option. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 C |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=for readme plugin version title='REQUIREMENTS' |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This argument allows you to change the title of the heading. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 KNOWN ISSUES |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item * |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Trailing zeros in module versions may be dropped. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
If you specify a minimum version of a module with a trailing zero, |
65
|
|
|
|
|
|
|
e.g. "0.30", then it may be shown as "0.3". A workaround is to |
66
|
|
|
|
|
|
|
specify the module version in your F as a string instead |
67
|
|
|
|
|
|
|
of number: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
requires( |
70
|
|
|
|
|
|
|
'CPAN::Changes' => '0.30', |
71
|
|
|
|
|
|
|
... |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
requires 'parse_cmd_args'; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has 'requires_from_file' => ( |
81
|
|
|
|
|
|
|
is => 'rw', |
82
|
|
|
|
|
|
|
isa => File, |
83
|
|
|
|
|
|
|
coerce => sub { File->coerce(@_) }, |
84
|
|
|
|
|
|
|
default => 'META.yml', |
85
|
|
|
|
|
|
|
lazy => 1, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
has 'requires_title' => ( |
89
|
|
|
|
|
|
|
is => 'rw', |
90
|
|
|
|
|
|
|
isa => Str, |
91
|
|
|
|
|
|
|
default => 'REQUIREMENTS', |
92
|
|
|
|
|
|
|
lazy => 1, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
has 'requires_omit_core' => ( |
96
|
|
|
|
|
|
|
is => 'rw', |
97
|
|
|
|
|
|
|
isa => Bool, |
98
|
|
|
|
|
|
|
default => 1, |
99
|
|
|
|
|
|
|
lazy => 1, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has 'requires_heading_level' => ( |
103
|
|
|
|
|
|
|
is => 'rw', |
104
|
|
|
|
|
|
|
isa => HeadingLevel, |
105
|
|
|
|
|
|
|
default => 1, |
106
|
|
|
|
|
|
|
lazy => 1, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has 'requires_run' => ( |
110
|
|
|
|
|
|
|
is => 'rw', |
111
|
|
|
|
|
|
|
isa => Bool, |
112
|
|
|
|
|
|
|
default => 0, |
113
|
|
|
|
|
|
|
lazy => 1, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
around 'depends_on' => sub { |
117
|
|
|
|
|
|
|
my ( $orig, $self ) = @_; |
118
|
|
|
|
|
|
|
return ( $self->requires_from_file, $self->$orig ); |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub cmd_requires { |
122
|
3
|
|
|
3
|
0
|
8
|
my ( $self, @args ) = @_; |
123
|
|
|
|
|
|
|
|
124
|
3
|
50
|
|
|
|
57
|
die "The requires plugin can only be used once" if $self->requires_run; |
125
|
|
|
|
|
|
|
|
126
|
3
|
|
|
|
|
66
|
my $res = $self->parse_cmd_args( |
127
|
|
|
|
|
|
|
[qw/ from-file title omit-core no-omit-core heading-level /], @args ); |
128
|
2
|
|
|
|
|
4
|
foreach my $key ( keys %{$res} ) { |
|
2
|
|
|
|
|
6
|
|
129
|
2
|
|
|
|
|
34
|
( my $name = "requires_${key}" ) =~ s/-/_/g; |
130
|
2
|
50
|
|
|
|
9
|
if ( my $method = $self->can($name) ) { |
131
|
2
|
|
|
|
|
36
|
$self->$method( $res->{$key} ); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else { |
134
|
0
|
|
|
|
|
0
|
die "Invalid key: '${key}'"; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
32
|
my $meta; |
139
|
|
|
|
|
|
|
|
140
|
2
|
50
|
|
|
|
13
|
if ( $self->zilla ) { |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
$meta = CPAN::Meta->create( $self->zilla->distmeta, |
143
|
|
|
|
|
|
|
{ lazy_validation => 1 } ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
|
|
|
|
|
|
|
148
|
2
|
|
|
|
|
44
|
my $file = |
149
|
|
|
|
|
|
|
path( $self->base_dir, $self->requires_from_file )->stringify; |
150
|
2
|
50
|
|
|
|
196
|
unless ( -e $file ) { |
151
|
0
|
|
|
|
|
0
|
die "Cannot find META.yml file at '${file}"; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
17
|
$meta = CPAN::Meta->load_file($file); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
2
|
|
|
|
|
31891
|
my ( $prereqs, $perl ) = $self->_get_prereqs( $meta, 'requires' ); |
158
|
2
|
50
|
|
|
|
5
|
if ( %{$prereqs} ) { |
|
2
|
|
|
|
|
7
|
|
159
|
|
|
|
|
|
|
|
160
|
2
|
50
|
|
|
|
70
|
my $heading = $self->can( "write_head" . $self->requires_heading_level ) |
161
|
|
|
|
|
|
|
or die "Invalid heading level: " . $self->requires_heading_level; |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
100
|
$self->$heading( $self->requires_title ); |
164
|
|
|
|
|
|
|
|
165
|
2
|
50
|
|
|
|
100
|
if ($perl) { |
166
|
2
|
|
|
|
|
48
|
$self->write_para( |
167
|
|
|
|
|
|
|
sprintf( 'This distribution requires Perl %s.', |
168
|
|
|
|
|
|
|
version->parse($perl)->normal ) |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
2
|
|
|
|
|
48
|
$self->write_para('This distribution requires the following modules:'); |
173
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
46
|
$self->_write_modules($prereqs); |
175
|
|
|
|
|
|
|
|
176
|
2
|
|
|
|
|
42
|
my ($recommends) = $self->_get_prereqs( $meta, 'recommends' ); |
177
|
2
|
50
|
|
|
|
4
|
if ( %{$recommends} ) { |
|
2
|
|
|
|
|
7
|
|
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
$self->write_para( |
180
|
|
|
|
|
|
|
'This distribution recommends the following modules:'); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
$self->_write_modules($recommends); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
2
|
|
|
|
|
35
|
$self->requires_run(1); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _get_prereqs { |
192
|
4
|
|
|
4
|
|
11
|
my ( $self, $meta, $key ) = @_; |
193
|
|
|
|
|
|
|
|
194
|
4
|
|
|
|
|
6
|
my %prereqs; |
195
|
4
|
|
|
|
|
8
|
foreach my $type ( values %{ $meta->prereqs } ) { |
|
4
|
|
|
|
|
15
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# TODO: max version |
198
|
12
|
|
|
|
|
805
|
$prereqs{$_} = $type->{$key}->{$_} for ( keys %{ $type->{$key} } ); |
|
12
|
|
|
|
|
88
|
|
199
|
|
|
|
|
|
|
} |
200
|
4
|
|
|
|
|
26
|
my $perl = delete $prereqs{perl}; |
201
|
4
|
100
|
66
|
|
|
89
|
if ( $self->requires_omit_core && $perl ) { |
202
|
2
|
|
|
|
|
54
|
foreach ( keys %prereqs ) { |
203
|
53
|
|
|
|
|
57631
|
my $ver = $prereqs{$_}; |
204
|
|
|
|
|
|
|
delete $prereqs{$_} |
205
|
53
|
100
|
100
|
|
|
183
|
if Module::CoreList->first_release( $_, $prereqs{$ver} ) |
206
|
|
|
|
|
|
|
&& version->parse( Module::CoreList->first_release($_) ) <= |
207
|
|
|
|
|
|
|
version->parse($perl); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
4
|
|
|
|
|
561
|
return ( \%prereqs, $perl ); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub _write_modules { |
214
|
2
|
|
|
2
|
|
6
|
my ( $self, $prereqs ) = @_; |
215
|
2
|
|
|
|
|
18
|
$self->write_over(4); |
216
|
2
|
|
|
|
|
39
|
foreach my $module ( sort { lc($a) cmp lc($b) } keys %{$prereqs} ) { |
|
86
|
|
|
|
|
132
|
|
|
2
|
|
|
|
|
17
|
|
217
|
31
|
|
|
|
|
598
|
my $version = $prereqs->{$module}; |
218
|
31
|
100
|
|
|
|
54
|
my $text = $version ? " (version ${version})" : ''; |
219
|
31
|
|
|
|
|
115
|
$self->write_item( sprintf( '* L<%s>', $module ) . $text ); |
220
|
|
|
|
|
|
|
} |
221
|
2
|
|
|
|
|
49
|
$self->write_back; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
1
|
|
|
1
|
|
8
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |