line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package inc::latest::private; |
5
|
|
|
|
|
|
|
# ABSTRACT: private implementation for inc::latest |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.500'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
10
|
1
|
|
|
1
|
|
5
|
use IO::File; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
923
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# must ultimately "goto" the import routine of the module to be loaded |
13
|
|
|
|
|
|
|
# so that the calling package is correct when $mod->import() runs. |
14
|
|
|
|
|
|
|
sub import { |
15
|
0
|
|
|
0
|
|
|
my ( $package, $mod, @args ) = @_; |
16
|
0
|
|
|
|
|
|
my $file = $package->_mod2path($mod); |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
if ( $INC{$file} ) { |
19
|
|
|
|
|
|
|
# Already loaded, but let _load_module handle import args |
20
|
0
|
|
|
|
|
|
goto \&_load_module; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# A bundled copy must be present |
24
|
0
|
0
|
|
|
|
|
my ( $bundled, $bundled_dir ) = $package->_search_bundled($file) |
25
|
|
|
|
|
|
|
or die "No bundled copy of $mod found"; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $from_inc = $package->_search_INC($file); |
28
|
0
|
0
|
|
|
|
|
unless ($from_inc) { |
29
|
|
|
|
|
|
|
# Only bundled is available |
30
|
0
|
|
|
|
|
|
unshift( @INC, $bundled_dir ); |
31
|
0
|
|
|
|
|
|
goto \&_load_module; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( _version($from_inc) >= _version($bundled) ) { |
35
|
|
|
|
|
|
|
# Ignore the bundled copy |
36
|
0
|
|
|
|
|
|
goto \&_load_module; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Load the bundled copy |
40
|
0
|
|
|
|
|
|
unshift( @INC, $bundled_dir ); |
41
|
0
|
|
|
|
|
|
goto \&_load_module; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _version { |
45
|
0
|
|
|
0
|
|
|
require ExtUtils::MakeMaker; |
46
|
0
|
|
|
|
|
|
return ExtUtils::MM->parse_version(shift); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# use "goto" for import to preserve caller |
50
|
|
|
|
|
|
|
sub _load_module { |
51
|
0
|
|
|
0
|
|
|
my $package = shift; # remaining @_ is ready for goto |
52
|
0
|
|
|
|
|
|
my ( $mod, @args ) = @_; |
53
|
0
|
0
|
|
|
|
|
eval "require $mod; 1" or die $@; |
54
|
0
|
0
|
|
|
|
|
if ( my $import = $mod->can('import') ) { |
55
|
0
|
|
|
|
|
|
goto $import; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
return 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _search_bundled { |
61
|
0
|
|
|
0
|
|
|
my ( $self, $file ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $mypath = 'inc'; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
local *DH; # Maintain 5.005 compatibility |
66
|
0
|
0
|
|
|
|
|
opendir DH, $mypath or die "Can't open directory $mypath: $!"; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
while ( defined( my $e = readdir DH ) ) { |
69
|
0
|
0
|
|
|
|
|
next unless $e =~ /^inc_/; |
70
|
0
|
|
|
|
|
|
my $try = File::Spec->catfile( $mypath, $e, $file ); |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
return ( $try, File::Spec->catdir( $mypath, $e ) ) if -e $try; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Look for the given path in @INC. |
78
|
|
|
|
|
|
|
sub _search_INC { |
79
|
|
|
|
|
|
|
# TODO: doesn't handle coderefs or arrayrefs or objects in @INC, but |
80
|
|
|
|
|
|
|
# it probably should |
81
|
0
|
|
|
0
|
|
|
my ( $self, $file ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
foreach my $dir (@INC) { |
84
|
0
|
0
|
|
|
|
|
next if ref $dir; |
85
|
0
|
|
|
|
|
|
my $try = File::Spec->catfile( $dir, $file ); |
86
|
0
|
0
|
|
|
|
|
return $try if -e $try; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Translate a module name into a directory/file.pm to search for in @INC |
93
|
|
|
|
|
|
|
sub _mod2path { |
94
|
0
|
|
|
0
|
|
|
my ( $self, $mod ) = @_; |
95
|
0
|
|
|
|
|
|
my @parts = split /::/, $mod; |
96
|
0
|
|
|
|
|
|
$parts[-1] .= '.pm'; |
97
|
0
|
0
|
|
|
|
|
return $parts[0] if @parts == 1; |
98
|
0
|
|
|
|
|
|
return File::Spec->catfile(@parts); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 tw=75 et: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |