Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if used modules are pure perl?

Tags:

module

perl

If I have Perl code which usees a lot of modules, is there a fast and easy way to find out if some of this modules are not pure Perl modules?

like image 432
sid_com Avatar asked Jan 02 '13 16:01

sid_com


People also ask

How do I tell what Perl modules are installed?

Answer: To list all the installed Perl modules in the system, use the following command. # perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\. pm\z/ }, no_chdir => 1 }, @INC' /usr/local/lib/perl/5.10.

What is CPAN module in Perl?

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors.

What is the difference between package and module in Perl?

A Perl package is a collection of code which resides in its own namespace. Perl module is a package defined in a file having the same name as that of the package and having extension . pm. Two different modules may contain a variable or a function of the same name.


2 Answers

@DynaLoader::dl_modules contains the list of XS modules loaded.

perl -MSome::Module1 -MSome::Module2 -M... \
   -MDynaLoader -E'say for sort @DynaLoader::dl_modules;'

Or if you wanted to write it as a script:

# Usage: script Some::Module1 Some::Module2 ...

use 5.010;
use DynaLoader qw( );

while (defined($_ = shift(@ARGV))) {
   s{::}{/}g;
   $_ .= ".pm";
   require $_;
}

say for sort @DynaLoader::dl_modules;

Of course, nothing's stopping you from putting it in an existing script either.

use 5.010;
use DynaLoader qw( );
END { say for sort @DynaLoader::dl_modules; }
like image 147
ikegami Avatar answered Nov 03 '22 01:11

ikegami


This looks like a job for what I call a "blowup sensor". You could just boobytrap the hooks, by putting this at the top of the first module:

BEGIN { 
    require Carp; #Does the stack stuff
    # Fool Perl into thinking that these are already loaded.
    @INC{ 'XSLoader.pm', 'DynaLoader.pm' } = ( 1, 1 );

    # overload boobytrapped stubs
    sub XSLoader::load        { Carp::confess( 'NOT Pure Perl!' ); }
    sub DynaLoader::bootstrap { Carp::confess( 'NOT Pure Perl!' ); }
}
like image 43
Axeman Avatar answered Nov 03 '22 01:11

Axeman