line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Test::Depends; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
948
|
use strict 'vars', 'subs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
34
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
56
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 0.06; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Test::Depends - Gracefully skip tests if missing modules |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Test::Depends qw(Some::Module), [ SomeOtherModule => 1.1 ]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This module requires the modules that you asked for, and if some of |
21
|
|
|
|
|
|
|
them are not there, it will bail out and exit saying which ones and |
22
|
|
|
|
|
|
|
why. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
54301
|
use Data::Dumper; |
|
1
|
|
|
|
|
16014
|
|
|
1
|
|
|
|
|
150
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub import { |
29
|
1
|
|
|
1
|
|
15
|
my $package = shift; |
30
|
1
|
|
|
|
|
3
|
my $caller = caller(); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
3
|
my @missing; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
6
|
while ( my $package = shift ) { |
35
|
0
|
|
|
|
|
0
|
my $eval = ("# line 0 \"Test::Depends generated\"\n" |
36
|
|
|
|
|
|
|
."package $caller;\n"); |
37
|
0
|
|
|
|
|
0
|
my $import = ""; |
38
|
0
|
|
|
|
|
0
|
my $wanted_version; |
39
|
0
|
0
|
0
|
|
|
0
|
if ( ref $package and ref $package eq "ARRAY" ) { |
40
|
0
|
|
|
|
|
0
|
($package, my @args) = (@$package); |
41
|
1
|
|
|
1
|
|
11
|
no warnings 'numeric'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1211
|
|
42
|
0
|
0
|
0
|
|
|
0
|
if ( @args == 1 and |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
43
|
|
|
|
|
|
|
not ref $args[0] and |
44
|
|
|
|
|
|
|
( $args[0]+0 != 0 or $args[0]+0 eq $args[0] ) |
45
|
|
|
|
|
|
|
) { |
46
|
0
|
|
|
|
|
0
|
$wanted_version = $args[0]; |
47
|
0
|
|
|
|
|
0
|
($import = $wanted_version) =~ s{'}{\'}g; |
48
|
0
|
|
|
|
|
0
|
$import = " '$import'"; |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
0
|
local($Data::Dumper::Purity) = 1; |
51
|
0
|
|
|
|
|
0
|
local($Data::Dumper::Varname) = "bob"; |
52
|
0
|
|
|
|
|
0
|
my $dumped = Data::Dumper->Dump([\@args]); |
53
|
0
|
|
|
|
|
0
|
$dumped =~ s{\A\$bob1 = }{}; |
54
|
0
|
|
|
|
|
0
|
$import = ' @{'.$dumped.'}'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
$eval .= "use $package$import;"; |
58
|
0
|
|
|
|
|
0
|
eval $eval; |
59
|
0
|
|
|
|
|
0
|
$eval =~ s{^}{# }mg; |
60
|
|
|
|
|
|
|
#print STDERR "# RAN:\n$eval\n" if ( -t STDOUT ); |
61
|
0
|
0
|
|
|
|
0
|
if ( $@ ) { |
62
|
0
|
|
|
|
|
0
|
(my $pm = $package) =~ s{::}{/}g; |
63
|
0
|
|
|
|
|
0
|
$pm .= ".pm"; |
64
|
0
|
0
|
0
|
|
|
0
|
if ( $wanted_version and ${"${package}::VERSION"} ) { |
|
0
|
0
|
|
|
|
0
|
|
65
|
0
|
|
|
|
|
0
|
push @missing, "$package (${$package.'::VERSION'} < $wanted_version)", $@; |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
} elsif ( exists $INC{$pm} ) { |
67
|
0
|
|
|
|
|
0
|
push @missing, "$package (import failure)", $@; |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
0
|
push @missing, "$package", $@; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
16
|
if ( @missing ) { |
75
|
0
|
|
|
|
|
|
print("1..0 # Skip missing/broken dependancies"); |
76
|
0
|
0
|
|
|
|
|
if ( -t STDOUT ) { |
77
|
0
|
|
|
|
|
|
print "\n"; |
78
|
0
|
|
|
|
|
|
while ( my ($pkg, $err) = splice @missing, 0, 2 ) { |
79
|
0
|
|
|
|
|
|
$err =~ s{^}{\t}gm; |
80
|
0
|
|
|
|
|
|
print STDERR ("ERROR - pre-requisite $pkg " |
81
|
|
|
|
|
|
|
."failed to load:\n$err\n"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
|
my $i; |
85
|
0
|
|
|
|
|
|
print "; ".join(", ", grep { !($i++ % 2) } @missing)."\n"; |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
exit(0); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |