X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FConfigLoader%2FJSON.pm;h=248543b752ad31ab5b6ff064dd612b17988c088b;hb=06b5f4a9a71a1c3781c6074c9bc701e1581785ac;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..248543b 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/JSON.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/JSON.pm @@ -3,8 +3,6 @@ package Catalyst::Plugin::ConfigLoader::JSON; use strict; use warnings; -use File::Slurp; - =head1 NAME Catalyst::Plugin::ConfigLoader::JSON - Load JSON config files @@ -15,13 +13,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 +37,21 @@ Attempts to load C<$file> as a JSON file. =cut sub load { - my $class = shift; - my $confpath = shift; - - my @files; - if( $confpath =~ /\.(.{3,4})$/ ) { - return unless $1 =~ /^jso?n$/; - @files = $confpath; + my $class = shift; + my $file = shift; + + open( my $fh, $file ) or die $!; + my $content = do { local $/; <$fh> }; + close $fh; + + 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 * L + =back =cut