line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
25042
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package recommended; |
6
|
|
|
|
|
|
|
# ABSTRACT: Load a recommended module and don't die if it doesn't exist |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
615
|
use version; |
|
1
|
|
|
|
|
2128
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
81
|
use Carp (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
10
|
1
|
|
|
1
|
|
686
|
use Module::Runtime (); |
|
1
|
|
|
|
|
2002
|
|
|
1
|
|
|
|
|
361
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# $MODULES{$type}{$caller}{$mod} = [$min_version, $satisfied] |
15
|
|
|
|
|
|
|
my %MODULES; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# for testing and diagnostics |
18
|
0
|
|
|
0
|
|
0
|
sub __modules { return \%MODULES } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub import { |
21
|
4
|
|
|
4
|
|
318
|
my $class = shift; |
22
|
4
|
|
|
|
|
6
|
my $caller = caller; |
23
|
4
|
|
|
|
|
8
|
for my $arg (@_) { |
24
|
6
|
|
|
|
|
12
|
my $type = ref $arg; |
25
|
6
|
100
|
|
|
|
12
|
if ( !$type ) { |
|
|
50
|
|
|
|
|
|
26
|
5
|
|
|
|
|
2008
|
$MODULES{$class}{$caller}{$arg} = [ 0, undef ]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif ( $type eq 'HASH' ) { |
29
|
1
|
|
|
|
|
13
|
while ( my ( $mod, $ver ) = each %$arg ) { |
30
|
2
|
50
|
|
|
|
7
|
Carp::croak("module '$mod': '$ver' is not a valid version string") |
31
|
|
|
|
|
|
|
if !version::is_lax($ver); |
32
|
2
|
|
|
|
|
94
|
$MODULES{$class}{$caller}{$mod} = [ $ver, undef ]; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
Carp::croak("arguments to 'recommended' must be scalars or a hash ref"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub has { |
42
|
11
|
|
|
11
|
1
|
1151
|
my ( $class, $mod, $ver ) = @_; |
43
|
11
|
|
|
|
|
60
|
my $caller = caller; |
44
|
11
|
|
|
|
|
35
|
my $spec = $MODULES{$class}{$caller}{$mod}; |
45
|
|
|
|
|
|
|
|
46
|
11
|
100
|
|
|
|
45
|
return unless $spec; |
47
|
|
|
|
|
|
|
|
48
|
8
|
100
|
|
|
|
21
|
if ( defined $ver ) { |
49
|
1
|
50
|
|
|
|
10
|
Carp::croak("module '$mod': '$ver' is not a valid version string") |
50
|
|
|
|
|
|
|
if !version::is_lax($ver); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
# shortcut if default already checked |
54
|
7
|
50
|
|
|
|
19
|
return $spec->[1] if defined $spec->[1]; |
55
|
7
|
|
|
|
|
14
|
$ver = $spec->[0]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
36
|
local $@; |
59
|
8
|
|
|
|
|
17
|
my $ok = eval { Module::Runtime::use_module( $mod, $ver ) }; |
|
8
|
|
|
|
|
24
|
|
60
|
8
|
100
|
|
|
|
31953
|
return $spec->[1] = $ok ? 1 : 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 et: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |