sub get_config_from_file {
my ($class, $file) = @_;
- my $raw_cfany = Config::Any->load_files({
- files => [ $file ],
- use_ext => 1,
- });
+ my $can_config_any_args = $class->can('config_any_args');
+ my %args = $can_config_any_args ?
+ ( %{$can_config_any_args->($class, $file)}, files => [ $file ], use_ext => 1 ) :
+ ( files => [ $file ], use_ext => 1 )
+ ;
+ my $raw_cfany = Config::Any->load_files(\%args);
die q{Specified configfile '} . $file
. q{' does not exist, is empty, or is not readable}
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib 't/lib';
+use lib '../t/lib';
+
+BEGIN {
+ use Test::More;
+
+ eval "use Config::General ()";
+ if($@) {
+ plan skip_all => "Config::General required for this test";
+ }
+
+ plan tests => 6;
+
+ use_ok('MXDriverArgsConfigTest');
+}
+
+# Does it work with no configfile and not barf?
+{
+ eval { MXDriverArgsConfigTest->new(req_attr => 'foo') };
+ ok(!$@, 'Did not die with no configfile specified')
+ or diag $@;
+}
+
+# Can it load a simple YAML file with the options
+{
+ open(my $test_conf, '>', 'test.conf')
+ or die "Cannot create test.conf: $!";
+ print $test_conf <<EOM;
+Direct_Attr 123
+Inherited_Ro_Attr asdf
+Req_Attr foo
+EOM
+ close($test_conf);
+
+ my $foo = eval {
+ MXDriverArgsConfigTest->new_with_config(configfile => 'test.conf');
+ };
+ ok(!$@, 'Did not die with good General configfile')
+ or diag $@;
+
+ is($foo->req_attr, 'foo', 'req_attr works');
+ is($foo->direct_attr, 123, 'direct_attr works');
+ is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
+}
+
+END { unlink('test.conf') }
\ No newline at end of file
--- /dev/null
+package MXDriverArgsConfigTestBase;
+use Moose;
+
+has 'inherited_ro_attr' => (is => 'ro', isa => 'Str');
+
+no Moose;
+1;
+
+package MXDriverArgsConfigTest;
+use Moose;
+extends 'MXDriverArgsConfigTestBase';
+with 'MooseX::SimpleConfig';
+
+has 'direct_attr' => (is => 'ro', isa => 'Int');
+
+has 'req_attr' => (is => 'rw', isa => 'Str', required => 1);
+
+sub config_any_args {
+ return +{
+ driver_args => {
+ General => {
+ -LowerCaseNames => 1
+ }
+ }
+ }
+}
+
+no Moose;
+1;