X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FGetopt.pm;h=d0dbb3f70180d36965c710be2403d73a7a1b902b;hb=topic%2Fconfigfile_default_codref_call;hp=6b0c359afcdc635b0030a2d87c55c037dd6b58e5;hpb=47a89a8dec3d21759af9d3e9fbf06149a2870543;p=gitmo%2FMooseX-Getopt.git diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 6b0c359..d0dbb3f 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -11,7 +11,7 @@ use Carp (); use Getopt::Long (); # GLD uses it anyway, doesn't hurt use constant HAVE_GLD => not not eval { require Getopt::Long::Descriptive }; -our $VERSION = '0.18'; +our $VERSION = '0.21'; our $AUTHORITY = 'cpan:STEVAN'; has ARGV => (is => 'rw', isa => 'ArrayRef', metaclass => "NoGetopt"); @@ -31,9 +31,21 @@ sub new_with_options { if(!defined $configfile) { my $cfmeta = $class->meta->find_attribute_by_name('configfile'); $configfile = $cfmeta->default if $cfmeta->has_default; + if (ref $configfile eq 'CODE') { + # not sure theres a lot you can do with the class and may break some assumptions + # warn? + $configfile = &$configfile($class); + } + if (defined $configfile) { + $config_from_file = eval { + $class->get_config_from_file($configfile); + }; + if ($@) { + die $@ unless $@ =~ /Specified configfile '\Q$configfile\E' does not exist/; + } + } } - - if(defined $configfile) { + else { $config_from_file = $class->get_config_from_file($configfile); } } @@ -69,7 +81,7 @@ sub new_with_options { sub _parse_argv { my ( $class, %params ) = @_; - local @ARGV = @{ $params{argv} || \@ARGV }; + local @ARGV = @{ $params{params}{argv} || \@ARGV }; my ( $opt_spec, $name_to_init_arg ) = ( HAVE_GLD ? $class->_gld_spec(%params) : $class->_traditional_spec(%params) ); @@ -285,8 +297,8 @@ to have C ignore your attribute in the commandline options. By default, attributes which start with an underscore are not given commandline argument support, unless the attribute's metaclass is set -to L. If you don't want you accessors -to have the leading underscore in thier name, you can do this: +to L. If you don't want your accessors +to have the leading underscore in their name, you can do this: # for read/write attributes has '_foo' => (accessor => 'foo', ...); @@ -423,6 +435,9 @@ 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. +The special parameter C, if specified should point to an array +reference with an array to use instead of C<@ARGV>. + If L fails (due to invalid arguments), C will throw an exception. @@ -435,7 +450,7 @@ B option for each attribute to document. --help --usage -If you have L a the C param is also passed to +If you have L the C param is also passed to C. =item B