From: Piotr Roszatycki Date: Thu, 20 Nov 2008 15:52:06 +0000 (+0000) Subject: * MooseX::Getopt::Session: New attribute "status". X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a29a50d34d57607b72e29b62904f824a7f9dc51;p=gitmo%2FMooseX-Getopt.git * MooseX::Getopt::Session: New attribute "status". * MooseX::Getopt::Session: Constructor does not call build_options. * MooseX::Getopt: new_with_options calls $getopt->build_options. --- diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 8d0acd3..8eda924 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -52,6 +52,9 @@ sub get_options_from_argv { 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 diff --git a/lib/MooseX/Getopt/Parser/Descriptive.pm b/lib/MooseX/Getopt/Parser/Descriptive.pm index 1b69fb5..57ecaea 100644 --- a/lib/MooseX/Getopt/Parser/Descriptive.pm +++ b/lib/MooseX/Getopt/Parser/Descriptive.pm @@ -95,6 +95,7 @@ sub build_options { # Include old options and usage object $new_options = { usage => $usage, %$options, %$new_options }; + $getopt->status( !! $warnings ); $getopt->options( $new_options ); die $warnings if $warnings; diff --git a/lib/MooseX/Getopt/Parser/Long.pm b/lib/MooseX/Getopt/Parser/Long.pm index e697e1f..3a1eb2d 100644 --- a/lib/MooseX/Getopt/Parser/Long.pm +++ b/lib/MooseX/Getopt/Parser/Long.pm @@ -66,6 +66,7 @@ sub build_options { # 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; diff --git a/lib/MooseX/Getopt/Session.pm b/lib/MooseX/Getopt/Session.pm index bdb0417..dae6c01 100644 --- a/lib/MooseX/Getopt/Session.pm +++ b/lib/MooseX/Getopt/Session.pm @@ -44,12 +44,12 @@ has options => ( 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 { @@ -141,8 +141,8 @@ L. =item B -This method creates new CLI session for L and calls -C method. +This method creates new CLI session object for L. The +session should be started with C method. =item B @@ -181,9 +181,10 @@ This accessor contains an arrayref of options parsed from command line by L. If the options list are not empty before parsing the command line, the old list will be included to new list. -=item B +=item B -This is a default L constructor. +This accessor contains a true value if L was +called via C method and it succeeded. =item B