X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FConfigLoader%2FJSON.pm;h=041e55fe614433468bcc946fbbfacb82154070c2;hb=refs%2Ftags%2Fv0.02;hp=02cdced10520cedd08bf1d3ebb3505e20bc56b76;hpb=b2d855940c68a8bec09c76f6235b804ef9090dc6;p=catagits%2FCatalyst-Plugin-ConfigLoader.git diff --git a/lib/Catalyst/Plugin/ConfigLoader/JSON.pm b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm index 02cdced..041e55f 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/JSON.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm @@ -15,13 +15,23 @@ Loads JSON files. Example: { "name": "TestApp", - "Controller::Config": { + "Controller::Foo": { "foo": "bar" } } =head1 METHODS +=head2 extensions( ) + +return an array of valid extensions (C, C). + +=cut + +sub extensions { + return qw( json jsn ); +} + =head2 load( $file ) Attempts to load C<$file> as a JSON file. @@ -29,32 +39,19 @@ Attempts to load C<$file> as a JSON file. =cut sub load { - my $class = shift; - my $confpath = shift; + my $class = shift; + my $file = shift; - my @files; - if( $confpath =~ /\.(.{3,4})$/ ) { - return unless $1 =~ /^jso?n$/; - @files = $confpath; + my $content = read_file( $file ); + + eval { require JSON::Syck; }; + if( $@ ) { + require JSON; + JSON->import; + return jsonToObj( $content ); } else { - @files = map { "$confpath.$_" } qw( json jsn ); - } - - for my $file ( @files ) { - next unless -f $file; - - my $content = read_file( $file ); - - eval { require JSON::Syck; }; - if( $@ ) { - require JSON; - JSON->import; - return jsonToObj( $content ); - } - else { - return JSON::Syck::Load( $content ); - } + return JSON::Syck::Load( $content ); } } @@ -79,6 +76,8 @@ it under the same terms as Perl itself. =item * L +=item * + =back =cut