line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Module::Spec::V0; |
3
|
|
|
|
|
|
|
$Module::Spec::V0::VERSION = '0.9.0'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Module::Spec internal utilities |
5
|
5
|
|
|
5
|
|
710
|
use 5.012; |
|
5
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# use warnings; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(need_module try_module); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# _need_module($opts, $m, @v); |
12
|
|
|
|
|
|
|
sub _need_module { |
13
|
45
|
|
|
45
|
|
82
|
my ( $opts, $m, @v ) = @_; |
14
|
45
|
100
|
66
|
|
|
155
|
_require_module($m) if $opts->{REQUIRE} // $opts->{require}->( $m, @v ); |
15
|
43
|
100
|
|
|
|
399
|
$m->VERSION(@v) if @v; |
16
|
34
|
100
|
|
|
|
197
|
return wantarray ? ( $m, $m->VERSION ) : $m; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _opts { |
20
|
31
|
|
100
|
31
|
|
47
|
my %opts = ( require => 1, %{ shift // {} } ); |
|
31
|
|
|
|
|
167
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$opts{REQUIRE} = !!delete $opts{require} |
23
|
31
|
100
|
|
|
|
127
|
unless ref $opts{require} eq 'CODE'; |
24
|
|
|
|
|
|
|
|
25
|
31
|
|
|
|
|
77
|
return \%opts; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Diagnostics: |
29
|
|
|
|
|
|
|
# Can't locate Foo.pm in @INC (you may need to install the Foo module) (@INC contains: |
30
|
|
|
|
|
|
|
# Carp version 2.3 required--this is only version 1.40 at |
31
|
|
|
|
|
|
|
# Foo2 does not define $Foo2::VERSION--version check failed at |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# _try_module($opts, $m, @v); |
34
|
|
|
|
|
|
|
sub _try_module { |
35
|
57
|
|
|
57
|
|
98
|
my ( $opts, $m, @v ) = @_; |
36
|
57
|
100
|
66
|
|
|
144
|
if ( $opts->{REQUIRE} // $opts->{require}->( $m, @v ) ) { |
37
|
43
|
|
|
|
|
64
|
eval { _require_module($m) }; |
|
43
|
|
|
|
|
78
|
|
38
|
43
|
100
|
|
|
|
200
|
if ($@) { |
39
|
8
|
|
|
|
|
14
|
my $err = $@; |
40
|
8
|
100
|
|
|
|
50
|
$err =~ /\ACan't locate\b/ ? return : die $err; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
49
|
100
|
|
|
|
100
|
if (@v) { |
44
|
33
|
|
|
|
|
41
|
eval { $m->VERSION(@v) }; |
|
33
|
|
|
|
|
321
|
|
45
|
33
|
100
|
|
|
|
102
|
if ($@) { |
46
|
15
|
|
|
|
|
21
|
my $err = $@; |
47
|
15
|
100
|
|
|
|
88
|
$err =~ /\A\S+ version \S+ required\b/ ? return : die $err; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
34
|
100
|
|
|
|
166
|
return wantarray ? ( $m, $m->VERSION ) : $m; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# TODO need_modules($spec1, $spec1) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _require_module { |
56
|
77
|
|
|
77
|
|
188
|
( my $f = "$_[0].pm" ) =~ s{::}{/}g; |
57
|
77
|
|
|
|
|
4444
|
require $f; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub croak { |
61
|
0
|
|
|
0
|
0
|
|
require Carp; |
62
|
5
|
|
|
5
|
|
35
|
no warnings 'redefine'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
1289
|
|
63
|
0
|
|
|
|
|
|
*croak = \&Carp::croak; |
64
|
0
|
|
|
|
|
|
goto &croak; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
### EXPERIMENTAL |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# _generate_code($opts, $m, @v); |
70
|
|
|
|
|
|
|
sub _generate_code { |
71
|
0
|
|
|
0
|
|
|
my $opts = shift; |
72
|
0
|
|
0
|
|
|
|
$opts->{context} ||= 'void'; |
73
|
0
|
|
0
|
|
|
|
$opts->{indent} ||= ' ' x 4; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my ( $m, @v ) = @_; |
76
|
0
|
|
|
|
|
|
my $code = "require $m;\n"; |
77
|
0
|
0
|
|
|
|
|
$code .= "$m->VERSION('$v[0]');\n" if @v; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ( $opts->{context} eq 'void' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# nothing to do |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif ( $opts->{context} eq 'scalar' ) { |
84
|
0
|
|
|
|
|
|
$code .= "'$m';\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ( $opts->{context} eq 'list' ) { |
87
|
0
|
|
|
|
|
|
$code .= "('$m', '$m'->VERSION);\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if ( $opts->{wrap} ) { |
91
|
0
|
0
|
|
|
|
|
$code =~ s/^/$opts->{indent}/mg if $opts->{indent}; |
92
|
0
|
|
|
|
|
|
$code = "do {\n$code};\n"; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $code; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |