line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package autorequire ; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23313
|
use strict ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
76
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Spec ; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
913
|
use IO::File ; |
|
1
|
|
|
|
|
9433
|
|
|
1
|
|
|
|
|
1039
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.08' ; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
4
|
|
|
4
|
|
3021
|
my $class = shift ; |
14
|
4
|
|
|
|
|
5
|
my $sub = shift ; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
8
|
my $ar = $class->new($sub) ; |
17
|
4
|
100
|
|
|
|
25
|
$ar->insert(-1) if defined($sub) ; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
5
|
|
|
5
|
1
|
16
|
my $class = shift ; |
23
|
5
|
|
|
|
|
5
|
my $sub = shift ; |
24
|
5
|
|
50
|
|
|
21
|
my $list = shift || \@INC ; |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
6
|
my $this = {} ; |
27
|
5
|
|
|
|
|
10
|
$this->{'sub'} = $sub ; |
28
|
5
|
|
|
|
|
6
|
$this->{'list'} = $list ; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
11
|
bless($this, $class) ; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _get_sub { |
35
|
26
|
|
|
26
|
|
38
|
my $this = shift ; |
36
|
|
|
|
|
|
|
|
37
|
26
|
|
|
|
|
54
|
return $this->{'sub'} ; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _get_list { |
42
|
5
|
|
|
5
|
|
5
|
my $this = shift ; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
12
|
return $this->{'list'} ; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Insert $this into @INC at the specified |
49
|
|
|
|
|
|
|
# position. |
50
|
|
|
|
|
|
|
sub insert { |
51
|
5
|
|
|
5
|
1
|
359
|
my $this = shift ; |
52
|
5
|
|
|
|
|
7
|
my $idx = shift ; |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
10
|
my $l = $this->_get_list() ; |
55
|
5
|
50
|
|
|
|
5
|
if (! scalar(@{$l})){ |
|
5
|
|
|
|
|
11
|
|
56
|
0
|
|
|
|
|
0
|
push @{$l}, $this ; |
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
5
|
|
|
|
|
8
|
my $cur = $l->[$idx] ; |
60
|
5
|
|
|
|
|
183
|
splice(@{$l}, $idx, 1, |
|
2
|
|
|
|
|
24
|
|
61
|
|
|
|
|
|
|
($idx >= 0 |
62
|
5
|
100
|
|
|
|
5
|
? (scalar(@{$l}) > $idx |
|
|
100
|
|
|
|
|
|
63
|
|
|
|
|
|
|
? ($this, $cur) |
64
|
|
|
|
|
|
|
: ($this)) |
65
|
|
|
|
|
|
|
: ($cur, $this))) ; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Remove $this from the @INC array. |
71
|
|
|
|
|
|
|
sub delete { |
72
|
2
|
|
|
2
|
1
|
597
|
my $this = shift ; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
3
|
for (my $i = 0 ; $i < scalar(@{$this->{'list'}}) ; $i++){ |
|
31
|
|
|
|
|
63
|
|
75
|
29
|
100
|
|
|
|
59
|
if ($INC[$i] eq $this){ |
76
|
2
|
|
|
|
|
3
|
splice(@{$this->{'list'}}, $i, 1) ; |
|
2
|
|
|
|
|
5
|
|
77
|
2
|
|
|
|
|
4
|
$i-- ; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub enable { |
84
|
1
|
|
|
1
|
0
|
5
|
my $this = shift ; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
2
|
$this->{disabled} = 0 ; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub disable { |
91
|
1
|
|
|
1
|
1
|
373
|
my $this = shift ; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
21
|
$this->{disabled} = 1 ; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub autorequire::INC { |
98
|
27
|
|
|
27
|
0
|
112561
|
my ($this, $f) = @_ ; |
99
|
|
|
|
|
|
|
|
100
|
27
|
100
|
|
|
|
78
|
return undef if $this->{disabled} ; |
101
|
|
|
|
|
|
|
|
102
|
26
|
|
|
|
|
46
|
my $s = $this->_get_sub() ; |
103
|
26
|
100
|
|
|
|
59
|
if (! ref($s)){ |
104
|
|
|
|
|
|
|
# Symbolic reference. It may not be defined yet. |
105
|
3
|
100
|
|
|
|
3
|
return undef if !defined(&{$s}) ; |
|
3
|
|
|
|
|
47
|
|
106
|
2
|
|
|
|
|
4
|
$s = \&{$s} ; |
|
2
|
|
|
|
|
5
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
25
|
|
|
|
|
65
|
my $ret = $s->($this, $f) ; |
110
|
25
|
100
|
|
|
|
178
|
if (defined($ret)){ |
111
|
5
|
100
|
|
|
|
12
|
if (! _is_handle($ret)){ |
112
|
|
|
|
|
|
|
# Maybe the value returned is the name of a file. |
113
|
4
|
100
|
100
|
|
|
62
|
if (($ret !~ /\n/)&&(-r $ret)){ |
114
|
1
|
|
|
|
|
2
|
my $file = $ret ; |
115
|
1
|
|
|
|
|
2
|
$ret = undef ; |
116
|
1
|
50
|
|
|
|
38
|
open($ret, "<$file") or |
117
|
|
|
|
|
|
|
croak("Can't open '$file' for reading: $!") ; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
3
|
|
|
|
|
6
|
my $code = $ret ; |
121
|
3
|
|
|
|
|
3
|
$ret = undef ; |
122
|
1
|
100
|
|
1
|
|
9
|
open($ret, '<', (ref($code) ? $code : \$code)) or |
|
1
|
50
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
62
|
|
123
|
|
|
|
|
|
|
croak("Can't open in-memory filehandle: $!") ; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
25
|
|
|
|
|
8199
|
return $ret ; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Pasted from File::Copy |
133
|
|
|
|
|
|
|
sub _is_handle { |
134
|
5
|
|
|
5
|
|
6
|
my $h = shift ; |
135
|
|
|
|
|
|
|
|
136
|
5
|
100
|
66
|
|
|
35
|
return (ref($h) |
137
|
|
|
|
|
|
|
? (ref($h) eq 'GLOB' |
138
|
|
|
|
|
|
|
|| UNIVERSAL::isa($h, 'GLOB') |
139
|
|
|
|
|
|
|
|| UNIVERSAL::isa($h, 'IO::Handle')) |
140
|
|
|
|
|
|
|
: (ref(\$h) eq 'GLOB')) ; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub is_loaded { |
145
|
4
|
|
|
4
|
1
|
17
|
my $class = shift ; |
146
|
4
|
|
|
|
|
6
|
my $filename = shift ; |
147
|
4
|
|
|
|
|
11
|
my %opts = @_ ; |
148
|
|
|
|
|
|
|
|
149
|
4
|
|
|
|
|
6
|
my $I = $INC{$filename} ; |
150
|
4
|
|
|
|
|
14
|
return $class->_name_or_open_or_slurp_file($I, %opts) ; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub is_installed { |
155
|
2
|
|
|
2
|
1
|
4
|
my $class = shift ; |
156
|
2
|
|
|
|
|
3
|
my $filename = shift ; |
157
|
2
|
|
|
|
|
3
|
my %opts = @_ ; |
158
|
|
|
|
|
|
|
|
159
|
2
|
|
|
|
|
3
|
my $file = undef ; |
160
|
2
|
50
|
|
|
|
20
|
if (File::Spec->file_name_is_absolute($filename)){ |
161
|
0
|
|
|
|
|
0
|
$file = $filename ; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
2
|
|
|
|
|
4
|
foreach my $I (@INC){ |
165
|
23
|
100
|
|
|
|
40
|
next if ref($I) ; |
166
|
21
|
|
|
|
|
148
|
my $test = File::Spec->catfile($I, $filename) ; |
167
|
21
|
100
|
|
|
|
524
|
if (-r File::Spec->catfile($I, $filename)){ |
168
|
1
|
|
|
|
|
3
|
$file = $test ; |
169
|
1
|
|
|
|
|
3
|
last ; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
8
|
return $class->_name_or_open_or_slurp_file($file, %opts) ; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _name_or_open_or_slurp_file { |
179
|
6
|
|
|
6
|
|
8
|
my $class = shift ; |
180
|
6
|
|
|
|
|
6
|
my $file = shift ; |
181
|
6
|
|
|
|
|
11
|
my %opts = @_ ; |
182
|
|
|
|
|
|
|
|
183
|
6
|
100
|
|
|
|
20
|
return undef unless defined($file) ; |
184
|
|
|
|
|
|
|
|
185
|
4
|
100
|
100
|
|
|
21
|
if (($opts{'open'})||($opts{slurp})){ |
186
|
2
|
|
|
|
|
12
|
my $fh = new IO::File("<$file") ; |
187
|
2
|
50
|
|
|
|
239
|
croak("Can't open '$file' for reading: $!") unless defined($fh) ; |
188
|
|
|
|
|
|
|
|
189
|
2
|
100
|
|
|
|
5
|
if ($opts{slurp}){ |
190
|
1
|
|
|
|
|
5
|
local $/ = undef ; |
191
|
1
|
|
|
|
|
171
|
return <$fh> ; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
1
|
|
|
|
|
6
|
return $fh ; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
2
|
|
|
|
|
13
|
return $file ; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1 ; |
202
|
|
|
|
|
|
|
__END__ |