From: Brandon L Black Date: Tue, 18 Dec 2007 22:45:47 +0000 (+0000) Subject: add MX::ConfigFromFile support X-Git-Tag: 0_08~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ee69c4ba080aacb8eaa084320e9f96bb1ab40c9f;p=gitmo%2FMooseX-Getopt.git add MX::ConfigFromFile support --- diff --git a/ChangeLog b/ChangeLog index d3403b6..97f5cd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ Revision history for Perl extension MooseX-Getopt + * MooseX::Getopt + - Added support for configfile loading via + MooseX::ConfigFromFile-based roles with + the -configfile commandline option. + 0.07 Tues. Dec. 4, 2007 * MooseX::Getopt::Meta::Attribute::NoGetopt - fixed miscapitalization of NoGetopt in the docs diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 2602a4a..0c16a20 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -23,11 +23,21 @@ sub new_with_options { ] ); + my $params = $processed{params}; + + if($class->meta->does_role('MooseX::ConfigFromFile') + && defined $params->{configfile}) { + %$params = ( + %{$class->get_config_from_file($params->{configfile})}, + %$params, + ); + } + $class->new( ARGV => $processed{argv_copy}, extra_argv => $processed{argv}, @params, # explicit params to ->new - %{ $processed{params} }, # params from CLI + %$params, # params from CLI ); } @@ -179,6 +189,11 @@ to have the leading underscore in thier name, you can do this: This will mean that Getopt will not handle a --foo param, but your code can still call the C method. +If your class also uses a configfile-loading role based on +L, such as L, +L's C will load the configfile +specified by the C<--configfile> option for you. + =head2 Supported Type Constraints =over 4