| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SHARYANTO::Module::Path; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
449
|
use 5.010001; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
2009
|
use Perinci::Sub::Util qw(gen_modified_sub); |
|
|
1
|
|
|
|
|
1902
|
|
|
|
1
|
|
|
|
|
163
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(module_path pod_path); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.21'; # VERSION |
|
14
|
|
|
|
|
|
|
our $DATE = '2014-12-02'; # DATE |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $SEPARATOR; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our %SPEC; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
BEGIN { |
|
21
|
1
|
50
|
|
1
|
|
11
|
if ($^O =~ /^(dos|os2)/i) { |
|
|
|
50
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
$SEPARATOR = '\\'; |
|
23
|
|
|
|
|
|
|
} elsif ($^O =~ /^MacOS/i) { |
|
24
|
0
|
|
|
|
|
0
|
$SEPARATOR = ':'; |
|
25
|
|
|
|
|
|
|
} else { |
|
26
|
1
|
|
|
|
|
426
|
$SEPARATOR = '/'; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$SPEC{module_path} = { |
|
31
|
|
|
|
|
|
|
v => 1.1, |
|
32
|
|
|
|
|
|
|
summary => 'Get path to locally installed Perl module', |
|
33
|
|
|
|
|
|
|
description => <<'_', |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Search `@INC` (reference entries are skipped) and return path(s) to Perl module |
|
36
|
|
|
|
|
|
|
files with the requested name. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This function is like the one from `Module::Path`, except with a different |
|
39
|
|
|
|
|
|
|
interface and more options (finding all matches instead of the first, the option |
|
40
|
|
|
|
|
|
|
of not absolutizing paths, finding `.pmc` & `.pod` files, finding module |
|
41
|
|
|
|
|
|
|
prefixes). |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
_ |
|
44
|
|
|
|
|
|
|
args => { |
|
45
|
|
|
|
|
|
|
module => { |
|
46
|
|
|
|
|
|
|
summary => 'Module name to search', |
|
47
|
|
|
|
|
|
|
schema => 'str*', |
|
48
|
|
|
|
|
|
|
req => 1, |
|
49
|
|
|
|
|
|
|
pos => 0, |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
find_pm => { |
|
52
|
|
|
|
|
|
|
summary => 'Whether to find .pm files', |
|
53
|
|
|
|
|
|
|
schema => 'bool', |
|
54
|
|
|
|
|
|
|
default => 1, |
|
55
|
|
|
|
|
|
|
}, |
|
56
|
|
|
|
|
|
|
find_pmc => { |
|
57
|
|
|
|
|
|
|
summary => 'Whether to find .pmc files', |
|
58
|
|
|
|
|
|
|
schema => 'bool', |
|
59
|
|
|
|
|
|
|
default => 1, |
|
60
|
|
|
|
|
|
|
}, |
|
61
|
|
|
|
|
|
|
find_pod => { |
|
62
|
|
|
|
|
|
|
summary => 'Whether to find .pod files', |
|
63
|
|
|
|
|
|
|
schema => 'bool', |
|
64
|
|
|
|
|
|
|
default => 0, |
|
65
|
|
|
|
|
|
|
}, |
|
66
|
|
|
|
|
|
|
find_prefix => { |
|
67
|
|
|
|
|
|
|
summary => 'Whether to find module prefixes', |
|
68
|
|
|
|
|
|
|
schema => 'bool', |
|
69
|
|
|
|
|
|
|
default => 0, |
|
70
|
|
|
|
|
|
|
}, |
|
71
|
|
|
|
|
|
|
all => { |
|
72
|
|
|
|
|
|
|
summary => 'Return all results instead of just the first', |
|
73
|
|
|
|
|
|
|
schema => 'bool', |
|
74
|
|
|
|
|
|
|
default => 0, |
|
75
|
|
|
|
|
|
|
}, |
|
76
|
|
|
|
|
|
|
abs => { |
|
77
|
|
|
|
|
|
|
summary => 'Whether to return absolute paths', |
|
78
|
|
|
|
|
|
|
schema => 'bool', |
|
79
|
|
|
|
|
|
|
default => 0, |
|
80
|
|
|
|
|
|
|
}, |
|
81
|
|
|
|
|
|
|
}, |
|
82
|
|
|
|
|
|
|
result => { |
|
83
|
|
|
|
|
|
|
schema => ['any' => of => ['str*', ['array*' => of => 'str*']]], |
|
84
|
|
|
|
|
|
|
}, |
|
85
|
|
|
|
|
|
|
result_naked => 1, |
|
86
|
|
|
|
|
|
|
}; |
|
87
|
|
|
|
|
|
|
sub module_path { |
|
88
|
6
|
|
|
6
|
1
|
1202
|
my %args = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
6
|
50
|
|
|
|
20
|
my $module = $args{module} or die "Please specify module"; |
|
91
|
|
|
|
|
|
|
|
|
92
|
6
|
|
50
|
|
|
31
|
$args{abs} //= 0; |
|
93
|
6
|
|
50
|
|
|
62
|
$args{all} //= 0; |
|
94
|
6
|
|
50
|
|
|
21
|
$args{find_pm} //= 1; |
|
95
|
6
|
|
50
|
|
|
19
|
$args{find_pmc} //= 1; |
|
96
|
6
|
|
50
|
|
|
18
|
$args{find_pod} //= 0; |
|
97
|
6
|
|
100
|
|
|
18
|
$args{find_prefix} //= 0; |
|
98
|
|
|
|
|
|
|
|
|
99
|
6
|
50
|
|
|
|
14
|
require Cwd if $args{abs}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
6
|
|
|
|
|
6
|
my @res; |
|
102
|
6
|
50
|
|
5
|
|
25
|
my $add = sub { push @res, $args{abs} ? Cwd::abs_path($_[0]) : $_[0] }; |
|
|
5
|
|
|
|
|
19
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
7
|
my $relpath; |
|
105
|
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
17
|
($relpath = $module) =~ s/::/$SEPARATOR/g; |
|
107
|
6
|
|
|
|
|
19
|
$relpath =~ s/\.(pm|pmc|pod)\z//i; |
|
108
|
|
|
|
|
|
|
|
|
109
|
6
|
|
|
|
|
12
|
foreach my $dir (@INC) { |
|
110
|
43
|
50
|
|
|
|
67
|
next if not defined($dir); |
|
111
|
43
|
50
|
|
|
|
60
|
next if ref($dir); |
|
112
|
|
|
|
|
|
|
|
|
113
|
43
|
|
|
|
|
67
|
my $prefix = $dir . $SEPARATOR . $relpath; |
|
114
|
43
|
50
|
|
|
|
72
|
if ($args{find_pmc}) { |
|
115
|
43
|
|
|
|
|
42
|
my $file = $prefix . ".pmc"; |
|
116
|
43
|
50
|
|
|
|
550
|
if (-f $file) { |
|
117
|
0
|
|
|
|
|
0
|
$add->($file); |
|
118
|
0
|
0
|
|
|
|
0
|
last unless $args{all}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
43
|
50
|
|
|
|
84
|
if ($args{find_pm}) { |
|
122
|
43
|
|
|
|
|
55
|
my $file = $prefix . ".pm"; |
|
123
|
43
|
100
|
|
|
|
439
|
if (-f $file) { |
|
124
|
4
|
|
|
|
|
12
|
$add->($file); |
|
125
|
4
|
50
|
|
|
|
12
|
last unless $args{all}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
39
|
50
|
|
|
|
60
|
if ($args{find_pod}) { |
|
129
|
0
|
|
|
|
|
0
|
my $file = $prefix . ".pod"; |
|
130
|
0
|
0
|
|
|
|
0
|
if (-f $file) { |
|
131
|
0
|
|
|
|
|
0
|
$add->($file); |
|
132
|
0
|
0
|
|
|
|
0
|
last unless $args{all}; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
39
|
100
|
|
|
|
77
|
if ($args{find_prefix}) { |
|
136
|
8
|
100
|
|
|
|
62
|
if (-d $prefix) { |
|
137
|
1
|
|
|
|
|
3
|
$add->($prefix); |
|
138
|
1
|
50
|
|
|
|
6
|
last unless $args{all}; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
6
|
50
|
|
|
|
13
|
if ($args{all}) { |
|
144
|
0
|
|
|
|
|
0
|
return \@res; |
|
145
|
|
|
|
|
|
|
} else { |
|
146
|
6
|
100
|
|
|
|
64
|
return @res ? $res[0] : undef; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
gen_modified_sub( |
|
151
|
|
|
|
|
|
|
output_name => 'pod_path', |
|
152
|
|
|
|
|
|
|
base_name => 'module_path', |
|
153
|
|
|
|
|
|
|
summary => 'Find path to Perl POD files', |
|
154
|
|
|
|
|
|
|
description => <<'_', |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Shortcut for `module_path(..., find_pm=>0, find_pmc=>0, find_pod=>1, |
|
157
|
|
|
|
|
|
|
find_prefix=>1, )`. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
_ |
|
160
|
|
|
|
|
|
|
remove_args => [qw/find_pm find_pmc find_pod find_prefix/], |
|
161
|
|
|
|
|
|
|
output_code => sub { |
|
162
|
0
|
|
|
0
|
|
|
my %args = @_; |
|
163
|
0
|
|
|
|
|
|
module_path( |
|
164
|
|
|
|
|
|
|
%args, find_pm=>0, find_pmc=>0, find_pod=>1, find_prefix=>0); |
|
165
|
|
|
|
|
|
|
}, |
|
166
|
|
|
|
|
|
|
); |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
|
169
|
|
|
|
|
|
|
# ABSTRACT: Get path to locally installed Perl module |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |