1 package Config::Any::JSON;
6 use base 'Config::Any::Base';
10 Config::Any::JSON - Load JSON config files
14 Loads JSON files. Example:
30 return an array of valid extensions (C<json>, C<jsn>).
35 return qw( json jsn );
40 Attempts to load C<$file> as a JSON file.
48 open( my $fh, $file ) or die $!;
49 my $content = do { local $/; <$fh> };
52 eval { require JSON::DWIW; };
54 my $decoder = JSON::DWIW->new;
55 my ( $data, $error ) = $decoder->from_json( $content );
60 eval { require JSON::XS; };
62 my $decoder = JSON::XS->new->relaxed;
63 return $decoder->decode( $content );
66 eval { require JSON::Syck; };
68 return JSON::Syck::Load( $content );
72 eval { JSON->VERSION( 2 ); };
73 return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content );
76 =head2 requires_any_of( )
78 Specifies that this modules requires one of, L<JSON::DWIW>, L<JSON::XS>,
79 L<JSON::Syck> or L<JSON> in order to work.
83 sub requires_any_of { 'JSON::DWIW', 'JSON::XS', 'JSON::Syck', 'JSON' }
87 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
89 =head1 COPYRIGHT AND LICENSE
91 Copyright 2006-2009 by Brian Cassidy
93 This library is free software; you can redistribute it and/or modify
94 it under the same terms as Perl itself.
102 =item * L<Config::Any>
104 =item * L<JSON::DWIW>
108 =item * L<JSON::Syck>