Subject: | Pod::Usage: pod2usage(0) -- exit status is 2 |
Hello,
[ Recently I posted this message to perl5-porters mailing list, but later
recognized that I should have used rt.cpan.org. ]
$ cat pod2usage.pl
#!/usr/bin/perl
use Pod::Usage;
pod2usage(0);
$ ./pod2usage.pl; echo $?
2
$
However, I expect exit status to be 0, not 2;
because documentation says:
When a single argument is given, it should correspond to exactly one
of the following:
* A string containing the text of a message to print *before*
printing the usage message
* A numeric value corresponding to the desired exit status
* A reference to a hash
Surely I passed a numeric value corresponding to the desired exit
status. Here is the reason for this misbehaviour:
435 sub pod2usage {
436 local($_) = shift || "";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
437 my %opts;
438 ## Collect arguments
439 if (@_ > 0) {
440 ## Too many arguments - assume that this is a hash and
441 ## the user forgot to pass a reference to it.
442 %opts = ($_, @_);
443 }
444 elsif (ref $_) {
445 ## User passed a ref to a hash
446 %opts = %{$_} if (ref($_) eq 'HASH');
447 }
448 elsif (/^[-+]?\d+$/) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
437 my %opts;
449 ## User passed in the exit value to use
450 $opts{"-exitval"} = $_;
451 }
452 else {
453 ## User passed in a message to print before issuing usage.
454 $_ and $opts{"-message"} = $_;
455 }
Use see, 0 is replaced with an empty string which does not match against
/number/ patter later. Looks like a bug for me.
--
Alexey Tourbin
ALT Linux Team