PageRenderTime 108ms CodeModel.GetById 96ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/tests/perl_swiss_army_knife.pl

https://code.google.com/p/camelbox/
Perl | 86 lines | 48 code | 17 blank | 21 comment | 5 complexity | 9a1e65763c5e4ec3a60ff9a80513abbd MD5 | raw file
 1#!/usr/bin/perl
 2# $Id: perl_swiss_army_knife.pl 367 2008-07-20 17:48:23Z elspicyjack $
 3
 4# A script to print out a bunch of info about the current Perl environment
 5# by Brian Manning (elspicyjack {at} gmail ⋅ com)
 6
 7# The original script most likely appears in the Perl Cookbook from O'Reilly.
 8
 9# if the script detects that it's running as under a CGI environment (the
10# REQUEST_METHOD environment variable is set), it will wrap the plaintext
11# output in the correct HTML tags so the browser will render it in the same
12# manner as if the script were running in a shell.
13
14my @found_modules; # a list of modules that were found in @INC paths
15my $i=1;	# a counter
16
17# are we CGI?
18if ( exists $ENV{'REQUEST_METHOD'} ) {
19    print "Content-type: text/html","\n\n";
20    print "<html><body><pre>\n";
21} # if ( exists $ENV{'REQUEST_METHOD'} )
22
23print "##################################################################\n";
24print "# Perl Executable Name (\$^X)                                     #\n";
25print "##################################################################\n";
26print qq(Executable name: $^X\n\n);
27
28print "##################################################################\n";
29print "# Perl Runtime Environment (\%ENV)                                #\n";
30print "##################################################################\n";
31
32# print the runtime environment
33foreach my $key ( sort(keys(%ENV)) ) {
34    print(sprintf("%2d", $i) . qq( $key = ) . $ENV{$key} . qq(\n));
35	$i++;	
36} # while (($key, $val) = each %ENV)
37print "\n";
38
39$i=1;	# reset counter
40
41# print the @INC array
42print "##################################################################\n";
43print "# Perl Module Include Paths (\@INC)                               #\n";
44print "##################################################################\n";
45printf qq(%2d %s\n), $i++, $_ for sort(@INC);
46print "\n";
47
48$i=0;	# reset counter
49
50# print installed modules
51print "##################################################################\n";
52print "# Installed Perl Modules (\&modules in \@INC)                      #\n";
53print "##################################################################\n";
54# NOTES
55#   1. Prune man, pod, etc. directories
56#   2. Skip files with a suffix other than .pm
57#   3. Format the filename so that it looks more like a module
58#   4. Print it
59use File::Find;
60foreach $start ( @INC ) { find(\&modules, $start); }
61
62# reset counter
63my $i=1;
64foreach $module ( sort(@found_modules) ) {
65    printf qq(%4d %s\n), $i++, $module;
66} # foreach $module ( sort(@found_modules) )
67
68# print the butt-end of the HTML if this is CGI
69if ( exists $ENV{'REQUEST_METHOD'} ) {
70    print "</body></html>\n";
71} # if ( exists $ENV{'REQUEST_METHOD'} ) {
72
73exit 0;
74
75### modules ###
76sub modules {
77	if (-d && /^[a-z]/) { $File::Find::prune = 1; return; }
78		return unless /\.pm$/;
79       	my $filename = "$File::Find::dir/$_";
80      	$filename =~ s!^$start/!!;
81       	$filename =~ s!\.pm$!!;
82        $filename =~ s!/!::!g;
83        push(@found_modules, $filename);
84		$i++;
85} # sub modules
86