line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Selector; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30455
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
888
|
use autouse Carp => qw(croak()); |
|
1
|
|
|
|
|
715
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new($$) { |
10
|
0
|
|
|
0
|
1
|
|
my ($class, $packages) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
croak "Module::Selector->new has to be passed an array reference" |
15
|
|
|
|
|
|
|
unless ref($packages) eq 'ARRAY'; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $self = { |
18
|
|
|
|
|
|
|
pkgs => $packages, |
19
|
|
|
|
|
|
|
pkg_c => scalar @$packages, |
20
|
|
|
|
|
|
|
ltry => 0, |
21
|
|
|
|
|
|
|
get_c => 0, |
22
|
|
|
|
|
|
|
vpkgs => [] |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
bless($self, $class); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
my %failed; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _try($) { |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
return if $self->{'ltry'} >= $self->{'pkg_c'}; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my ($i, $pkg, $pkgc); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$pkgc = $self->{'pkg_c'}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for($i=$self->{'ltry'}; $i<$pkgc; $i++) { |
43
|
0
|
|
|
|
|
|
$pkg = $self->{'pkgs'}->[$i]; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
next if $failed{$pkg}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
eval "require $pkg"; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if($@) { |
50
|
0
|
|
|
|
|
|
$failed{$pkg} = 1; |
51
|
0
|
|
|
|
|
|
$@ = undef |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
|
|
|
|
|
|
last |
55
|
0
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->{'ltry'} = ++$i; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
0
|
|
|
|
if($pkg and not $failed{$pkg}) { |
61
|
0
|
|
|
|
|
|
push @{$self->{'vpkgs'}}, $pkg; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return 1 |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return 0 |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub each($) { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if($self->{'get_c'} > @{$self->{'vpkgs'}}) { |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->{'get_c'} = 0; |
75
|
|
|
|
|
|
|
return |
76
|
0
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->{'get_c'}++; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
unless($self->{'get_c'} <= @{$self->{'vpkgs'}} or $self->_try) { |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{'get_c'} = 0; |
82
|
|
|
|
|
|
|
return |
83
|
0
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self->{'vpkgs'}->[($self->{'get_c'}-1)] |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub rewind($) { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->{'get_c'} = 0 |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |