add parse error tests. ensure INI errors are trapped. bumped version.
[p5sagit/Config-Any.git] / lib / Config / Any / INI.pm
index 1d0575e..e0d7215 100644 (file)
@@ -46,25 +46,37 @@ sub load {
     require Config::Tiny;
     my $config = Config::Tiny->read( $file );
 
-    my $main = delete $config->{ _ };
-    my $out;
-    $out->{ $_ } = $main->{ $_ } for keys %$main;
+    die $Config::Tiny::errstr if not defined $config;
+
+    my $out = delete $config->{ _ } || {};
 
     for my $k ( keys %$config ) {
-        my @keys = split /\s+/, $k if $MAP_SECTION_SPACE_TO_NESTED_KEY;
+        my @keys = split /\s+/, $k;
         my $ref = $config->{ $k };
 
-        if ( @keys > 1 ) {
+        if ( $MAP_SECTION_SPACE_TO_NESTED_KEY && @keys > 1 ) {
             my ( $a, $b ) = @keys[ 0, 1 ];
             $out->{ $a }->{ $b } = $ref;
         }
         else {
-            $out->{ $k } = $ref;
+            $out->{ $k } = { %{ $out->{ $k } || {} }, %$ref };
         }
     }
+
     return $out;
 }
 
+=head2 is_supported( )
+
+Returns true if L<Config::Tiny> is available.
+
+=cut
+
+sub is_supported {
+    eval { require Config::Tiny; };
+    return $@ ? 0 : 1;
+}
+
 =head1 PACKAGE VARIABLES
 
 =over 4