added a flatten_to_hash option to return a simple key-value hashref instead of the...
[p5sagit/Config-Any.git] / t / 20-parse.t
index b75eab7..47d38e7 100644 (file)
@@ -13,7 +13,6 @@ use Config::Any::Perl;
 use Config::Any::XML;
 use Config::Any::YAML;
 
-
 our %ext_map = (
     conf => 'Config::Any::General',
     ini  => 'Config::Any::INI',
@@ -27,37 +26,43 @@ sub load_parser_for {
     my $f = shift;
     return unless $f;
 
-    my ($ext) = $f =~ m{ \. ( [^\.]+ ) \z }xms;
-    my $mod = $ext_map{$ext};
+    my ( $ext ) = $f =~ m{ \. ( [^\.]+ ) \z }xms;
+    my $mod = $ext_map{ $ext };
     my $mod_load_result;
-    eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' };
-    return $@ ? (1,$mod) : (0,$mod);
+    eval {
+        $mod_load_result = $mod->load( $f );
+        delete $INC{ $f } if $ext eq 'pl';
+    };
+    return $@ ? ( 1, $mod ) : ( 0, $mod );
 }
 
-for my $f (map { "t/conf/conf.$_" } keys %ext_map) {
-    my ($skip,$mod) = load_parser_for($f);
-    SKIP: {
+for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) {
+    my ( $skip, $mod ) = load_parser_for( $f );
+SKIP: {
         skip "File loading backend for $mod not found", 9 if $skip;
-    
-        ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}), 
-            "load_files with use_ext works [$f]");
-        ok(my $c = $c_arr->[0], "load_files returns an arrayref");
-        
-        ok(ref $c, "load_files arrayref contains a ref");
+
+        ok( my $c_arr
+                = Config::Any->load_files(
+                { files => [ $f ], use_ext => 1 } ),
+            "load_files with use_ext works [$f]"
+        );
+        ok( my $c = $c_arr->[ 0 ], "load_files returns an arrayref" );
+
+        ok( ref $c, "load_files arrayref contains a ref" );
         my $ref = blessed $c ? reftype $c : ref $c;
-        is(substr($ref,0,4), "HASH", "hashref");
+        is( substr( $ref, 0, 4 ), "HASH", "hashref" );
+
+        my ( $name, $cfg ) = each %$c;
+        is( $name, $f, "filename matches" );
 
-        my ($name, $cfg) = each %$c;
-        is($name, $f, "filename matches");
-        
         my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg;
-        is(substr($cfgref,0,4), "HASH", "hashref cfg");
+        is( substr( $cfgref, 0, 4 ), "HASH", "hashref cfg" );
 
-        is( $cfg->{name}, 'TestApp', "appname parses" );
-        is( $cfg->{Component}{ "Controller::Foo" }->{ foo }, 'bar',           
-            "component->cntrlr->foo = bar" );
-        is( $cfg->{Model}{ "Model::Baz" }->{ qux },          'xyzzy',         
-            "model->model::baz->qux = xyzzy" );
+        is( $cfg->{ name }, 'TestApp', "appname parses" );
+        is( $cfg->{ Component }{ "Controller::Foo" }->{ foo },
+            'bar', "component->cntrlr->foo = bar" );
+        is( $cfg->{ Model }{ "Model::Baz" }->{ qux },
+            'xyzzy', "model->model::baz->qux = xyzzy" );
     }
 }