| 1 |
#!/usr/bin/env perl |
| 2 |
# pmload -- show what files a module loads |
| 3 |
|
| 4 |
# ------ pragmas |
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
our $VERSION = '2.0.0'; |
| 9 |
|
| 10 |
# ------ define variables |
| 11 |
my $module = undef; # module name |
| 12 |
my %seen = (); # list of files we've seen before |
| 13 |
|
| 14 |
BEGIN { $^W = 1 } |
| 15 |
|
| 16 |
die "usage: $0 module\n" unless @ARGV == 1; |
| 17 |
|
| 18 |
%seen = %INC; |
| 19 |
|
| 20 |
$module = shift; |
| 21 |
eval "local \$^W = 0; require $module"; |
| 22 |
|
| 23 |
if ($@) { |
| 24 |
$@ =~ s/at \(eval.*$//; |
| 25 |
die "$0: $@"; |
| 26 |
} |
| 27 |
|
| 28 |
for my $path (values %INC) { |
| 29 |
print "$path\n" unless $seen{$path}; |
| 30 |
} |
| 31 |
|
| 32 |
__END__ |
| 33 |
|
| 34 |
=head1 NAME |
| 35 |
|
| 36 |
pmload - show what files a given module loads at compile time |
| 37 |
|
| 38 |
=head1 DESCRIPTION |
| 39 |
|
| 40 |
Given an argument of a module name, show all the files |
| 41 |
that are loaded directly or indirectly when the module |
| 42 |
is used at compile-time. |
| 43 |
|
| 44 |
=head1 EXAMPLES |
| 45 |
|
| 46 |
$ pmload IO::Handle |
| 47 |
/usr/local/devperl/lib/5.00554/Exporter.pm |
| 48 |
/usr/local/devperl/lib/5.00554/Carp.pm |
| 49 |
/usr/local/devperl/lib/5.00554/strict.pm |
| 50 |
/usr/local/devperl/lib/5.00554/vars.pm |
| 51 |
/usr/local/devperl/lib/5.00554/i686-linux/DynaLoader.pm |
| 52 |
/usr/local/devperl/lib/5.00554/i686-linux/IO/Handle.pm |
| 53 |
/usr/local/devperl/lib/5.00554/Symbol.pm |
| 54 |
/usr/local/devperl/lib/5.00554/i686-linux/IO/File.pm |
| 55 |
/usr/local/devperl/lib/5.00554/SelectSaver.pm |
| 56 |
/usr/local/devperl/lib/5.00554/i686-linux/Fcntl.pm |
| 57 |
/usr/local/devperl/lib/5.00554/AutoLoader.pm |
| 58 |
/usr/local/devperl/lib/5.00554/i686-linux/IO.pm |
| 59 |
/usr/local/devperl/lib/5.00554/i686-linux/IO/Seekable.pm |
| 60 |
|
| 61 |
$ cat `pmload IO::Socket` | wc -l |
| 62 |
4015 |
| 63 |
|
| 64 |
$ oldperl -S pmload Tk |
| 65 |
/usr/lib/perl5/site_perl/Tk/Pretty.pm |
| 66 |
/usr/lib/perl5/Symbol.pm |
| 67 |
/usr/lib/perl5/site_perl/Tk/Frame.pm |
| 68 |
/usr/lib/perl5/site_perl/Tk/Toplevel.pm |
| 69 |
/usr/lib/perl5/strict.pm |
| 70 |
/usr/lib/perl5/Exporter.pm |
| 71 |
/usr/lib/perl5/vars.pm |
| 72 |
/usr/lib/perl5/site_perl/auto/Tk/Wm/autosplit.ix |
| 73 |
/usr/lib/perl5/site_perl/auto/Tk/Widget/autosplit.ix |
| 74 |
/usr/lib/perl5/site_perl/Tk.pm |
| 75 |
/usr/lib/perl5/i386-linux/5.00404/DynaLoader.pm |
| 76 |
/usr/lib/perl5/site_perl/auto/Tk/Frame/autosplit.ix |
| 77 |
/usr/lib/perl5/site_perl/auto/Tk/Toplevel/autosplit.ix |
| 78 |
/usr/lib/perl5/Carp.pm |
| 79 |
/usr/lib/perl5/site_perl/auto/Tk/autosplit.ix |
| 80 |
/usr/lib/perl5/site_perl/Tk/CmdLine.pm |
| 81 |
/usr/lib/perl5/site_perl/Tk/MainWindow.pm |
| 82 |
/usr/lib/perl5/site_perl/Tk/Submethods.pm |
| 83 |
/usr/lib/perl5/site_perl/Tk/Configure.pm |
| 84 |
/usr/lib/perl5/AutoLoader.pm |
| 85 |
/usr/lib/perl5/site_perl/Tk/Derived.pm |
| 86 |
/usr/lib/perl5/site_perl/Tk/Image.pm |
| 87 |
/usr/lib/perl5/site_perl/Tk/Wm.pm |
| 88 |
/usr/lib/perl5/site_perl/Tk/Widget.pm |
| 89 |
|
| 90 |
=head1 NOTE |
| 91 |
|
| 92 |
If the programmers used a delayed C<require>, those files won't show up. |
| 93 |
Furthermore, this doesn't show all possible files that get opened, |
| 94 |
just those that those up in %INC. Most systems have a way to trace |
| 95 |
system calls. You can use this to find the real answer. First, get a |
| 96 |
baseline with no modules loaded. |
| 97 |
|
| 98 |
$ strace perl -e 1 2>&1 | perl -nle '/^open\("(.*?)".* = [^-]/ && print $1' |
| 99 |
/etc/ld.so.cache |
| 100 |
/lib/libnsl.so.1 |
| 101 |
/lib/libdb.so.2 |
| 102 |
/lib/libdl.so.2 |
| 103 |
/lib/libm.so.6 |
| 104 |
/lib/libc.so.6 |
| 105 |
/lib/libcrypt.so.1 |
| 106 |
/dev/null |
| 107 |
|
| 108 |
$ strace perl -e 1 2>&1 | grep -c '^open.*= [^-]' |
| 109 |
8 |
| 110 |
|
| 111 |
Now add module loads and see what you get: |
| 112 |
|
| 113 |
$ strace perl -MIO::Socket -e 1 2>&1 | grep -c '^open.*= [^-]' |
| 114 |
24 |
| 115 |
|
| 116 |
$ strace perl -MTk -e 1 2>&1 | grep -c '^open.*= [^-]' |
| 117 |
35 |
| 118 |
|
| 119 |
=head1 SEE ALSO |
| 120 |
|
| 121 |
Devel::Loaded, plxload(1). |
| 122 |
|
| 123 |
=head1 AUTHORS and COPYRIGHTS |
| 124 |
|
| 125 |
Copyright (C) 1999 Tom Christiansen. |
| 126 |
|
| 127 |
Copyright (C) 2006-2014 Mark Leighton Fisher. |
| 128 |
|
| 129 |
=head1 LICENSE |
| 130 |
|
| 131 |
This is free software; you can redistribute it and/or modify it |
| 132 |
under the terms of either: |
| 133 |
(a) the GNU General Public License as published by the Free |
| 134 |
Software Foundation; either version 1, or (at your option) any |
| 135 |
later version, or |
| 136 |
(b) the Perl "Artistic License". |
| 137 |
(This is the Perl 5 licensing scheme.) |
| 138 |
|
| 139 |
Please note this is a change from the |
| 140 |
original pmtools-1.00 (still available on CPAN), |
| 141 |
as pmtools-1.00 were licensed only under the |
| 142 |
Perl "Artistic License". |