options => $options,
);
+ # Call Getopt parser only once.
+ $getopt->build_options if not $getopt->has_status;
+
my $new_options = {
%{ $options }, # explicit options to ->new
%{ $getopt->options }, # options from CLI
# Include old options and usage object
$new_options = { usage => $usage, %$options, %$new_options };
+ $getopt->status( !! $warnings );
$getopt->options( $new_options );
die $warnings if $warnings;
# Filter not defined values in new_options hashref
$new_options = { map { $_ => $new_options->{$_} } grep { defined $new_options->{$_} } keys %$new_options };
+ $getopt->status( !! $warnings );
$getopt->options( $new_options );
die $warnings if $warnings;
default => sub { {} },
);
-
-sub BUILD {
- my ($self, $args) = @_;
-
- $self->build_options;
-};
+# Status returned by Getopt parser
+has status => (
+ is => 'rw',
+ isa => 'Bool',
+ predicate => 'has_status',
+);
sub build_options {
=item B<new (%params)>
-This method creates new CLI session for L<MooseX::Getopt> and calls
-C<build_options> method.
+This method creates new CLI session object for L<MooseX::Getopt>. The
+session should be started with C<build_options> method.
=item B<build_options>
L<MooseX::Getopt::Parser>. If the options list are not empty before parsing
the command line, the old list will be included to new list.
-=item B<BUILD>
+=item B<status>
-This is a default L<Moose> constructor.
+This accessor contains a true value if L<MooseX::Getopt::Parser> was
+called via C<build_options> method and it succeeded.
=item B<meta>