Perl Code‎ > ‎

pmod.pl

I can't live without this little script. Type "pmod" and the name of a module and it will a.) tell you if the module is installed; b.) tell you the version; and c.) if you pass it the "-v" flag, is also returns an alphabetical list of the module's dependencies.

#!/usr/bin/perl
################################################################################
# $Id: pmod.pl 4 2009-04-30 19:04:46Z v89326 $
# $URL: file:///S:/svn/utilities/trunk/pmod.pl $
################################################################################
#
# Title:   pmod
# Author:  Kurt Kincaid
# VERSION: 0.0.1
#
################################################################################

use Data::Dumper;
use Getopt::Long;
use strict;

our( $class, $module, $version, $proc, $auth, $verbose, $author );
GetOptions( 'verbose' => \$verbose );
$class = shift or die "syntax: pev modulename\n";
$module = $class;
$module =~ s#::#/#g;
$module .= ".pm";

eval { require $module } or die "$class not installed.\n";
eval { $version = $class->VERSION }
  or print "Version information not available for ";
print "$class $version\n";

if ( $verbose ) {
    my $file = $INC{ $module };
    print "\n";
    print "Filename:\n\t$file\n\n";
    open my $PM, "<", $file or die $!;
    my @PM = <$PM>;
    close $PM;
    $proc = depends_on( @PM );
    print "Dependencies:\n";
    foreach my $mod ( @{ $proc } ) {
        $mod =~ s/;//;
        print "\t$mod\n";
    }
}

sub depends_on {
    my @code = @_;
    chomp @code;
    my %mods;
    foreach my $line ( @code ) {
        last if $line eq "__END__";
        if ( $line =~ /^\s*(?:require|use)\s+(\S+)/ ) {
            $mods{ $1 } = 1;
        }
    }
    my @mods = sort { lc( $a ) cmp lc( $b ) } keys %mods;
    return \@mods;
}

################################################################################
# EOF

Comments