refactored
[catagits/Catalyst-Plugin-ConfigLoader.git] / lib / Catalyst / Plugin / ConfigLoader.pm
index ef29444..d4092cb 100644 (file)
@@ -9,7 +9,7 @@ use Module::Pluggable::Fast
     search  => [ __PACKAGE__ ],\r
     require => 1;\r
 \r
-our $VERSION = '0.01';\r
+our $VERSION = '0.02';\r
 \r
 =head1 NAME\r
 \r
@@ -17,9 +17,9 @@ Catalyst::Plugin::ConfigLoader - Load config files of various types
 \r
 =head1 SYNOPSIS\r
 \r
-       package MyApp;\r
-       \r
-       use Catalyst( ConfigLoader );\r
+    package MyApp;\r
+    \r
+    use Catalyst( ConfigLoader );\r
        \r
     # by default myapp.* will be loaded\r
     # you can specify a file if you'd like\r
@@ -43,14 +43,29 @@ successfully loaded.
 =cut\r
 \r
 sub setup {\r
-    my $c        = shift;\r
-    my $confpath = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );\r
+    my $c    = shift;\r
+    my $path = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );\r
+\r
+    my( $extension ) = ( $path =~ /\.(.{1,4})$/ );\r
     \r
     for my $loader ( $c->_config_loaders ) {\r
-        my $config = $loader->load( $confpath );\r
-        if( $config ) {\r
-            $c->config( $config );\r
-            last;\r
+        my @files;\r
+        my @extensions = $loader->extensions;\r
+        if( $extension ) {\r
+            next unless grep { $_ eq $extension } @extensions;\r
+            push @files, $path;\r
+        }\r
+        else {\r
+            push @files, "$path.$_" for @extensions;\r
+        }\r
+\r
+        for( @files ) {\r
+            next unless -f $_;\r
+            my $config = $loader->load( $_ );\r
+            if( $config ) {\r
+                $c->config( $config );\r
+                last;\r
+            }\r
         }\r
     }\r
 \r