distro work
[p5sagit/Config-Any.git] / t / 20-parse.t
index 420b581..b75eab7 100644 (file)
@@ -1,63 +1,63 @@
-package MockApp;\r
-use strict;\r
-use warnings;\r
-\r
-$|++;\r
-use Test::More tests => 54;\r
-use Scalar::Util qw(blessed reftype);\r
-use Config::Any;\r
-use Config::Any::General;\r
-use Config::Any::INI;\r
-use Config::Any::JSON;\r
-use Config::Any::Perl;\r
-use Config::Any::XML;\r
-use Config::Any::YAML;\r
-\r
-\r
-our %ext_map = (\r
-       conf => 'Config::Any::General',\r
-       ini  => 'Config::Any::INI',\r
-       json => 'Config::Any::JSON',\r
-       pl   => 'Config::Any::Perl',\r
-       xml  => 'Config::Any::XML',\r
-       yml  => 'Config::Any::YAML'\r
-);\r
-\r
-sub load_parser_for {\r
-    my $f = shift;\r
-    return unless $f;\r
-\r
-       my ($ext) = $f =~ m{ \. ( [^\.]+ ) \z }xms;\r
-       my $mod = $ext_map{$ext};\r
-       my $mod_load_result;\r
-       eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' };\r
-    return $@ ? (1,$mod) : (0,$mod);\r
-}\r
-\r
-for my $f (map { "t/conf/conf.$_" } keys %ext_map) {\r
-    my ($skip,$mod) = load_parser_for($f);\r
-       SKIP: {\r
-               skip "File loading backend for $mod not found", 9 if $skip;\r
-       \r
-               ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}), \r
-                       "load_files with use_ext works [$f]");\r
-               ok(my $c = $c_arr->[0], "load_files returns an arrayref");\r
-               \r
-               ok(ref $c, "load_files arrayref contains a ref");\r
-               my $ref = blessed $c ? reftype $c : ref $c;\r
-               is(substr($ref,0,4), "HASH", "hashref");\r
-\r
-               my ($name, $cfg) = each %$c;\r
-               is($name, $f, "filename matches");\r
-               \r
-               my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg;\r
-               is(substr($cfgref,0,4), "HASH", "hashref cfg");\r
-\r
-               is( $cfg->{name}, 'TestApp', "appname parses" );\r
-               is( $cfg->{Component}{ "Controller::Foo" }->{ foo }, 'bar',               \r
-                       "component->cntrlr->foo = bar" );\r
-               is( $cfg->{Model}{ "Model::Baz" }->{ qux },              'xyzzy',                 \r
-                       "model->model::baz->qux = xyzzy" );\r
-       }\r
-}\r
-\r
+package MockApp;
+use strict;
+use warnings;
+
+$|++;
+use Test::More tests => 54;
+use Scalar::Util qw(blessed reftype);
+use Config::Any;
+use Config::Any::General;
+use Config::Any::INI;
+use Config::Any::JSON;
+use Config::Any::Perl;
+use Config::Any::XML;
+use Config::Any::YAML;
+
+
+our %ext_map = (
+    conf => 'Config::Any::General',
+    ini  => 'Config::Any::INI',
+    json => 'Config::Any::JSON',
+    pl   => 'Config::Any::Perl',
+    xml  => 'Config::Any::XML',
+    yml  => 'Config::Any::YAML'
+);
+
+sub load_parser_for {
+    my $f = shift;
+    return unless $f;
+
+    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);
+}
+
+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");
+        my $ref = blessed $c ? reftype $c : ref $c;
+        is(substr($ref,0,4), "HASH", "hashref");
+
+        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( $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" );
+    }
+}
+