Subject: | MooseX-getopt-basic doesn't raise an error when unknow options or ambiguous options specified on command line |
When an unknown option is specified on the command line, no error is
given nor is the option added to extra_argv.
If ambiguous options are entered, no errors are issued and in both
cases the program continues.
Examples
H:\Metrics> perl test.pl -debug -database PROD -unknown
Debug: 1; DB: PROD
Unused params:
H:\Metrics> perl test.pl -d
Debug: 0; DB: DEV
Unused params:
Solution?
Locally, I changed the function _getopt_spec_warnings from
sub _getopt_spec_warnings { }
to
sub _getopt_spec_warnings {
my ($self, @warnings) = @_;
die @warnings, "\n";
}
And to the correct results
H:\Metrics> perl test.pl -debug -database PROD -unknown
Unknown option: unknown
H:\Metrics> perl test.pl -d
Option d is ambiguous (database, debug)
Subject: | TestGetOpts.pm |
package TestGetOpts;
use Moose;
with 'MooseX::Getopt::Basic';
use strict;
use warnings;
no warnings qw(uninitialized); ## no critic qw(ProhibitNoWarnings)
use Carp;
has 'debug' => (
is => 'rw',
isa => 'Bool',
default => 0,
documentation => 'hidden',
);
has 'database' => (
is => 'rw',
isa => 'Str',
default => 'DEV',
documentation => 'The database',
);
1;
Subject: | test.pl |
#!
use strict;
use warnings;
use Carp;
use TestGetOpts;
my $OPTS = TestGetOpts->new_with_options();
my $debug = $OPTS->debug;
my $database = $OPTS->database;
print "Debug: $debug; DB: $database\n";
print "Unused params: " . join(', ', @{$OPTS->extra_argv}) . "\n";