What files does your Perl load?

acme on 2009-05-06T15:27:50

It can interesting to see what files your Perl loads. One way to do this is to use the Linux::Inotify2 module which uses inotify to monitor file changes. Something like:

#!/home/acme/bin/perl
use strict;
use warnings;
use Linux::Inotify2;
use File::Find::Rule;
use Perl6::Say;

my $inotify = new Linux::Inotify2
    or die "Unable to create new inotify object: $!";

foreach my $inc (@INC) {
    next if $inc eq '.';
    foreach my $directory ( File::Find::Rule->new->directory->in($inc) ) {
        $inotify->watch( $directory, IN_ACCESS )
            or die "watch creation failed";
    }
}

while () {
    my @events = $inotify->read;
    unless ( @events > 0 ) {
        print "read error: $!";
        last;
    }
    foreach my $event (@events) {
        say $event->fullname if $event->IN_ACCESS;
    }
}

Which outputs something along the lines of the following if you load Moose by running perl -e 'use Moose' in another terminal:

/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose.pm
/home/acme/perl-5.10.0/lib/5.10.0/strict.pm
/home/acme/perl-5.10.0/lib/5.10.0/warnings.pm
/home/acme/perl-5.10.0/lib/5.10.0/warnings.pm
/home/acme/perl-5.10.0/lib/5.10.0/warnings.pm
/home/acme/perl-5.10.0/lib/5.10.0/warnings.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/Scalar/Util.pm
/home/acme/perl-5.10.0/lib/5.10.0/vars.pm
/home/acme/perl-5.10.0/lib/5.10.0/warnings/register.pm
/home/acme/perl-5.10.0/lib/5.10.0/Exporter.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/List/Util.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/XSLoader.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/auto/List/Util/Util.so
/home/acme/perl-5.10.0/lib/5.10.0/Carp.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/MRO/Compat.pm
/home/acme/perl-5.10.0/lib/5.10.0/mro.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/MRO/Compat.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/MRO/Compat.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Devel/GlobalDestruction.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/auto/Devel/GlobalDestruction/GlobalDestruction.so
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Data/OptList.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Params/Util.pm
/home/acme/perl-5.10.0/lib/5.10.0/overload.pm
/home/acme/perl-5.10.0/lib/5.10.0/overload.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Params/Util.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Params/Util.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Install.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Install.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Install.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Data/OptList.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Sub/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Sub/Name.pm
/home/acme/perl-5.10.0/lib/5.10.0/base.pm
/home/acme/perl-5.10.0/lib/5.10.0/base.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/DynaLoader.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/Config.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/DynaLoader.pm
/home/acme/perl-5.10.0/lib/5.10.0/AutoLoader.pm
/home/acme/perl-5.10.0/lib/5.10.0/AutoLoader.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/auto/Sub/Name/Name.so
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Immutable.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Generated.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Object.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Immutable.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Immutable.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Instance.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Instance.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Wrapped.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Wrapped.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Module.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Package.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/B.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/B.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/auto/B/B.so
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Package.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Accessor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Method/Accessor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/Class/MOP.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/auto/Class/MOP/MOP.so
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/List/MoreUtils.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/List/MoreUtils.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/auto/List/MoreUtils/MoreUtils.so
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/MetaRole.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Exporter.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Overridden.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Augmented.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Error/Default.pm
/home/acme/perl-5.10.0/lib/5.10.0/Carp/Heavy.pm
/home/acme/perl-5.10.0/lib/5.10.0/Carp/Heavy.pm
/home/acme/perl-5.10.0/lib/5.10.0/Carp/Heavy.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Constructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Destructor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/i686-linux/metaclass.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeCoercion.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Accessor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Accessor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Accessor.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Method/Delegation.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Union.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeCoercion/Union.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Parameterized.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Parameterizable.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Class.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Enum.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/TypeConstraint/Registry.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints/OptimizedConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/re.pm
/home/acme/perl-5.10.0/lib/5.10.0/i686-linux/re.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Util/TypeConstraints.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Attribute.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Instance.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Object.pm
/home/acme/perl-5.10.0/lib/5.10.0/if.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Method.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Method/Required.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Composite.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/RoleSummation.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/RoleSummation.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToRole.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToRole.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose/Meta/Role/Application/ToInstance.pm
/home/acme/perl-5.10.0/lib/site_perl/5.10.0/Moose.pm

No, I'm not sure why it's accessing some files multiple times. Now, who can change this into a CPAN module popularity contest?


strace?

merijnb on 2009-05-06T16:02:32

Have a look at the strace output. man strace for more details. dtrace or truss on Solaris. dtrace or ktrace on Mac OSX

too complicated

merlyn on 2009-05-10T04:38:50

END {
  print "$_\n" for sort keys %INC;
}

Re:too complicated

acme on 2009-05-10T19:47:44

The advantage of my approach is that you don't have to modify all your applications ;-)