#!/usr/bin/env perl
# pmload -- show what files a module loads

# ------ pragmas
use strict;
use warnings;

our $VERSION = '2.0.0';

# ------ define variables
my $module = undef;	# module name
my %seen = ();		# list of files we've seen before

BEGIN { $^W = 1 }

die "usage: $0 module\n" unless @ARGV == 1;

%seen = %INC;

$module = shift;
eval "local \$^W = 0; require $module";

if ($@) {
    $@ =~ s/at \(eval.*$//;
    die "$0: $@";

for my $path (values %INC) {
    print "$path\n" unless $seen{$path};


=head1 NAME

pmload - show what files a given module loads at compile time


Given an argument of a module name, show all the files 
that are loaded directly or indirectly when the module
is used at compile-time.


    $ pmload IO::Handle

    $ cat `pmload IO::Socket` | wc -l

    $ oldperl -S pmload Tk

=head1 NOTE

If the programmers used a delayed C<require>, those files won't show up.
Furthermore, this doesn't show all possible files that get opened,
just those that those up in %INC.  Most systems have a way to trace
system calls.  You can use this to find the real answer.  First, get a
baseline with no modules loaded.

    $ strace perl -e 1 2>&1 | perl -nle '/^open\("(.*?)".* = [^-]/ && print $1'

    $ strace perl -e 1 2>&1 | grep -c '^open.*= [^-]'

Now add module loads and see what you get:

    $ strace perl -MIO::Socket -e 1 2>&1 | grep -c '^open.*= [^-]'

    $ strace perl -MTk -e 1 2>&1 | grep -c '^open.*= [^-]'

=head1 SEE ALSO

Devel::Loaded, plxload(1).


Copyright (C) 1999 Tom Christiansen.

Copyright (C) 2006-2014 Mark Leighton Fisher.

=head1 LICENSE

This is free software; you can redistribute it and/or modify it
under the terms of either:
(a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
(b) the Perl "Artistic License".
(This is the Perl 5 licensing scheme.)

Please note this is a change from the
original pmtools-1.00 (still available on CPAN),
as pmtools-1.00 were licensed only under the
Perl "Artistic License".