1#!/usr/bin/perl 2 3use HTML::Perlinfo; 4use Getopt::Long; 5use Pod::Usage; 6use strict; 7use warnings; 8 9my $version = "1.02"; 10my %Opts; 11 12if ( !@ARGV ) { 13 pod2usage(0); 14} 15 16GetOptions(\%Opts, qw[ help|? version all i:s c:s g:s m:s e:s ] ) 17 or die pod2usage(0); 18 19pod2usage(1) if $Opts{help}; 20 21 22if ($Opts{version}) { 23 print STDERR "perlinfo version $version\n"; 24 print STDERR "HTML::Perlinfo version $HTML::Perlinfo::VERSION\n"; 25 print STDERR "Copyright (c) 2009 by Mike Accardo\n"; 26 exit; 27} 28 29my %hok = ( 30 i => { o=> 'INFO_ALL', f=>'perlinfo.html'}, 31 c => { o=> 'INFO_CONFIG', f=>'perlconfig.html'}, 32 g => { o=> 'INFO_GENERAL', f=>'perlversion.html'}, 33 e => { o=> 'INFO_VARIABLES',f=>'variables.html'}, 34 m => { o=> 'INFO_MODULES', f=>'perlmodules.html'}, 35 ); 36 37if ($Opts{all}) { 38 $Opts{$_} = $hok{$_}{f} for (keys %hok); 39 delete $Opts{all}; 40} 41 42for my $key ( keys %Opts ) { 43 $Opts{$key} = $hok{$key}{f} if ( !$Opts{$key} ); 44 create_file($Opts{$key}, $hok{$key}{o}); 45} 46 47sub create_file { 48 my ($file_name, $perlinfo_option) = @_; 49 if (-e $file_name && !(overwrite_file($file_name))) { 50 print "exiting ...\n"; 51 } 52 else { 53 open (WR, ">$file_name") or die "Can't open $file_name: $!"; 54 print WR perlinfo($perlinfo_option); 55 close WR; 56 print "Saved file $file_name\n"; 57 } 58 59} 60 61sub overwrite_file { 62 my $file_name = shift; 63 print "Overwrite existing file $file_name? (Y/N)\n"; 64 chomp(my $answer = <>); 65 return ($answer =~ /y/i) ? 1 : 0; 66 67} 68 691; 70=pod 71 72=head1 NAME 73 74perlinfo - a command-line frontend to HTML::Perlinfo 75 76=head1 DESCRIPTION 77 78See L<HTML::Perlinfo> for one. 79 80=head1 SYNOPSIS 81 82 perlinfo -i 83 perlinfo [-help] [-version] [-all] [-i|-c|-g|-m|-e] <FileName> ... 84 85=head1 OPTIONS 86 87All options (except for I<help> and I<version>) use the perlinfo function to produce a complete HTML page in the current working directory. The following table shows the flags corresponding perlinfo option and the name under which the file is saved. 88 89 flag | perlinfo option | file name 90 91 -i | INFO_ALL | perlinfo.html 92 -c | INFO_CONFIG | perlconfig.html 93 -g | INFO_GENERAL | perlversion.html 94 -m | INFO_MODULES | perlmodules.html 95 -e | INFO_VARIABLES | variables.html 96 97You can specify your own file name, including the absolute path name, after the flag. 98 99=over 100 101=item -all 102 103Saves you all the pages at once. 104 105=item -help 106 107help! help! help! 108 109=item -version 110 111perlinfo and HTML::Perlinfo versions 112 113=back 114 115=head1 EXAMPLES 116 117 perlinfo -i 118 119 'Saved file perlinfo.html' 120 121 perlinfo -i /home/paco/www/perl-info.html 122 123 'Saved file /home/paco/www/perl-info.html' 124 125=head1 COPYRIGHT 126 127Copyright (c) 2009 by Mike Accardo 128 129This program is distributed under the same terms as perl itself. 130See http://perl.org/ or http://cpan.org/ for more info on that. 131 132=cut 133