| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | # pmpath -- show path to a perl module | ||||||||||
| 3 | |||||||||||
| 4 | # ------ pragmas | ||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | our $VERSION = '2.0.0'; | |||||||||
| 9 | |||||||||||
| 10 | # ------ define variables | ||||||||||
| 11 | 5 | my $errors = 0; # error count | |||||||||
| 12 | 5 | my $fullpath = undef; # full path | |||||||||
| 13 | 5 | my $module = undef; # module name | |||||||||
| 14 | 5 | my $shortpath = undef; # short path | |||||||||
| 15 | |||||||||||
| 16 | 5 | ▶ | BEGIN { $^W = 1 } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 5 | $errors = 0; | |||||||||
| 19 | |||||||||||
| 20 | 5 | for $module (@ARGV) { | |||||||||
| 21 | 5 | eval "local \$^W = 0; require $module"; | |||||||||
| 22 | 5 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | $@ =~ s/at \(eval.*$//; | |||||||||
| 24 | 0 | warn "$0: $@"; | |||||||||
| 25 | 0 | $errors++; | |||||||||
| 26 | 0 | next; | |||||||||
| 27 | } | ||||||||||
| 28 | 5 | for ($shortpath = $module) { | |||||||||
| 29 | 5 | s{::}{/}g; | |||||||||
| 30 | 5 | s/$/.pm/; | |||||||||
| 31 | } | ||||||||||
| 32 | # print "$module is in " if @ARGV > 1; | ||||||||||
| 33 | 5 | ▶ | if (defined($fullpath = $INC{$shortpath})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 5 | print "$fullpath\n"; | |||||||||
| 35 | } | ||||||||||
| 36 | else { | ||||||||||
| 37 | 0 | $errors++; | |||||||||
| 38 | 0 | warn "$0: path unavailable in %INC\n"; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 5 | exit ($errors != 0); | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||