line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Require; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
743
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw: @ISA @EXPORT_OK $VERSION :; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1255
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw[ Exporter ]; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# $Id: Require.pm,v 1.1 2004/03/05 16:58:44 jgsmith Exp $ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT_OK = qw: require_regex require_glob walk_inc :; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _walk_inc { |
15
|
0
|
|
|
0
|
|
|
my $filter = shift; |
16
|
0
|
|
|
|
|
|
my $todo = shift; |
17
|
0
|
|
|
|
|
|
my $prefix = shift; |
18
|
0
|
|
|
|
|
|
my $root = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my %modules = ( ); |
21
|
0
|
|
|
|
|
|
my $dh; |
22
|
0
|
|
|
|
|
|
opendir $dh, "$prefix/$root"; |
23
|
0
|
|
|
|
|
|
my(@files) = grep { defined } map &$filter("$root/$_"), grep !/^\./, readdir($dh); |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
closedir $dh; |
25
|
0
|
|
|
|
|
|
foreach my $f (@files) { |
26
|
0
|
0
|
|
|
|
|
next unless $f; |
27
|
0
|
|
|
|
|
|
my $realfilename = "$prefix/$root/$f"; |
28
|
0
|
0
|
|
|
|
|
next if $INC{"$root/$f"}; |
29
|
0
|
0
|
|
|
|
|
if ( -d $realfilename ) { |
|
|
0
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
@modules{&_walk_inc($filter, $todo, $prefix, "$root/$f")} = ( ); |
31
|
|
|
|
|
|
|
} elsif( -f $realfilename ) { |
32
|
0
|
|
|
|
|
|
$modules{"$root/$f"} = undef; |
33
|
0
|
0
|
|
|
|
|
eval { &$todo("$root/$f", $realfilename) and delete $modules{"$root/$f"} }; |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
return keys %modules; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub walk_inc(;&&$) { |
40
|
0
|
|
|
0
|
1
|
|
my $filter = shift; |
41
|
0
|
0
|
0
|
0
|
|
|
$filter ||= sub { return $_ unless /\.pod$/ or /\.pl$/ }; |
|
0
|
|
0
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $todo = shift; |
44
|
0
|
0
|
0
|
0
|
|
|
$todo ||= sub { require $_[1] and $INC{$_[0]} = $_[1] and 1 }; |
|
0
|
|
0
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $root = shift; |
47
|
0
|
0
|
|
|
|
|
$root = "" unless defined $root; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my %modules = ( ); |
50
|
0
|
|
|
|
|
|
foreach my $prefix (@INC) { |
51
|
0
|
|
|
|
|
|
@modules{_walk_inc $filter, $todo, $prefix, $root} = ( ); |
52
|
|
|
|
|
|
|
} |
53
|
0
|
0
|
|
|
|
|
return unless defined wantarray; |
54
|
0
|
0
|
|
|
|
|
return wantarray ? keys %modules : scalar keys %modules; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub require_regex { |
58
|
0
|
|
|
0
|
1
|
|
my %modules = ( ); |
59
|
0
|
|
|
|
|
|
while(@_) { |
60
|
0
|
|
|
|
|
|
my $file = shift; |
61
|
0
|
|
|
|
|
|
$file =~ s{::}{/}g; |
62
|
0
|
|
|
|
|
|
$file .= ".pm"; |
63
|
0
|
|
|
|
|
|
my $fileprefix = ""; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if($file =~ m{^(.*)/([^/]*)$}) { |
66
|
0
|
|
|
|
|
|
$fileprefix = $1; |
67
|
0
|
|
|
|
|
|
$file = $2; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# $file is guaranteed to not have a `/' in it :) |
71
|
0
|
|
|
|
|
|
my $filter = eval qq"sub { grep m/$file/, readdir \$_[0] }"; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# thanks to `perldoc -f require' for the basic logic here :) |
74
|
0
|
|
|
|
|
|
foreach my $prefix (@INC) { |
75
|
0
|
|
|
|
|
|
my $dh; |
76
|
0
|
|
|
|
|
|
opendir $dh, "$prefix/$fileprefix"; |
77
|
0
|
|
|
|
|
|
my @files = &$filter($dh); |
78
|
0
|
|
|
|
|
|
closedir $dh; |
79
|
0
|
|
|
|
|
|
foreach my $f (@files) { |
80
|
0
|
|
|
|
|
|
my $realfilename = "$prefix/$fileprefix/$f"; |
81
|
0
|
0
|
0
|
|
|
|
next if $INC{$realfilename} || $INC{"$fileprefix/$f"}; |
82
|
0
|
0
|
|
|
|
|
if( -f $realfilename ) { |
83
|
0
|
|
|
|
|
|
$modules{"$fileprefix/$f"} = undef; |
84
|
0
|
|
|
|
|
|
eval { |
85
|
0
|
0
|
|
|
|
|
$INC{"$fileprefix/$f"} = $realfilename if eval qq"require $realfilename"; |
86
|
0
|
|
|
|
|
|
delete $INC{$realfilename}; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
0
|
0
|
|
|
|
|
delete @modules{grep m{$fileprefix/$file}, keys %INC} if defined wantarray; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
0
|
|
|
|
|
return unless defined wantarray; |
94
|
0
|
0
|
|
|
|
|
return wantarray ? keys %modules : scalar keys %modules; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub require_glob { |
98
|
0
|
|
|
0
|
1
|
|
my %modules = ( ); |
99
|
0
|
|
|
|
|
|
while(@_) { |
100
|
0
|
|
|
|
|
|
my $file = shift; |
101
|
0
|
|
|
|
|
|
$file =~ s{::}{/}g; |
102
|
0
|
|
|
|
|
|
$file .= '\.pm'; |
103
|
0
|
|
|
|
|
|
my $fileprefix = ""; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if($file =~ m{^(.*)/([^/]*)$}) { |
106
|
0
|
|
|
|
|
|
$fileprefix = $1; |
107
|
0
|
|
|
|
|
|
$file = $2; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# thanks to `perldoc -f require' for the basic logic here :) |
111
|
0
|
|
|
|
|
|
foreach my $prefix (@INC) { |
112
|
0
|
|
|
|
|
|
my @files = eval "<$prefix/$fileprefix/$file>"; |
113
|
0
|
|
|
|
|
|
foreach my $realfilename (@files) { |
114
|
0
|
|
|
|
|
|
my $f = $realfilename; |
115
|
0
|
|
|
|
|
|
$f =~ s{^$prefix/$fileprefix/}{}; |
116
|
0
|
0
|
0
|
|
|
|
next if $INC{$realfilename} || $INC{"$fileprefix/$f"}; |
117
|
0
|
0
|
|
|
|
|
if( -f $realfilename ) { |
118
|
0
|
|
|
|
|
|
$modules{"$fileprefix/$f"} = undef; |
119
|
0
|
|
|
|
|
|
eval { |
120
|
0
|
0
|
|
|
|
|
if(eval { require $realfilename }) { |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$INC{"$fileprefix/$f"} = $realfilename; |
122
|
0
|
|
|
|
|
|
delete $modules{"$fileprefix/$f"}; |
123
|
0
|
|
|
|
|
|
delete $INC{$realfilename}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
|
return unless defined wantarray; |
131
|
0
|
0
|
|
|
|
|
return wantarray ? keys %modules : scalar keys %modules; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |