line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
18250
|
use 5.008001; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
51
|
|
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package recommended; |
6
|
|
|
|
|
|
|
# ABSTRACT: Load recommended modules on demand when available |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
709
|
use version; |
|
1
|
|
|
|
|
2262
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
75
|
use Carp (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
768
|
use Module::Runtime 0.014 (); # bugfixes for use_package_optimistically |
|
1
|
|
|
|
|
2077
|
|
|
1
|
|
|
|
|
439
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
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
|
|
377
|
my $class = shift; |
22
|
4
|
|
|
|
|
9
|
my $caller = caller; |
23
|
4
|
|
|
|
|
10
|
for my $arg (@_) { |
24
|
6
|
|
|
|
|
9
|
my $type = ref $arg; |
25
|
6
|
100
|
|
|
|
14
|
if ( !$type ) { |
|
|
50
|
|
|
|
|
|
26
|
5
|
|
|
|
|
2075
|
$MODULES{$class}{$caller}{$arg} = [ 0, undef ]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif ( $type eq 'HASH' ) { |
29
|
1
|
|
|
|
|
16
|
while ( my ( $mod, $ver ) = each %$arg ) { |
30
|
2
|
50
|
|
|
|
6
|
Carp::croak("module '$mod': '$ver' is not a valid version string") |
31
|
|
|
|
|
|
|
if !version::is_lax($ver); |
32
|
2
|
|
|
|
|
117
|
$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
|
546
|
my ( $class, $mod, $ver ) = @_; |
43
|
11
|
|
|
|
|
21
|
my $caller = caller; |
44
|
11
|
|
|
|
|
32
|
my $spec = $MODULES{$class}{$caller}{$mod}; |
45
|
|
|
|
|
|
|
|
46
|
11
|
100
|
|
|
|
37
|
return unless $spec; |
47
|
|
|
|
|
|
|
|
48
|
8
|
100
|
|
|
|
17
|
if ( defined $ver ) { |
49
|
1
|
50
|
|
|
|
5
|
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
|
|
|
|
|
8
|
$ver = $spec->[0]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# don't call with a version; we want this to die only on compile failure |
59
|
8
|
|
|
|
|
40
|
Module::Runtime::use_package_optimistically($mod); |
60
|
|
|
|
|
|
|
|
61
|
8
|
|
100
|
|
|
23699
|
my $ok = $INC{ Module::Runtime::module_notional_filename($mod) } |
62
|
|
|
|
|
|
|
&& $mod->VERSION >= version->new($ver); |
63
|
|
|
|
|
|
|
|
64
|
8
|
100
|
|
|
|
376
|
return $spec->[1] = $ok ? 1 : 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 et: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |