From: Brandon L Black Date: Mon, 2 Apr 2007 21:30:59 +0000 (+0000) Subject: added ARGV accessor which holds a copy of the original @ARGV X-Git-Tag: 0_02~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3899e5dfad165bd892dd6917fad97d58346073b0;p=gitmo%2FMooseX-Getopt.git added ARGV accessor which holds a copy of the original @ARGV added skipping _attributes, unless they have the MooseX::Getopt::Meta::Attribute meta --- diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 86c5904..7716f52 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -10,18 +10,24 @@ use MooseX::Getopt::Meta::Attribute; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; +has ARGV => (is => rw, isa => 'ArrayRef'); + sub new_with_options { my ($class, %params) = @_; my (@options, %name_to_init_arg); foreach my $attr ($class->meta->compute_all_applicable_attributes) { my $name = $attr->name; + my $aliases; if ($attr->isa('MooseX::Getopt::Meta::Attribute')) { $name = $attr->cmd_flag if $attr->has_cmd_flag; $aliases = $attr->cmd_aliases if $attr->has_cmd_aliases; - } + } + else { + next if $name =~ /^_/; + } $name_to_init_arg{$name} = $attr->init_arg; @@ -39,6 +45,7 @@ sub new_with_options { push @options => $opt_string; } + my $saved_argv = [ @ARGV ]; my %options; GetOptions(\%options, @options); @@ -52,7 +59,8 @@ sub new_with_options { %params, map { $name_to_init_arg{$_} => $options{$_} - } keys %options + } keys %options, + ARGV => $saved_argv; ); } @@ -99,7 +107,14 @@ This module attempts to DWIM as much as possible with the command line params by introspecting your class's attributes. It will use the name of your attribute as the command line option, and if there is a type constraint defined, it will configure Getopt::Long to handle the option -accordingly. +accordingly. + +You can use the attribute metaclass L +to get non-default commandline option names and aliases. + +By default, attributes which start with an underscore are not given +commandline argument support, unless the attribute's metaclass is set +to L. =head2 Supported Type Constraints @@ -203,6 +218,12 @@ This method will take a set of default C<%params> and then collect params from the command line (possibly overriding those in C<%params>) and then return a newly constructed object. +=item B + +This accessor contains a reference to a copy of the C<@ARGV> array +which was copied before L mangled it, in case you want +to see your original options. + =item B This returns the role meta object.