line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Module::Spec::V0; |
3
|
|
|
|
|
|
|
$Module::Spec::V0::VERSION = '0.8.0'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Module::Spec internal utilities |
5
|
5
|
|
|
5
|
|
542
|
use 5.012; |
|
5
|
|
|
|
|
15
|
|
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
|
|
97
|
my ( $opts, $m, @v ) = @_; |
14
|
45
|
100
|
66
|
|
|
163
|
_require_module($m) if $opts->{REQUIRE} // $opts->{require}->( $m, @v ); |
15
|
43
|
100
|
|
|
|
454
|
$m->VERSION(@v) if @v; |
16
|
34
|
100
|
|
|
|
216
|
return wantarray ? ( $m, $m->VERSION ) : $m; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _opts { |
20
|
31
|
|
100
|
31
|
|
46
|
my %opts = ( require => 1, %{ shift // {} } ); |
|
31
|
|
|
|
|
155
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$opts{REQUIRE} = !!delete $opts{require} |
23
|
31
|
100
|
|
|
|
124
|
unless ref $opts{require} eq 'CODE'; |
24
|
|
|
|
|
|
|
|
25
|
31
|
|
|
|
|
68
|
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
|
|
114
|
my ( $opts, $m, @v ) = @_; |
36
|
57
|
100
|
66
|
|
|
134
|
if ( $opts->{REQUIRE} // $opts->{require}->( $m, @v ) ) { |
37
|
43
|
|
|
|
|
66
|
eval { _require_module($m) }; |
|
43
|
|
|
|
|
71
|
|
38
|
43
|
100
|
|
|
|
175
|
if ($@) { |
39
|
8
|
|
|
|
|
14
|
my $err = $@; |
40
|
8
|
100
|
|
|
|
46
|
$err =~ /\ACan't locate\b/ ? return : die $err; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
49
|
100
|
|
|
|
105
|
if (@v) { |
44
|
33
|
|
|
|
|
41
|
eval { $m->VERSION(@v) }; |
|
33
|
|
|
|
|
296
|
|
45
|
33
|
100
|
|
|
|
99
|
if ($@) { |
46
|
15
|
|
|
|
|
18
|
my $err = $@; |
47
|
15
|
100
|
|
|
|
76
|
$err =~ /\A\S+ version \S+ required\b/ ? return : die $err; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
34
|
100
|
|
|
|
150
|
return wantarray ? ( $m, $m->VERSION ) : $m; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# TODO need_modules($spec1, $spec1) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _require_module { |
56
|
77
|
|
|
77
|
|
189
|
( my $f = "$_[0].pm" ) =~ s{::}{/}g; |
57
|
77
|
|
|
|
|
4114
|
require $f; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub croak { |
61
|
0
|
|
|
0
|
0
|
|
require Carp; |
62
|
5
|
|
|
5
|
|
33
|
no warnings 'redefine'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
1513
|
|
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__ |