line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::MechanicalTurk::ModuleUtil; |
2
|
25
|
|
|
25
|
|
124
|
use strict; |
|
25
|
|
|
|
|
39
|
|
|
25
|
|
|
|
|
755
|
|
3
|
25
|
|
|
25
|
|
120
|
use warnings; |
|
25
|
|
|
|
|
39
|
|
|
25
|
|
|
|
|
602
|
|
4
|
25
|
|
|
25
|
|
22275
|
use IO::Dir; |
|
25
|
|
|
|
|
376993
|
|
|
25
|
|
|
|
|
1423
|
|
5
|
25
|
|
|
25
|
|
238
|
use Carp; |
|
25
|
|
|
|
|
54
|
|
|
25
|
|
|
|
|
8035
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub listSubmodules { |
10
|
0
|
|
|
0
|
0
|
0
|
my ($class, $package) = @_; |
11
|
0
|
|
|
|
|
0
|
my $dir = $package; |
12
|
0
|
|
|
|
|
0
|
$dir =~ s/::/\//g; |
13
|
0
|
|
|
|
|
0
|
my %submodules; |
14
|
0
|
|
|
|
|
0
|
foreach my $inc (@INC) { |
15
|
0
|
0
|
|
|
|
0
|
next unless !ref($inc); |
16
|
0
|
|
|
|
|
0
|
my $dh = IO::Dir->new("$inc/$dir"); |
17
|
0
|
0
|
|
|
|
0
|
if ($dh) { |
18
|
0
|
|
|
|
|
0
|
while (my $file = $dh->read) { |
19
|
0
|
0
|
0
|
|
|
0
|
if ($file =~ /\.pm$/i and -f "$inc/$dir/$file") { |
20
|
0
|
|
|
|
|
0
|
my $submod = "${package}::${file}"; |
21
|
0
|
|
|
|
|
0
|
$submod =~ s/\.pm$//i; |
22
|
0
|
|
|
|
|
0
|
$submodules{$submod} = 1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
0
|
$dh->close; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
0
|
return sort keys %submodules; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub packageExists { |
32
|
24
|
|
|
24
|
0
|
52
|
my ($class, $package) = @_; |
33
|
|
|
|
|
|
|
# Symbol table black magic |
34
|
25
|
|
|
25
|
|
150
|
no strict 'refs'; |
|
25
|
|
|
|
|
57
|
|
|
25
|
|
|
|
|
13322
|
|
35
|
24
|
|
|
|
|
51
|
return defined %{*{"${package}::"}}; |
|
24
|
|
|
|
|
47
|
|
|
24
|
|
|
|
|
341
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub require { |
39
|
24
|
|
|
24
|
0
|
59
|
my ($class, $module) = @_; |
40
|
24
|
50
|
|
|
|
108
|
if (!$class->packageExists($module)) { |
41
|
0
|
|
|
|
|
0
|
my $moduleFile = $module . ".pm"; |
42
|
0
|
|
|
|
|
0
|
$moduleFile =~ s/::/\//g; |
43
|
0
|
|
|
|
|
0
|
require $moduleFile; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub tryRequire { |
48
|
24
|
|
|
24
|
0
|
78
|
my ($class, $module) = @_; |
49
|
24
|
|
|
|
|
55
|
eval { |
50
|
24
|
|
|
|
|
123
|
Net::Amazon::MechanicalTurk::ModuleUtil->require($module); |
51
|
|
|
|
|
|
|
}; |
52
|
24
|
|
|
|
|
158
|
return (!$@); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub requireFirst { |
56
|
3
|
|
|
3
|
0
|
7
|
my $class = shift; |
57
|
3
|
50
|
66
|
|
|
31
|
my @modules = ($#_ == 0 and UNIVERSAL::isa($_[0], "ARRAY")) ? @{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
58
|
3
|
|
|
|
|
7
|
foreach my $module (@modules) { |
59
|
3
|
50
|
|
|
|
15
|
if (Net::Amazon::MechanicalTurk::ModuleUtil->tryRequire($module)) { |
60
|
3
|
|
|
|
|
486
|
return $module; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
Carp::croak("Could not load any of the following modules " . join(", ", @modules) . "."); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return 1; |