line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
2236
|
use utf8; |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
8
|
|
2
|
2
|
|
|
2
|
|
60
|
use v5.10; |
|
2
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Module::Extract::DeclaredMinimumPerl; |
5
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
31
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
51
|
|
8
|
2
|
|
|
2
|
|
10
|
no warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1162
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.022'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=encoding utf8 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Module::Extract::DeclaredMinimumPerl - Extract the version of Perl a module declares |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Module::Extract::DeclaredMinimumPerl; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $extor = Module::Extract::DeclaredMinimumPerl->new; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $version = $extor->get_minimum_declared_perl( $file ); |
25
|
|
|
|
|
|
|
if( $extor->error ) { ... } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Extract the largest declared Perl version and returns it as a |
30
|
|
|
|
|
|
|
version object. For instance, in a script you might have: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use v5.16; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This module will extract that C and return it. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This module tries to handle any format that PPI will recognize, passing |
37
|
|
|
|
|
|
|
them through version.pm to normalize them. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over 4 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item new |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Makes an object. The object doesn't do anything just yet, but you need |
46
|
|
|
|
|
|
|
it to call the methods. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
1
|
|
|
1
|
1
|
448
|
my $class = shift; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
2
|
$self->init; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
3
|
$self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item init |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Set up the object. You shouldn't need to call this yourself. You can |
63
|
|
|
|
|
|
|
override it though! |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub init { |
68
|
1
|
|
|
1
|
1
|
3
|
$_[0]->_clear_error; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item get_minimum_declared_perl( FILE ) |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Extracts all of the declared minimum versions for Perl, sorts them, |
74
|
|
|
|
|
|
|
and returns the largest a version object. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_minimum_declared_perl { |
79
|
3
|
|
|
3
|
1
|
2420
|
my( $self, $file ) = @_; |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
10
|
$self->_clear_error; |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
5
|
my $versions = $self->_get_ppi_for_file( $file ); |
84
|
3
|
100
|
|
|
|
3189
|
return unless defined $versions; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my @sorted = sort { |
87
|
2
|
|
|
|
|
13
|
eval { version->parse( $b->{version} ) } |
|
1
|
|
|
|
|
10
|
|
88
|
|
|
|
|
|
|
<=> |
89
|
1
|
|
|
|
|
4
|
eval { version->parse( $a->{version} ) } |
|
1
|
|
|
|
|
11
|
|
90
|
|
|
|
|
|
|
} @$versions; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
5
|
eval { version->parse( $sorted[0]->{version} ) }; |
|
2
|
|
|
|
|
25
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _get_ppi_for_file { |
96
|
3
|
|
|
3
|
|
5
|
my( $self, $file ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
3
|
100
|
|
|
|
42
|
unless( -e $file ) { |
99
|
1
|
|
|
|
|
6
|
$self->_set_error( ref( $self ) . ": File [$file] does not exist!" ); |
100
|
1
|
|
|
|
|
2
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
483
|
require PPI; |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
91463
|
my $Document = eval { PPI::Document->new( $file ) }; |
|
2
|
|
|
|
|
17
|
|
106
|
2
|
50
|
|
|
|
60526
|
unless( $Document ) { |
107
|
0
|
|
|
|
|
0
|
$self->_set_error( ref( $self ) . ": Could not parse file [$file]" ); |
108
|
0
|
|
|
|
|
0
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $modules = $Document->find( |
112
|
|
|
|
|
|
|
sub { |
113
|
666
|
100
|
66
|
666
|
|
6838
|
$_[1]->isa( 'PPI::Statement::Include' ) && |
114
|
|
|
|
|
|
|
( $_[1]->type eq 'use' || $_[1]->type eq 'require' ) |
115
|
|
|
|
|
|
|
} |
116
|
2
|
|
|
|
|
21
|
); |
117
|
|
|
|
|
|
|
|
118
|
2
|
50
|
|
|
|
30
|
return unless $modules; |
119
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
4
|
my %Seen; |
121
|
|
|
|
|
|
|
my @versions = |
122
|
15
|
|
|
|
|
94
|
grep { $_->{version_literal} } |
123
|
|
|
|
|
|
|
map { |
124
|
2
|
|
|
|
|
6
|
my $literal = $_->version_literal; |
|
15
|
|
|
|
|
408
|
|
125
|
15
|
|
|
|
|
321
|
$literal =~ s/\s//g; |
126
|
15
|
100
|
|
|
|
49
|
$literal = undef unless length $literal; |
127
|
15
|
|
66
|
|
|
35
|
my $hash = { |
128
|
|
|
|
|
|
|
version => $_->version, |
129
|
|
|
|
|
|
|
version_literal => ( $literal // $_->version ), #/ |
130
|
|
|
|
|
|
|
}; |
131
|
|
|
|
|
|
|
} @$modules; |
132
|
|
|
|
|
|
|
|
133
|
2
|
|
|
|
|
16
|
return \@versions; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item error |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Return the error from the last call to C. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
1
|
|
2
|
sub _set_error { $_[0]->{error} = $_[1]; } |
143
|
|
|
|
|
|
|
|
144
|
4
|
|
|
4
|
|
10
|
sub _clear_error { $_[0]->{error} = '' } |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
3
|
1
|
35
|
sub error { $_[0]->{error} } |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 TO DO |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * Make it recursive, so it scans the source for any module that it finds. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
The source code is in Github: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
https://github.com/briandfoy/module-extract-declaredminimumperl |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
brian d foy, C<< >> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright © 2011-2021, brian d foy . All rights reserved. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
You may redistribute this under the terms of the Artistic License 2.0. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |