1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!perl -w
package version;
use 5.005_04;
use strict;
use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
$VERSION = '0.80';
$VERSION = eval $VERSION;
$CLASS = 'version';
# Define STRICT version parsing
my $DECIMAL_VERSION = '
(?:
(?: # integer part
0(?=[.]) # 0 but only if followed by a period
| # or
[1-9] # 1-9 followed by
[0-9]* # zero or more digits
)
(?: # decimal part
[.] # literal decimal point
[0-9]+ # one or more digits
)? # optional
)';
my $DOTTED_DECIMAL_VERSION = '
(?:
v # leading v required
(?: # integer part
0(?=[.]) # 0 but only if followed by a period
| # or
[1-9] # 1-9 followed by
[0-9]* # zero or more digits
)
(?: # repeated part
[.] # literal decimal point
[0-9]{1,3} # followed by one to three digits
){2,} # repeating 2 or more times
)';
$STRICT = qr/(?:${DECIMAL_VERSION}|${DOTTED_DECIMAL_VERSION})/x;
# Define LAX version parsing
my $ALPHA = '
(?:
[_] # literal underscore
[0-9]{1,} # followed by one or more digits
)';
my $LAX_DOTTED_DECIMAL_VERSION = '
(?:
(?:
v # leading v required
(?: # integer part
[0-9]+ # zero or more digits
)
(?: # repeated part
[.] # literal decimal point
[0-9]{1,} # followed by one or more digits
){0,} # repeating zero or more times
)
| # or
(?:
v # leading v required
(?: # integer part
[0-9]+ # zero or more digits
)
(?: # repeated part
[.] # literal decimal point
[0-9]{1,} # followed by one or more digits
){1,} # repeating one or more times
${ALPHA}* # with trailing optional alpha stanza(s)
)
| # or
(?:
(?!v) # no leading v
(?: # integer part
0(?=[.]) # 0 but only if followed by a period
| # or
[1-9] # 1-9 followed by
[0-9]* # zero or more digits
)
(?: # repeated part
[.] # literal decimal point
[0-9]{1,} # followed by one or more digits
){2,} # repeating two or more times
${ALPHA}* # with trailing optional alpha stanza(s)
)
)
';
my $LAX_DECIMAL_VERSION = '
(?:
(?:
(?: # integer part
0(?=[.]) # 0 but only if followed by a period
| # or
[1-9] # 1-9 followed by
[0-9]* # zero or more digits
)
(?: # decimal part
[.] # literal decimal point
[0-9]+ # one or more digits
)? # optional
)
| # or
(?:
(?: # integer part
0(?=[.]) # 0 but only if followed by a period
| # or
[1-9] # 1-9 followed by
[0-9]* # zero or more digits
) # mantissa required
(?: # decimal part
[.] # literal decimal point
[0-9]+ # one or more digits
) # required
${ALPHA}* # with trailing optional alpha stanza(s)
)
)
';
$LAX= qr/(?:${LAX_DECIMAL_VERSION}|${LAX_DOTTED_DECIMAL_VERSION})/x;
eval "use version::vxs $VERSION";
if ( $@ ) { # don't have the XS version installed
eval "use version::vpp $VERSION"; # don't tempt fate
die "$@" if ( $@ );
push @ISA, "version::vpp";
local $^W;
*version::qv = \&version::vpp::qv;
*version::declare = \&version::vpp::declare;
*version::_VERSION = \&version::vpp::_VERSION;
if ($] > 5.009001 && $] <= 5.010000) {
no strict 'refs';
*{'version::stringify'} = \*version::vpp::stringify;
*{'version::(""'} = \*version::vpp::stringify;
*{'version::new'} = \*version::vpp::new;
}
}
else { # use XS module
push @ISA, "version::vxs";
local $^W;
*version::declare = \&version::vxs::declare;
*version::qv = \&version::vxs::qv;
*version::_VERSION = \&version::vxs::_VERSION;
if ($] > 5.009001 && $] < 5.010000) {
no strict 'refs';
*{'version::stringify'} = \*version::vxs::stringify;
*{'version::(""'} = \*version::vxs::stringify;
}
elsif ($] == 5.010000) {
no strict 'refs';
*{'version::stringify'} = \*version::vxs::stringify;
*{'version::(""'} = \*version::vxs::stringify;
*version::new = \&version::vxs::new;
*version::parse = \&version::vxs::parse;
}
}
# Preloaded methods go here.
sub import {
no strict 'refs';
my ($class) = shift;
# Set up any derived class
unless ($class eq 'version') {
local $^W;
*{$class.'::declare'} = \&version::declare;
*{$class.'::qv'} = \&version::qv;
}
my %args;
if (@_) { # any remaining terms are arguments
map { $args{$_} = 1 } @_
}
else { # no parameters at all on use line
%args =
(
qv => 1,
'UNIVERSAL::VERSION' => 1,
);
}
my $callpkg = caller();
if (exists($args{declare})) {
*{$callpkg."::declare"} =
sub {return $class->declare(shift) }
unless defined(&{$callpkg.'::declare'});
}
if (exists($args{qv})) {
*{$callpkg."::qv"} =
sub {return $class->qv(shift) }
unless defined(&{"$callpkg\::qv"});
}
if (exists($args{'UNIVERSAL::VERSION'})) {
local $^W;
*UNIVERSAL::VERSION
= \&version::_VERSION;
}
if (exists($args{'VERSION'})) {
*{$callpkg."::VERSION"} = \&version::_VERSION;
}
}
1;
|