6 use Test::More tests => 54;
7 use Scalar::Util qw(blessed reftype);
9 use Config::Any::General;
11 use Config::Any::JSON;
12 use Config::Any::Perl;
14 use Config::Any::YAML;
17 conf => 'Config::Any::General',
18 ini => 'Config::Any::INI',
19 json => 'Config::Any::JSON',
20 pl => 'Config::Any::Perl',
21 xml => 'Config::Any::XML',
22 yml => 'Config::Any::YAML'
29 my ( $ext ) = $f =~ m{ \. ( [^\.]+ ) \z }xms;
30 my $mod = $ext_map{ $ext };
33 $mod_load_result = $mod->load( $f );
34 delete $INC{ $f } if $ext eq 'pl';
36 return $@ ? ( 1, $mod ) : ( 0, $mod );
39 for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) {
40 my ( $skip, $mod ) = load_parser_for( $f );
42 skip "File loading backend for $mod not found", 9 if $skip;
45 = Config::Any->load_files(
46 { files => [ $f ], use_ext => 1 } ),
47 "load_files with use_ext works [$f]"
49 ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" );
51 ok( ref $c, "load_files arrayref contains a ref" );
52 my $ref = blessed $c ? reftype $c : ref $c;
53 is( substr( $ref, 0, 4 ), "HASH", "hashref" );
55 my ( $name, $cfg ) = each %$c;
56 is( $name, $f, "filename matches" );
58 my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg;
59 is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" );
61 is( $cfg->{ name }, 'TestApp', "appname parses" );
62 is( $cfg->{ Component }{ "Controller::Foo" }->{ foo },
63 'bar', "component->cntrlr->foo = bar" );
64 is( $cfg->{ Model }{ "Model::Baz" }->{ qux },
65 'xyzzy', "model->model::baz->qux = xyzzy" );