Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

pod2usage does not work for verbose level 1.

by isha (Sexton)
on Jan 29, 2008 at 13:44 UTC ( [id://664898]=perlquestion: print w/replies, xml ) Need Help??

isha has asked for the wisdom of the Perl Monks concerning the following question:

I am calling pod2usage with verbose level 1 when -help is provided (Please run below code on LINUX).
&GetOptions( 'h|help' => \$opt_help, 'man' => sub{ pod2usage({-verbose=>2, -exitval=>0}); }, 'q|quiet' => \$opt_quiet, 'c|config=s' => \@opt_config, 'p|project=s' => \$opt_proj ) || pod2usage(1); if($opt_help){ print "help---------------\n"; pod2usage(1); }

But this is not printing the SYNOPSIS secction from the Pod document. I m using embedded pod document.
please help me! <br
Here is the whole program with POD document.
use strict; use Getopt::Long; use Pod::Usage; my $opt_maxError = 0; my $opt_quiet = 0; my $file = ""; my $errors = 0; my @opt_config; my $opt_project; my $opt_help; my @files = (); &GetOptions( 'h|help' => \$opt_help, 'man' => sub{ &pod2usage({-verbose=>2, -exitval=>0}); }, 'q|quiet' => \$opt_quiet, 'c|config=s' => \@opt_config, 'p|project=s' => \$opt_project ) || pod2usage(1); if($opt_help){ print "help---------------\n"; &pod2usage(1); } if(@ARGV){ @files = @ARGV; } elsif(!@opt_config && !$opt_project){ @files = glob("*.cc *.txt"); } if(!defined $opt_project){ pod2usage( -msg => "\n%E, PROJECT DEFINITION FILE DOESN'T EXIST.\n", -exitval=>1); } # take place for all those specified files if(!@files) { pod2usage( -msg => "\n%E, NO TESTPLAN LISTS FILE.\n", -exitval=>1); } exit; ##########END OF SCRIPT########### __END__ =head1 NAME test.pl -- A simple script. =head1 SYNOPSIS test.pl [options] Options: -h or -help Display help. -man About the script. -c <config_name> Configuration name. -p <path> Path to Project Definition File. -m <n> or -maxerror <n> Maximum number of errors. -q or -quiet Do not print errors. =head1 OPTIONS =over 8 =item B<-h|help> Print a brief help message and exits. =item B<-man> Prints the manual page and exits. =item B<-c> <name> Configuration name. i.e: -c tg,mpg or -c tg -c mpg =item B<-p> <path> Path to Project Definition File. =item B<-m|maxerror> <number> Maximum number of errors. =item B<-q|quiet> Setting this switch will not print any error on stderr. =back =head1 DESCRIPTION The script parses the feature file & print errors.

Replies are listed 'Best First'.
Re: pod2usage does not work for verbose level 1.
by kyle (Abbot) on Jan 29, 2008 at 14:51 UTC

    Looking at the Pod::Usage documentation, it says that when you call pod2usage with a single numerical argument, that argument is the exit status, not the verbose level...but it also says that an exit status of 1 would be a verbose level of 1 also.

    Maybe you should show us the POD documentation as it appears in the file that's giving you problems. When I attach my own little POD and try it with your code, it works (prints the synopsis).

    Update: Here's the code I tried:

Re: pod2usage does not work for verbose level 1.
by Khen1950fx (Canon) on Jan 29, 2008 at 22:43 UTC
    "verbose 1" is working. It will print the help message, usage and options. If you want the SYNOPSIS printed, then "verbose 2" is the way to go, but it won't print out the help message:)
    #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Pod::Usage; my $help; GetOptions( "help" => \$help ) or pod2usage( -input => \*DATA ); pod2usage( -message => "help------------------------\n", -exitval => 0, -verbose => 2 ); __DATA__ =head1 NAME yourscript.pl =head1 SYNOPSIS Print help message and manual =head1 OPTIONS =over =item B<--help> Prints a brief help message =item B<--man> Prints man =cut
Re: pod2usage does not work for verbose level 1.
by andreas1234567 (Vicar) on Jan 29, 2008 at 20:28 UTC
    Use explicit arguments to Pod::Usage to remove the ambiguity of what the number represents:
    if ($opt_help) { pod2usage({ -verbose => 1, -exitval => 0 }); }
    --
    Andreas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found