X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FGetopt.pm;fp=lib%2FMooseX%2FGetopt.pm;h=27c17c8496eefd2e71629aa0d9969a12d20619af;hb=d09046450c54b37640fed28a06a17b7d040ba81a;hp=c8504df47a78e1d84dcbeb96ceb161d3488c2e92;hpb=4848d3bb544e93773978e6907d8f446918ab664f;p=gitmo%2FMooseX-Getopt.git diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index c8504df..27c17c8 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -40,7 +40,7 @@ sub get_options_from_argv { 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] } : @_ ); + my %params = ( $class->_get_options_from_configfile, @_ == 1 ? %{ $_[0] } : @_ ); my $getopt = defined $params{getopt} ? $params{getopt} @@ -60,6 +60,32 @@ sub get_options_from_argv { }; +sub _get_options_from_configfile { + my $class = shift; + + my %params = (); + + if ($class->meta->does_role('MooseX::ConfigFromFile')) { + local @ARGV = @ARGV; + + my $configfile; + my $opt_parser = Getopt::Long::Parser->new( config => [ 'pass_through' ] ); + $opt_parser->getoptions( "configfile=s" => \$configfile ); + + if (not defined $configfile) { + my $cfmeta = $class->meta->find_attribute_by_name('configfile'); + $configfile = $cfmeta->default if $cfmeta->has_default; + }; + + if (defined $configfile) { + %params = %{ $class->get_config_from_file($configfile) }; + }; + }; + + return %params; +}; + + sub _compute_getopt_attrs { my $class = shift;