From: Piotr Roszatycki Date: Thu, 13 Nov 2008 16:22:55 +0000 (+0000) Subject: * MooseX::Getopt: New method get_options_from_argv. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4848d3bb544e93773978e6907d8f446918ab664f;p=gitmo%2FMooseX-Getopt.git * MooseX::Getopt: New method get_options_from_argv. --- diff --git a/ChangeLog b/ChangeLog index 3b8ca54..d9976f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ Revision history for Perl extension MooseX-Getopt - Use Moose's throw_error() method. (dexter) * MooseX::Getopt + - New method get_options_from_argv. (dexter) + + * MooseX::Getopt * MooseX::Getopt::Session - MooseX::Getopt can start new Getopt session or get it as parameter (dexter) diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 8bc9399..c8504df 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -30,7 +30,14 @@ has getopt => ( sub new_with_options { my $class = shift; - Moose->throw_error("Single parameters to new_with_options() must be a HASH ref") + return $class->new( $class->get_options_from_argv(@_) ); +}; + + +sub get_options_from_argv { + my $class = shift; + + Moose->throw_error("Single parameters to get_options_from_argv() must be a HASH ref") if ref $_[0] and ref $_ ne 'HASH'; my %params = ( @_ == 1 ? %{ $_[0] } : @_ ); @@ -42,12 +49,14 @@ sub new_with_options { params => \%params, ); - $class->new( - getopt => $getopt, + my %new_params = ( %{ $getopt->params }, # params from session object %params, # explicit params to ->new %{ $getopt->options }, # params from CLI + getopt => $getopt, ); + + return %new_params; }; @@ -299,6 +308,11 @@ C will throw an exception. If you have L a the C param is also passed to C. +=item B + +This method returns the list of parameters collected from command line +without creating the new object. + =item B This accessor contains a reference to a copy of the C<@ARGV> array as it