Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Module Dependencies

by Brovnik (Hermit)
on Jun 05, 2001 at 19:12 UTC ( [id://85848]=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Brovnik
Description: The script generates a database with information about the installed modules on your system.

They are stored in a mysql database.

A trivial CGI::Application can then be used to browse the database.

Will need Depend::Module to run, and Depend::Browse for the browser application, available here

Sample of the browser program running is Here<here

#! /usr/local/bin/perl -w

# Copyright (c) 2001  Richard Nuttall richard@nuttall.uk.net

# This uses the Depend::Module to generate a database of the dependenc
+ies
# of Perl Modules installed on your system.

use strict;
use File::Find;

use Data::Dumper;    # for debugging
use DBI();
use Depend::Module;
use Date::Manip;

connect(droptable=>1,log=>1,user=>'root',password=>'sql');

find(\&wanted, @INC);

do_module("/usr/local/lib/perl5/5.6.1/sun4-solaris/perllocal.pod");

populate_usedby();

cleanup();

########## SUBROUTINES BELOW #########

sub wanted
{
   my $module = $File::Find::name;
   return unless $module =~ /\.pm$/;
   return if $module =~ /^\./;

   #print "$_\n";
   open(FILE, $module) || warn("Can't open [$module]") && return;

   my $package      = undef;
   my $packagecount = 0;
   my @remember     = ();
   my $line         = 0;
   my $pod          = 0;
   my $p = undef;

   report("\n$module");
   while (<FILE>)
   {
      chomp;
      if (/^=cut/)
      {
         report("WARN: Found [$_]@ line [$line] outside pod") unless $
+pod;
         $pod = 0;
         next;
      }
      elsif (/^=/)
      {
         $pod++;
         next;
      }
      next if $pod;

      if (/^__END__/)
      {
         last;
      }
      elsif (/^package\s+([\w:_]+)/)
      {
         my $package = $1;
         next if $package eq 'main';

         report("   package [$package][$packagecount]");
         $p = Depend::Module::new($package, $module);
         $p->use(@remember);
         @remember = ();
      }
      elsif (/^(use|require)\s+([\w:_\d\.]+)/)
      {
         my $word     = $1;
         my $used     = $2;

         report("   ${word}s [$used]]");
         if ($p)
         {
            $p->use($used);
         }
         else
         {
            push @remember, $used;
        }
      }
      elsif (/^\$VERSION\s*=\s*(\$VERSION\s*=\s*|)['"]*([\d\.]+)/)
      {
         my $version = $2;

         report("   version [$version]");
         $p->set_version($version) if $p;
         report("WARN: Version [$version] but \$p not set in\n   [$mod
+ule]")
           unless $p;
      }
      # try to find RCSed versions
      elsif (/^\$VERSION\s*=\s.*\$Revision: ([\d\.]+)/)
      {
         my $version = $1;

         report("   version [$version]RCS");
         $p->set_version($version) if $p;
         report("WARN: Version [$version] but \$p not set in\n   [$mod
+ule]")
           unless $p;
      }
      elsif (/^(use|require|package|\$VERSION)\b/)
      {
         report("WARN: Didn't match [$_] in\n   [$module]");
      }
   }

   close(FILE);
}

sub do_module
{
   my $module = shift;
   open(FILE,$module) || croak("Can't open [$module]");

   my $package = undef;
   my $packagecount = 0;
   my $version;
   my $date;
   my $exefiles;
   my $p;

   report("\n$module");

   while (<FILE>)
   {
      chomp;
      if (/^=head2 (.+): C\<Module\> L\<(.+)\|/)
      {
         $date       = UnixDate(ParseDate($1),"%Y-%m-%d");
         report("Date -> [$date]");
         $package     = $2;
         $p = Depend::Module::new($package);
         $p->set_date($date);
      }
      elsif (/^C\<VERSION: (.+)\>$/)
      {
         $p->set_version($1);
      }
      elsif (/^C\<EXE_FILES: (.+)\>$/)
      {
         $p->set_exefiles(join('+',split(/ /,$1)));
      }
   }
   close(FILE);
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://85848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found