| Config-Any documentation | Contained in the Config-Any distribution. |
Config::Any::JSON - Load JSON config files
Loads JSON files. Example:
{
"name": "TestApp",
"Controller::Foo": {
"foo": "bar"
},
"Model::Baz": {
"qux": "xyzzy"
}
}
return an array of valid extensions (json, jsn).
Attempts to load $file as a JSON file.
Specifies that this modules requires one of, JSON::DWIW, JSON::XS, JSON::Syck or JSON in order to work.
Brian Cassidy <bricas@cpan.org>
Copyright 2006-2011 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Config-Any documentation | Contained in the Config-Any distribution. |
package Config::Any::JSON; use strict; use warnings; use base 'Config::Any::Base';
sub extensions { return qw( json jsn ); }
sub load { my $class = shift; my $file = shift; open( my $fh, $file ) or die $!; my $content = do { local $/; <$fh> }; close $fh; eval { require JSON::DWIW; }; unless( $@ ) { my $decoder = JSON::DWIW->new; my ( $data, $error ) = $decoder->from_json( $content ); die $error if $error; return $data; } eval { require JSON::XS; }; unless( $@ ) { my $decoder = JSON::XS->new->relaxed; return $decoder->decode( $content ); } eval { require JSON::Syck; }; unless( $@ ) { return JSON::Syck::Load( $content ); } require JSON; eval { JSON->VERSION( 2 ); }; return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content ); }
sub requires_any_of { 'JSON::DWIW', 'JSON::XS', 'JSON::Syck', 'JSON' }
1;