line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
require v5.10; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Module::Extract::VERSION; |
4
|
2
|
|
|
2
|
|
1449
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
7
|
2
|
|
|
2
|
|
9
|
no warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp qw(carp); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
815
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.116'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Module::Extract::VERSION - Extract a module version safely |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Module::Extract::VERSION; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $version # just the version |
24
|
|
|
|
|
|
|
= Module::Extract::VERSION->parse_version_safely( $file ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my @version_info # extra info |
27
|
|
|
|
|
|
|
= Module::Extract::VERSION->parse_version_safely( $file ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module lets you pull out of module source code the version number |
32
|
|
|
|
|
|
|
for the module. It assumes that there is only one C<$VERSION> |
33
|
|
|
|
|
|
|
in the file and the entire C<$VERSION> statement is on the same line. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Class methods |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item $class->parse_version_safely( FILE ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Given a module file, return the module version. This works just like |
44
|
|
|
|
|
|
|
C in PAUSE. It looks for the single line that has the |
45
|
|
|
|
|
|
|
C<$VERSION> statement, extracts it, evals it in a Safe compartment, |
46
|
|
|
|
|
|
|
and returns the result. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
In scalar context, it returns just the version as a string. In list |
49
|
|
|
|
|
|
|
context, it returns the list of: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sigil |
52
|
|
|
|
|
|
|
fully-qualified variable name |
53
|
|
|
|
|
|
|
version value |
54
|
|
|
|
|
|
|
file name |
55
|
|
|
|
|
|
|
line number of $VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub parse_version_safely { # stolen from PAUSE's mldistwatch, but refactored |
60
|
8
|
|
|
8
|
1
|
7702
|
my( $class, $file ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
32
|
local $/ = "\n"; |
63
|
8
|
|
|
|
|
13
|
local $_; # don't mess with the $_ in the map calling this |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
|
|
|
14
|
my $fh; |
66
|
8
|
50
|
|
|
|
316
|
unless( open $fh, "<", $file ) { |
67
|
0
|
|
|
|
|
0
|
carp( "Could not open file [$file]: $!\n" ); |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
|
|
25
|
my $in_pod = 0; |
72
|
8
|
|
|
|
|
15
|
my( $sigil, $var, $version, $line_number, $rhs ); |
73
|
8
|
|
|
|
|
230
|
while( <$fh> ) { |
74
|
99
|
|
|
|
|
149
|
$line_number++; |
75
|
99
|
|
|
|
|
137
|
chomp; |
76
|
99
|
50
|
|
|
|
202
|
$in_pod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $in_pod; |
|
|
50
|
|
|
|
|
|
77
|
99
|
100
|
66
|
|
|
337
|
next if $in_pod || /^\s*#/; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# package NAMESPACE VERSION <-- we handle that |
80
|
|
|
|
|
|
|
# package NAMESPACE VERSION BLOCK |
81
|
|
|
|
|
|
|
|
82
|
84
|
100
|
100
|
|
|
384
|
next unless / |
83
|
|
|
|
|
|
|
(? |
84
|
|
|
|
|
|
|
[\$*] |
85
|
|
|
|
|
|
|
) |
86
|
|
|
|
|
|
|
(? |
87
|
|
|
|
|
|
|
(? |
88
|
|
|
|
|
|
|
[\w\:\']* |
89
|
|
|
|
|
|
|
) |
90
|
|
|
|
|
|
|
\b |
91
|
|
|
|
|
|
|
VERSION |
92
|
|
|
|
|
|
|
) |
93
|
|
|
|
|
|
|
\b |
94
|
|
|
|
|
|
|
.*? |
95
|
|
|
|
|
|
|
\= |
96
|
|
|
|
|
|
|
(? |
97
|
|
|
|
|
|
|
.* |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
/x || |
100
|
|
|
|
|
|
|
m/ |
101
|
|
|
|
|
|
|
\b package \s+ |
102
|
|
|
|
|
|
|
(? \w[\w\:\']* ) \s+ |
103
|
|
|
|
|
|
|
(? \S+ ) \s* [;{] |
104
|
|
|
|
|
|
|
/x; |
105
|
2
|
|
|
2
|
|
863
|
( $sigil, $var, $rhs ) = @+{ qw(sigil var rhs) }; |
|
2
|
|
|
|
|
769
|
|
|
2
|
|
|
|
|
491
|
|
|
8
|
|
|
|
|
103
|
|
106
|
|
|
|
|
|
|
|
107
|
8
|
100
|
|
|
|
33
|
if ($sigil) { |
108
|
4
|
|
|
|
|
24
|
$version = $class->_eval_version( $_, @+{ qw(sigil var rhs) } ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
4
|
|
|
|
|
22
|
$version = $class->_eval_version( $_, '$', 'VERSION', qq('$rhs') ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
8
|
|
|
|
|
791
|
last; |
115
|
|
|
|
|
|
|
} |
116
|
8
|
50
|
66
|
|
|
50
|
$line_number = undef if eof($fh) && ! defined( $version ); |
117
|
8
|
|
|
|
|
160
|
close $fh; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return wantarray ? |
120
|
8
|
50
|
|
|
|
137
|
( $sigil, $var, $version, $file, $line_number ) |
121
|
|
|
|
|
|
|
: |
122
|
|
|
|
|
|
|
$version; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _eval_version { |
126
|
8
|
|
|
8
|
|
35
|
my( $class, $line, $sigil, $var, $rhs ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
8
|
|
|
|
|
569
|
require Safe; |
129
|
8
|
|
|
|
|
37634
|
require version; |
130
|
8
|
|
|
|
|
1777
|
local $^W = 0; |
131
|
|
|
|
|
|
|
|
132
|
8
|
|
|
|
|
38
|
my $s = Safe->new; |
133
|
|
|
|
|
|
|
|
134
|
8
|
50
|
|
|
|
7999
|
if (defined $Devel::Cover::VERSION) { |
135
|
8
|
|
|
|
|
27
|
$s->share_from('main', ['&Devel::Cover::use_file']); |
136
|
|
|
|
|
|
|
} |
137
|
8
|
|
|
|
|
387
|
$s->reval('$VERSION = ' . $rhs); |
138
|
8
|
|
|
|
|
5027
|
my $version = $s->reval('$VERSION'); |
139
|
|
|
|
|
|
|
|
140
|
8
|
|
|
|
|
3910
|
return $version; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This code is in Github: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
https://github.com/briandfoy/module-extract-version.git |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
brian d foy, C<< >> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
I stole the some of this code from C in the PAUSE |
156
|
|
|
|
|
|
|
code by Andreas König, but I've moved most of it around. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Andrey Starodubtsev added code to handle the v5.12 and v5.14 |
159
|
|
|
|
|
|
|
C syntax. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright © 2008-2022, brian d foy C<< >>. All rights reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
You may redistribute this under the Artistic License 2.0. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |