line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::whichpm; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::whichpm - locate a Perl module and it's version |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use App::whichpm 'which_pm'; |
10
|
|
|
|
|
|
|
my ($filename, $version) = which_pm('App::whichpm'); |
11
|
|
|
|
|
|
|
my $filename = App::whichpm::find('App::whichpm'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
from shell: |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
whichpm App::whichpm |
16
|
|
|
|
|
|
|
whichpm Universe::ObservableUniverse::Filament::SuperCluster::Cluster::Group::Galaxy::Arm::Bubble::InterstellarCloud::SolarSystem::Earth |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Loads a given module and reports it's location and version. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The similar function can be achieved via: |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
perldoc -l Some::Module |
25
|
|
|
|
|
|
|
perl -MSome::Module -le 'print $INC{"Some/Module.pm"}' |
26
|
|
|
|
|
|
|
perl -MSome::Module -le 'print Some::Module->VERSION' |
27
|
|
|
|
|
|
|
pmpath Some::Module |
28
|
|
|
|
|
|
|
pmvers Some::Module |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
28992
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
33
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
25
|
|
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
4
|
use base 'Exporter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
534
|
|
40
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
41
|
|
|
|
|
|
|
which_pm |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 EXPORTS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 which_pm |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
same as L only exported under C name. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
*which_pm = *find; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 FUNCTIONS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 find($module_name) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Loads the C<$module_name>. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
In scalar context returns filename corresponding to C<$module_name>. |
61
|
|
|
|
|
|
|
In array context returns filename and version. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
C<$module_name> can be either C or C |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub find { |
68
|
10
|
|
|
10
|
1
|
81
|
my $module_name = shift; |
69
|
10
|
|
|
|
|
17
|
my $module_filename; |
70
|
|
|
|
|
|
|
|
71
|
10
|
100
|
|
|
|
40
|
if ($module_name =~ m/\.pm$/xms) { |
72
|
2
|
|
|
|
|
7
|
$module_name = substr($module_name, 0, -3); |
73
|
2
|
|
|
|
|
9
|
$module_name =~ s{[/\\]}{::}g; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
10
|
|
|
|
|
18
|
$module_filename = $module_name.'.pm'; |
77
|
10
|
|
|
|
|
39
|
my $module_inc_filename = join('/', split('::', $module_filename)); |
78
|
10
|
|
|
|
|
104
|
$module_filename = File::Spec->catfile(split('::', $module_filename)); |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
1
|
|
615
|
eval "use $module_name;"; |
|
1
|
|
|
1
|
|
57
|
|
|
1
|
|
|
1
|
|
17
|
|
|
1
|
|
|
1
|
|
7
|
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
1
|
|
14
|
|
|
1
|
|
|
1
|
|
649
|
|
|
1
|
|
|
1
|
|
37
|
|
|
1
|
|
|
1
|
|
19
|
|
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
547
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
470
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
510
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
1031
|
|
81
|
10
|
|
|
|
|
55
|
my $filename = $INC{$module_inc_filename}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# if the filename is not in %INC then try to search the @INC folders |
84
|
10
|
100
|
|
|
|
27
|
if (not $filename) { |
85
|
3
|
|
|
|
|
7
|
foreach my $inc_path (@INC) { |
86
|
21
|
|
|
|
|
213
|
my $module_full_filename = File::Spec->catfile($inc_path, $module_filename); |
87
|
21
|
100
|
|
|
|
486
|
return $module_full_filename |
88
|
|
|
|
|
|
|
if -f $module_full_filename; |
89
|
|
|
|
|
|
|
} |
90
|
2
|
|
|
|
|
16
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# MSWin32 has unix / in the %INC folder paths, so recreate the filename |
94
|
7
|
|
|
|
|
161
|
$filename = File::Spec->catfile(split(m{[/\\]}, $filename)); |
95
|
|
|
|
|
|
|
|
96
|
7
|
100
|
|
|
|
73
|
if (wantarray) { |
97
|
3
|
|
|
|
|
6
|
my $version = eval { $module_name->VERSION }; |
|
3
|
|
|
|
|
375
|
|
98
|
3
|
100
|
|
|
|
34
|
return ($filename, (defined $version ? $version : ())); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
27
|
return $filename |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |