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