| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "Pod::Usage 3" |
| 132 | .TH Pod::Usage 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | Pod::Usage, pod2usage() \- print a usage message from embedded pod documentation |
| 135 | .SH "SYNOPSIS" |
| 136 | .IX Header "SYNOPSIS" |
| 137 | .Vb 1 |
| 138 | \& use Pod::Usage |
| 139 | .Ve |
| 140 | .PP |
| 141 | .Vb 4 |
| 142 | \& my $message_text = "This text precedes the usage message."; |
| 143 | \& my $exit_status = 2; ## The exit status to use |
| 144 | \& my $verbose_level = 0; ## The verbose level to use |
| 145 | \& my $filehandle = \e*STDERR; ## The filehandle to write to |
| 146 | .Ve |
| 147 | .PP |
| 148 | .Vb 1 |
| 149 | \& pod2usage($message_text); |
| 150 | .Ve |
| 151 | .PP |
| 152 | .Vb 1 |
| 153 | \& pod2usage($exit_status); |
| 154 | .Ve |
| 155 | .PP |
| 156 | .Vb 4 |
| 157 | \& pod2usage( { -message => $message_text , |
| 158 | \& -exitval => $exit_status , |
| 159 | \& -verbose => $verbose_level, |
| 160 | \& -output => $filehandle } ); |
| 161 | .Ve |
| 162 | .PP |
| 163 | .Vb 4 |
| 164 | \& pod2usage( -msg => $message_text , |
| 165 | \& -exitval => $exit_status , |
| 166 | \& -verbose => $verbose_level, |
| 167 | \& -output => $filehandle ); |
| 168 | .Ve |
| 169 | .PP |
| 170 | .Vb 2 |
| 171 | \& pod2usage( -verbose => 2, |
| 172 | \& -noperldoc => 1 ) |
| 173 | .Ve |
| 174 | .SH "ARGUMENTS" |
| 175 | .IX Header "ARGUMENTS" |
| 176 | \&\fBpod2usage\fR should be given either a single argument, or a list of |
| 177 | arguments corresponding to an associative array (a \*(L"hash\*(R"). When a single |
| 178 | argument is given, it should correspond to exactly one of the following: |
| 179 | .IP "\(bu" 4 |
| 180 | A string containing the text of a message to print \fIbefore\fR printing |
| 181 | the usage message |
| 182 | .IP "\(bu" 4 |
| 183 | A numeric value corresponding to the desired exit status |
| 184 | .IP "\(bu" 4 |
| 185 | A reference to a hash |
| 186 | .PP |
| 187 | If more than one argument is given then the entire argument list is |
| 188 | assumed to be a hash. If a hash is supplied (either as a reference or |
| 189 | as a list) it should contain one or more elements with the following |
| 190 | keys: |
| 191 | .ie n .IP """\-message""" 4 |
| 192 | .el .IP "\f(CW\-message\fR" 4 |
| 193 | .IX Item "-message" |
| 194 | .PD 0 |
| 195 | .ie n .IP """\-msg""" 4 |
| 196 | .el .IP "\f(CW\-msg\fR" 4 |
| 197 | .IX Item "-msg" |
| 198 | .PD |
| 199 | The text of a message to print immediately prior to printing the |
| 200 | program's usage message. |
| 201 | .ie n .IP """\-exitval""" 4 |
| 202 | .el .IP "\f(CW\-exitval\fR" 4 |
| 203 | .IX Item "-exitval" |
| 204 | The desired exit status to pass to the \fB\f(BIexit()\fB\fR function. |
| 205 | This should be an integer, or else the string \*(L"\s-1NOEXIT\s0\*(R" to |
| 206 | indicate that control should simply be returned without |
| 207 | terminating the invoking process. |
| 208 | .ie n .IP """\-verbose""" 4 |
| 209 | .el .IP "\f(CW\-verbose\fR" 4 |
| 210 | .IX Item "-verbose" |
| 211 | The desired level of \*(L"verboseness\*(R" to use when printing the usage |
| 212 | message. If the corresponding value is 0, then only the \*(L"\s-1SYNOPSIS\s0\*(R" |
| 213 | section of the pod documentation is printed. If the corresponding value |
| 214 | is 1, then the \*(L"\s-1SYNOPSIS\s0\*(R" section, along with any section entitled |
| 215 | \&\*(L"\s-1OPTIONS\s0\*(R", \*(L"\s-1ARGUMENTS\s0\*(R", or \*(L"\s-1OPTIONS\s0 \s-1AND\s0 \s-1ARGUMENTS\s0\*(R" is printed. If the |
| 216 | corresponding value is 2 or more then the entire manpage is printed. |
| 217 | .Sp |
| 218 | The special verbosity level 99 requires to also specify the \-section |
| 219 | parameter; then these sections are extracted (see Pod::Select) |
| 220 | and printed. |
| 221 | .ie n .IP """\-section""" 4 |
| 222 | .el .IP "\f(CW\-section\fR" 4 |
| 223 | .IX Item "-section" |
| 224 | A string representing a selection list for sections to be printed |
| 225 | when \-verbose is set to 99, e.g. \f(CW"NAME|SYNOPSIS|DESCRIPTION|VERSION"\fR. |
| 226 | .ie n .IP """\-output""" 4 |
| 227 | .el .IP "\f(CW\-output\fR" 4 |
| 228 | .IX Item "-output" |
| 229 | A reference to a filehandle, or the pathname of a file to which the |
| 230 | usage message should be written. The default is \f(CW\*(C`\e*STDERR\*(C'\fR unless the |
| 231 | exit value is less than 2 (in which case the default is \f(CW\*(C`\e*STDOUT\*(C'\fR). |
| 232 | .ie n .IP """\-input""" 4 |
| 233 | .el .IP "\f(CW\-input\fR" 4 |
| 234 | .IX Item "-input" |
| 235 | A reference to a filehandle, or the pathname of a file from which the |
| 236 | invoking script's pod documentation should be read. It defaults to the |
| 237 | file indicated by \f(CW$0\fR (\f(CW$PROGRAM_NAME\fR for users of \fIEnglish.pm\fR). |
| 238 | .ie n .IP """\-pathlist""" 4 |
| 239 | .el .IP "\f(CW\-pathlist\fR" 4 |
| 240 | .IX Item "-pathlist" |
| 241 | A list of directory paths. If the input file does not exist, then it |
| 242 | will be searched for in the given directory list (in the order the |
| 243 | directories appear in the list). It defaults to the list of directories |
| 244 | implied by \f(CW$ENV{PATH}\fR. The list may be specified either by a reference |
| 245 | to an array, or by a string of directory paths which use the same path |
| 246 | separator as \f(CW$ENV{PATH}\fR on your system (e.g., \f(CW\*(C`:\*(C'\fR for Unix, \f(CW\*(C`;\*(C'\fR for |
| 247 | MSWin32 and \s-1DOS\s0). |
| 248 | .ie n .IP """\-noperldoc""" 4 |
| 249 | .el .IP "\f(CW\-noperldoc\fR" 4 |
| 250 | .IX Item "-noperldoc" |
| 251 | By default, Pod::Usage will call perldoc when \-verbose >= 2 is |
| 252 | specified. This does not work well e.g. if the script was packed |
| 253 | with \s-1PAR\s0. The \-noperldoc option suppresses the external call to |
| 254 | perldoc and uses the simple text formatter (Pod::Text) to |
| 255 | output the \s-1POD\s0. |
| 256 | .SH "DESCRIPTION" |
| 257 | .IX Header "DESCRIPTION" |
| 258 | \&\fBpod2usage\fR will print a usage message for the invoking script (using |
| 259 | its embedded pod documentation) and then exit the script with the |
| 260 | desired exit status. The usage message printed may have any one of three |
| 261 | levels of \*(L"verboseness\*(R": If the verbose level is 0, then only a synopsis |
| 262 | is printed. If the verbose level is 1, then the synopsis is printed |
| 263 | along with a description (if present) of the command line options and |
| 264 | arguments. If the verbose level is 2, then the entire manual page is |
| 265 | printed. |
| 266 | .PP |
| 267 | Unless they are explicitly specified, the default values for the exit |
| 268 | status, verbose level, and output stream to use are determined as |
| 269 | follows: |
| 270 | .IP "\(bu" 4 |
| 271 | If neither the exit status nor the verbose level is specified, then the |
| 272 | default is to use an exit status of 2 with a verbose level of 0. |
| 273 | .IP "\(bu" 4 |
| 274 | If an exit status \fIis\fR specified but the verbose level is \fInot\fR, then the |
| 275 | verbose level will default to 1 if the exit status is less than 2 and |
| 276 | will default to 0 otherwise. |
| 277 | .IP "\(bu" 4 |
| 278 | If an exit status is \fInot\fR specified but verbose level \fIis\fR given, then |
| 279 | the exit status will default to 2 if the verbose level is 0 and will |
| 280 | default to 1 otherwise. |
| 281 | .IP "\(bu" 4 |
| 282 | If the exit status used is less than 2, then output is printed on |
| 283 | \&\f(CW\*(C`STDOUT\*(C'\fR. Otherwise output is printed on \f(CW\*(C`STDERR\*(C'\fR. |
| 284 | .PP |
| 285 | Although the above may seem a bit confusing at first, it generally does |
| 286 | \&\*(L"the right thing\*(R" in most situations. This determination of the default |
| 287 | values to use is based upon the following typical Unix conventions: |
| 288 | .IP "\(bu" 4 |
| 289 | An exit status of 0 implies \*(L"success\*(R". For example, \fB\f(BIdiff\fB\|(1)\fR exits |
| 290 | with a status of 0 if the two files have the same contents. |
| 291 | .IP "\(bu" 4 |
| 292 | An exit status of 1 implies possibly abnormal, but non\-defective, program |
| 293 | termination. For example, \fB\f(BIgrep\fB\|(1)\fR exits with a status of 1 if |
| 294 | it did \fInot\fR find a matching line for the given regular expression. |
| 295 | .IP "\(bu" 4 |
| 296 | An exit status of 2 or more implies a fatal error. For example, \fB\f(BIls\fB\|(1)\fR |
| 297 | exits with a status of 2 if you specify an illegal (unknown) option on |
| 298 | the command line. |
| 299 | .IP "\(bu" 4 |
| 300 | Usage messages issued as a result of bad command-line syntax should go |
| 301 | to \f(CW\*(C`STDERR\*(C'\fR. However, usage messages issued due to an explicit request |
| 302 | to print usage (like specifying \fB\-help\fR on the command line) should go |
| 303 | to \f(CW\*(C`STDOUT\*(C'\fR, just in case the user wants to pipe the output to a pager |
| 304 | (such as \fB\f(BImore\fB\|(1)\fR). |
| 305 | .IP "\(bu" 4 |
| 306 | If program usage has been explicitly requested by the user, it is often |
| 307 | desireable to exit with a status of 1 (as opposed to 0) after issuing |
| 308 | the user-requested usage message. It is also desireable to give a |
| 309 | more verbose description of program usage in this case. |
| 310 | .PP |
| 311 | \&\fBpod2usage\fR doesn't force the above conventions upon you, but it will |
| 312 | use them by default if you don't expressly tell it to do otherwise. The |
| 313 | ability of \fB\f(BIpod2usage()\fB\fR to accept a single number or a string makes it |
| 314 | convenient to use as an innocent looking error message handling function: |
| 315 | .PP |
| 316 | .Vb 2 |
| 317 | \& use Pod::Usage; |
| 318 | \& use Getopt::Long; |
| 319 | .Ve |
| 320 | .PP |
| 321 | .Vb 4 |
| 322 | \& ## Parse options |
| 323 | \& GetOptions("help", "man", "flag1") || pod2usage(2); |
| 324 | \& pod2usage(1) if ($opt_help); |
| 325 | \& pod2usage(-verbose => 2) if ($opt_man); |
| 326 | .Ve |
| 327 | .PP |
| 328 | .Vb 2 |
| 329 | \& ## Check for too many filenames |
| 330 | \& pod2usage("$0: Too many files given.\en") if (@ARGV > 1); |
| 331 | .Ve |
| 332 | .PP |
| 333 | Some user's however may feel that the above \*(L"economy of expression\*(R" is |
| 334 | not particularly readable nor consistent and may instead choose to do |
| 335 | something more like the following: |
| 336 | .PP |
| 337 | .Vb 2 |
| 338 | \& use Pod::Usage; |
| 339 | \& use Getopt::Long; |
| 340 | .Ve |
| 341 | .PP |
| 342 | .Vb 4 |
| 343 | \& ## Parse options |
| 344 | \& GetOptions("help", "man", "flag1") || pod2usage(-verbose => 0); |
| 345 | \& pod2usage(-verbose => 1) if ($opt_help); |
| 346 | \& pod2usage(-verbose => 2) if ($opt_man); |
| 347 | .Ve |
| 348 | .PP |
| 349 | .Vb 3 |
| 350 | \& ## Check for too many filenames |
| 351 | \& pod2usage(-verbose => 2, -message => "$0: Too many files given.\en") |
| 352 | \& if (@ARGV > 1); |
| 353 | .Ve |
| 354 | .PP |
| 355 | As with all things in Perl, \fIthere's more than one way to do it\fR, and |
| 356 | \&\fB\f(BIpod2usage()\fB\fR adheres to this philosophy. If you are interested in |
| 357 | seeing a number of different ways to invoke \fBpod2usage\fR (although by no |
| 358 | means exhaustive), please refer to \*(L"\s-1EXAMPLES\s0\*(R". |
| 359 | .SH "EXAMPLES" |
| 360 | .IX Header "EXAMPLES" |
| 361 | Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print just the |
| 362 | \&\*(L"\s-1SYNOPSIS\s0\*(R" section to \f(CW\*(C`STDERR\*(C'\fR and will exit with a status of 2: |
| 363 | .PP |
| 364 | .Vb 1 |
| 365 | \& pod2usage(); |
| 366 | .Ve |
| 367 | .PP |
| 368 | .Vb 1 |
| 369 | \& pod2usage(2); |
| 370 | .Ve |
| 371 | .PP |
| 372 | .Vb 1 |
| 373 | \& pod2usage(-verbose => 0); |
| 374 | .Ve |
| 375 | .PP |
| 376 | .Vb 1 |
| 377 | \& pod2usage(-exitval => 2); |
| 378 | .Ve |
| 379 | .PP |
| 380 | .Vb 1 |
| 381 | \& pod2usage({-exitval => 2, -output => \e*STDERR}); |
| 382 | .Ve |
| 383 | .PP |
| 384 | .Vb 1 |
| 385 | \& pod2usage({-verbose => 0, -output => \e*STDERR}); |
| 386 | .Ve |
| 387 | .PP |
| 388 | .Vb 1 |
| 389 | \& pod2usage(-exitval => 2, -verbose => 0); |
| 390 | .Ve |
| 391 | .PP |
| 392 | .Vb 1 |
| 393 | \& pod2usage(-exitval => 2, -verbose => 0, -output => \e*STDERR); |
| 394 | .Ve |
| 395 | .PP |
| 396 | Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print a message |
| 397 | of \*(L"Syntax error.\*(R" (followed by a newline) to \f(CW\*(C`STDERR\*(C'\fR, immediately |
| 398 | followed by just the \*(L"\s-1SYNOPSIS\s0\*(R" section (also printed to \f(CW\*(C`STDERR\*(C'\fR) and |
| 399 | will exit with a status of 2: |
| 400 | .PP |
| 401 | .Vb 1 |
| 402 | \& pod2usage("Syntax error."); |
| 403 | .Ve |
| 404 | .PP |
| 405 | .Vb 1 |
| 406 | \& pod2usage(-message => "Syntax error.", -verbose => 0); |
| 407 | .Ve |
| 408 | .PP |
| 409 | .Vb 1 |
| 410 | \& pod2usage(-msg => "Syntax error.", -exitval => 2); |
| 411 | .Ve |
| 412 | .PP |
| 413 | .Vb 1 |
| 414 | \& pod2usage({-msg => "Syntax error.", -exitval => 2, -output => \e*STDERR}); |
| 415 | .Ve |
| 416 | .PP |
| 417 | .Vb 1 |
| 418 | \& pod2usage({-msg => "Syntax error.", -verbose => 0, -output => \e*STDERR}); |
| 419 | .Ve |
| 420 | .PP |
| 421 | .Vb 1 |
| 422 | \& pod2usage(-msg => "Syntax error.", -exitval => 2, -verbose => 0); |
| 423 | .Ve |
| 424 | .PP |
| 425 | .Vb 4 |
| 426 | \& pod2usage(-message => "Syntax error.", |
| 427 | \& -exitval => 2, |
| 428 | \& -verbose => 0, |
| 429 | \& -output => \e*STDERR); |
| 430 | .Ve |
| 431 | .PP |
| 432 | Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print the |
| 433 | \&\*(L"\s-1SYNOPSIS\s0\*(R" section and any \*(L"\s-1OPTIONS\s0\*(R" and/or \*(L"\s-1ARGUMENTS\s0\*(R" sections to |
| 434 | \&\f(CW\*(C`STDOUT\*(C'\fR and will exit with a status of 1: |
| 435 | .PP |
| 436 | .Vb 1 |
| 437 | \& pod2usage(1); |
| 438 | .Ve |
| 439 | .PP |
| 440 | .Vb 1 |
| 441 | \& pod2usage(-verbose => 1); |
| 442 | .Ve |
| 443 | .PP |
| 444 | .Vb 1 |
| 445 | \& pod2usage(-exitval => 1); |
| 446 | .Ve |
| 447 | .PP |
| 448 | .Vb 1 |
| 449 | \& pod2usage({-exitval => 1, -output => \e*STDOUT}); |
| 450 | .Ve |
| 451 | .PP |
| 452 | .Vb 1 |
| 453 | \& pod2usage({-verbose => 1, -output => \e*STDOUT}); |
| 454 | .Ve |
| 455 | .PP |
| 456 | .Vb 1 |
| 457 | \& pod2usage(-exitval => 1, -verbose => 1); |
| 458 | .Ve |
| 459 | .PP |
| 460 | .Vb 1 |
| 461 | \& pod2usage(-exitval => 1, -verbose => 1, -output => \e*STDOUT}); |
| 462 | .Ve |
| 463 | .PP |
| 464 | Each of the following invocations of \f(CW\*(C`pod2usage()\*(C'\fR will print the |
| 465 | entire manual page to \f(CW\*(C`STDOUT\*(C'\fR and will exit with a status of 1: |
| 466 | .PP |
| 467 | .Vb 1 |
| 468 | \& pod2usage(-verbose => 2); |
| 469 | .Ve |
| 470 | .PP |
| 471 | .Vb 1 |
| 472 | \& pod2usage({-verbose => 2, -output => \e*STDOUT}); |
| 473 | .Ve |
| 474 | .PP |
| 475 | .Vb 1 |
| 476 | \& pod2usage(-exitval => 1, -verbose => 2); |
| 477 | .Ve |
| 478 | .PP |
| 479 | .Vb 1 |
| 480 | \& pod2usage({-exitval => 1, -verbose => 2, -output => \e*STDOUT}); |
| 481 | .Ve |
| 482 | .Sh "Recommended Use" |
| 483 | .IX Subsection "Recommended Use" |
| 484 | Most scripts should print some type of usage message to \f(CW\*(C`STDERR\*(C'\fR when a |
| 485 | command line syntax error is detected. They should also provide an |
| 486 | option (usually \f(CW\*(C`\-H\*(C'\fR or \f(CW\*(C`\-help\*(C'\fR) to print a (possibly more verbose) |
| 487 | usage message to \f(CW\*(C`STDOUT\*(C'\fR. Some scripts may even wish to go so far as to |
| 488 | provide a means of printing their complete documentation to \f(CW\*(C`STDOUT\*(C'\fR |
| 489 | (perhaps by allowing a \f(CW\*(C`\-man\*(C'\fR option). The following complete example |
| 490 | uses \fBPod::Usage\fR in combination with \fBGetopt::Long\fR to do all of these |
| 491 | things: |
| 492 | .PP |
| 493 | .Vb 2 |
| 494 | \& use Getopt::Long; |
| 495 | \& use Pod::Usage; |
| 496 | .Ve |
| 497 | .PP |
| 498 | .Vb 7 |
| 499 | \& my $man = 0; |
| 500 | \& my $help = 0; |
| 501 | \& ## Parse options and print usage if there is a syntax error, |
| 502 | \& ## or if usage was explicitly requested. |
| 503 | \& GetOptions('help|?' => \e$help, man => \e$man) or pod2usage(2); |
| 504 | \& pod2usage(1) if $help; |
| 505 | \& pod2usage(-verbose => 2) if $man; |
| 506 | .Ve |
| 507 | .PP |
| 508 | .Vb 4 |
| 509 | \& ## If no arguments were given, then allow STDIN to be used only |
| 510 | \& ## if it's not connected to a terminal (otherwise print usage) |
| 511 | \& pod2usage("$0: No files given.") if ((@ARGV == 0) && (-t STDIN)); |
| 512 | \& __END__ |
| 513 | .Ve |
| 514 | .PP |
| 515 | .Vb 1 |
| 516 | \& =head1 NAME |
| 517 | .Ve |
| 518 | .PP |
| 519 | .Vb 1 |
| 520 | \& sample - Using GetOpt::Long and Pod::Usage |
| 521 | .Ve |
| 522 | .PP |
| 523 | .Vb 1 |
| 524 | \& =head1 SYNOPSIS |
| 525 | .Ve |
| 526 | .PP |
| 527 | .Vb 1 |
| 528 | \& sample [options] [file ...] |
| 529 | .Ve |
| 530 | .PP |
| 531 | .Vb 3 |
| 532 | \& Options: |
| 533 | \& -help brief help message |
| 534 | \& -man full documentation |
| 535 | .Ve |
| 536 | .PP |
| 537 | .Vb 1 |
| 538 | \& =head1 OPTIONS |
| 539 | .Ve |
| 540 | .PP |
| 541 | .Vb 1 |
| 542 | \& =over 8 |
| 543 | .Ve |
| 544 | .PP |
| 545 | .Vb 1 |
| 546 | \& =item B<-help> |
| 547 | .Ve |
| 548 | .PP |
| 549 | .Vb 1 |
| 550 | \& Print a brief help message and exits. |
| 551 | .Ve |
| 552 | .PP |
| 553 | .Vb 1 |
| 554 | \& =item B<-man> |
| 555 | .Ve |
| 556 | .PP |
| 557 | .Vb 1 |
| 558 | \& Prints the manual page and exits. |
| 559 | .Ve |
| 560 | .PP |
| 561 | .Vb 1 |
| 562 | \& =back |
| 563 | .Ve |
| 564 | .PP |
| 565 | .Vb 1 |
| 566 | \& =head1 DESCRIPTION |
| 567 | .Ve |
| 568 | .PP |
| 569 | .Vb 2 |
| 570 | \& B<This program> will read the given input file(s) and do something |
| 571 | \& useful with the contents thereof. |
| 572 | .Ve |
| 573 | .PP |
| 574 | .Vb 1 |
| 575 | \& =cut |
| 576 | .Ve |
| 577 | .SH "CAVEATS" |
| 578 | .IX Header "CAVEATS" |
| 579 | By default, \fB\f(BIpod2usage()\fB\fR will use \f(CW$0\fR as the path to the pod input |
| 580 | file. Unfortunately, not all systems on which Perl runs will set \f(CW$0\fR |
| 581 | properly (although if \f(CW$0\fR isn't found, \fB\f(BIpod2usage()\fB\fR will search |
| 582 | \&\f(CW$ENV{PATH}\fR or else the list specified by the \f(CW\*(C`\-pathlist\*(C'\fR option). |
| 583 | If this is the case for your system, you may need to explicitly specify |
| 584 | the path to the pod docs for the invoking script using something |
| 585 | similar to the following: |
| 586 | .PP |
| 587 | .Vb 1 |
| 588 | \& pod2usage(-exitval => 2, -input => "/path/to/your/pod/docs"); |
| 589 | .Ve |
| 590 | .PP |
| 591 | In the pathological case that a script is called via a relative path |
| 592 | \&\fIand\fR the script itself changes the current working directory |
| 593 | (see \*(L"chdir\*(R" in perlfunc) \fIbefore\fR calling pod2usage, Pod::Usage will |
| 594 | fail even on robust platforms. Don't do that. |
| 595 | .SH "AUTHOR" |
| 596 | .IX Header "AUTHOR" |
| 597 | Please report bugs using <http://rt.cpan.org>. |
| 598 | .PP |
| 599 | Brad Appleton <bradapp@enteract.com> |
| 600 | .PP |
| 601 | Based on code for \fB\f(BIPod::Text::pod2text()\fB\fR written by |
| 602 | Tom Christiansen <tchrist@mox.perl.com> |
| 603 | .SH "ACKNOWLEDGEMENTS" |
| 604 | .IX Header "ACKNOWLEDGEMENTS" |
| 605 | Steven McDougall <swmcd@world.std.com> for his help and patience |
| 606 | with re-writing this manpage. |