Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

MoDetails v0.2

by hacker (Priest)
on Nov 02, 2002 at 16:48 UTC ( #209966=snippet: print w/ replies, xml ) Need Help??

Description: After reading a question on this node about querying installed module versions without having an interactive shell account on the box, I decided to hack up a quick CGI that does what the monk asked, and also adds a bit of additional functionality that could be helpful to others as well.

This module will query your locally installed modules using ExtUtils::Installed, present them in a standard dropdown form using CGI, and when you select a module by name from the list and click "Module Details", it will display the module name, version number, and the files associated with that module, including the full path to them on the system. Additionally, it will link the module name to a CPAN search for that module, so you can read up on the docs for it. Originally, I was going to use File::Basename and run pod2html against $base, and display that, but I figured CPAN's module documentation would be more current, and probably more useful.

It was a quick hack, let me know what you think!

ChangeLog

v0.2
A few small updates, as requested by some monks.

  • Added ability to link to both local and CPAN documentation for the module. This will require pod2html to be installed, and the .html files it creates will be stored in $ENV{'PWD'}, so make sure you put this script where it can write those files.
  • Added the ability to query the local environment (@INC, $^X and $^O for starters)
  • Ripped out the fonts for now, I'll add them and validate the HTML in a later version.

v0.1
Initial release

   #!/usr/bin/perl
   use strict;
   use CGI qw(:standard);
   use File::Basename;
   use ExtUtils::Installed;

   my $script       = $ENV{'SCRIPT_NAME'};
   my $cpan         = "http://search.cpan.org/search";
   my $inst         = ExtUtils::Installed->new();
   my $cgi          = CGI->new();

   print header(),

   start_html({-style =>'font-family: courier;',
               -title =>'MoDetails v0.2'});

   print_form();
   print_results($cgi) if $cgi->param('mod');

   sub print_form {
      push my @modules, $inst->modules();
      my $modname      = $cgi->param('mod');

      print start_form(-name   =>"modules",
                       -action =>"$script?mod=$modname"),

      popup_menu(-name   =>'mod',
                 -value  =>\@modules),

      submit(-label      =>'Module Details'),
      end_form;
   }

   sub print_results {
      my $module = $cgi->param('mod');

      print p({-class=>'c'}, b("Module Name"), 
            ":", $module);

      print p(b("Version currently installed"), ":",
            $inst->version($module));

      push my @filelist, $inst->files($module);

      print p(b("Files Installed by $module"), br(),
            join br(), $inst->files($module));

      push my @podpm, $inst->files($module);

      foreach my $file (@podpm) {
            my $base        = basename($file);
            my $dir         = dirname($file);
            my $nmod        = $module;
            $nmod           =~ s,::,/,;

            if ($file =~ /$nmod.pm/i) {
                  system('/usr/bin/pod2html',
                         "$file",
                         '--outfile',
                         "$base.html");

                  print b("Documentation for"), ":",
                          br(), a({-href=>"$base.html"},
                          "$module.pm"),
                          " (local version)", br();
            }
      }
      print a({-href=>"${cpan}?query=$module&mode=module"},
            "$module"), " (CPAN latest version)", br();

      my @newinc = (split " ", "@INC");

      print br(), b("Environment available to this user"),  
            br(), "\@INC", 
            div({-style=>'padding-left: 20px;'},
            join br(), sort @newinc);

      print br(), b("Host operating system"), br(),
            div({-style=>'padding-left: 20px;'}, "$^O");

      print br(), b("Path to perl binary"), br(),
            div({-style=>'padding-left: 20px;'}, "$^X");
}
Comment on MoDetails v0.2
Download Code
Re: MoDetails v0.1
by BrowserUk (Pope) on Nov 02, 2002 at 17:08 UTC

    hacker++


    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
Re: MoDetails v0.1
by Aristotle (Chancellor) on Nov 02, 2002 at 21:49 UTC

    Sweet! ++

    I would still like to see the pod2html functionality - CPAN will be more current indeed, and in this case that's actually not desired. You want the POD for the installed module, not the latest version available. (Of course you can go back in history on CPAN but that's a hassle.) You could also make use of that when working on a network not connected to the outside world. For that case, it would be nice if the pod2html output is File::Cached. (Just check whether the cache object timestamp is older than that of the module.)

    Makeshifts last the longest.

Re: MoDetails v0.1
by BrowserUk (Pope) on Nov 03, 2002 at 02:29 UTC

    A couple of possibilites for additions would be some of the perlvars (eg. $< $> $( $) $^O $^V) and possibly menus for stuff like $config, @ENV, @INC etc.


    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-12-20 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls