line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package version::Restrict; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1534
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
810
|
use version 0.77; |
|
1
|
|
|
|
|
2573
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $v0 = version->parse("0"); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
2
|
|
|
2
|
|
1050
|
my $self = shift; |
13
|
2
|
|
|
|
|
8
|
my %restricted = @_; |
14
|
2
|
|
|
|
|
7
|
my @ranges = keys %restricted; |
15
|
2
|
|
|
|
|
10
|
my $package = (caller())[0]; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
190
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
624
|
|
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
76
|
for my $range (@ranges) { |
20
|
2
|
|
|
|
|
15
|
my ($lb, $lower, $upper, $ub) = |
21
|
|
|
|
|
|
|
($range =~ /(.)([0-9.]+),([0-9.]+)(.)/); |
22
|
2
|
50
|
|
|
|
10
|
$lb = '>' . ( $lb eq '[' ? '=' : ''); |
23
|
2
|
50
|
|
|
|
5
|
$ub = '<' . ( $ub eq ']' ? '=' : ''); |
24
|
2
|
|
|
|
|
16
|
$lower = version->parse($lower); |
25
|
2
|
|
|
|
|
12
|
$upper = version->parse($upper); |
26
|
2
|
100
|
66
|
|
|
93
|
${"$package\::__version_required"} = 1 |
|
1
|
|
|
|
|
6
|
|
27
|
|
|
|
|
|
|
if $lb eq '>=' && $lower == $v0; |
28
|
2
|
|
|
|
|
18
|
my $test = "sub { \$_[0] $lb version->parse('$lower') && ". |
29
|
|
|
|
|
|
|
"\$_[0] $ub version->parse('$upper') }"; |
30
|
2
|
|
|
|
|
197
|
$restricted{$range} = [eval($test), $restricted{$range}]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
8
|
*{"$package\::VERSION"} = sub { |
34
|
12
|
|
|
12
|
|
6967
|
my ($package, $req) = @_; |
35
|
12
|
|
|
|
|
153
|
$req = version->parse($req); |
36
|
12
|
|
|
|
|
19
|
my $version = version->parse(${"$package\::VERSION"}); |
|
12
|
|
|
|
|
104
|
|
37
|
12
|
100
|
|
|
|
437
|
if ($req > $version) { |
38
|
2
|
|
|
|
|
50
|
die "$package version $req required--this is only version $version"; |
39
|
|
|
|
|
|
|
} |
40
|
10
|
|
|
|
|
19
|
for my $range (@ranges) { |
41
|
10
|
100
|
|
|
|
314
|
if ($restricted{$range}[0]->($req)) { |
42
|
5
|
|
|
|
|
122
|
die "Cannot 'use $package $req': $restricted{$range}[1]\n"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
5
|
|
|
|
|
7
|
${"$package\::__version_checked"} = 1; |
|
5
|
|
|
|
|
16
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#print "required=", ${"$package\::__version_required"}, "\n"; |
48
|
5
|
|
|
|
|
118
|
return $version; |
49
|
2
|
|
|
|
|
11
|
}; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
3
|
my $has_import = defined(&{"$package\::import"}); |
|
2
|
|
|
|
|
11
|
|
52
|
2
|
|
|
|
|
2
|
my $orig_import = \&{"$package\::import"}; |
|
2
|
|
|
|
|
10
|
|
53
|
|
|
|
|
|
|
#print "pkg=$package, has_import=$has_import\n"; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
50
|
*{"$package\::import"} = sub { |
56
|
7
|
|
|
7
|
|
72
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#print "checked=", ${"$package\::__version_checked"}, "\n"; |
59
|
|
|
|
|
|
|
#print "required=", ${"$package\::__version_required"}, "\n"; |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
607
|
my $version = version->parse(${"$package\::VERSION"}); |
|
7
|
|
|
|
|
81
|
|
62
|
7
|
|
|
|
|
33
|
die "Cannot 'use $package': must specify desired version, ". |
63
|
|
|
|
|
|
|
"e.g. 'use $package $version';\n" |
64
|
3
|
|
|
|
|
42
|
if ${"$package\::__version_required"} && |
65
|
7
|
100
|
100
|
|
|
9
|
!${"$package\::__version_checked"}; |
66
|
6
|
|
|
|
|
9
|
${"$package\::__version_checked"} = 0; |
|
6
|
|
|
|
|
14
|
|
67
|
|
|
|
|
|
|
|
68
|
6
|
50
|
|
|
|
28
|
if ($has_import) { |
69
|
0
|
|
|
|
|
0
|
$orig_import->($self, @_); |
70
|
|
|
|
|
|
|
} else { |
71
|
|
|
|
|
|
|
# XXX if Exporter-based only? |
72
|
6
|
|
|
|
|
81
|
$self->SUPER::import(@_); |
73
|
|
|
|
|
|
|
} |
74
|
2
|
|
|
|
|
9
|
}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
#ABSTRACT: Control permitted versions that can be use'd |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |