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 if ( eval { require JSON::DWIW } ) {
53 my $decoder = JSON::DWIW->new;
54 my ( $data, $error ) = $decoder->from_json( $content );
58 elsif ( eval { require JSON::XS } ) {
59 my $decoder = JSON::XS->new->relaxed;
60 return $decoder->decode( $content );
62 elsif ( eval { require JSON::Syck } ) {
63 return JSON::Syck::Load( $content );
65 elsif ( eval { require JSON::PP; JSON::PP->VERSION( 2 ); } ) {
66 my $decoder = JSON::PP->new->relaxed;
67 return $decoder->decode( $content );
70 if ( eval { JSON->VERSION( 2 ) } ) {
71 return JSON::from_json( $content );
74 return JSON::jsonToObj( $content );
78 =head2 requires_any_of( )
80 Specifies that this modules requires one of, L<JSON::DWIW>, L<JSON::XS>,
81 L<JSON::Syck> or L<JSON> in order to work.
85 sub requires_any_of { 'JSON::DWIW', 'JSON::XS', 'JSON::Syck', 'JSON::PP', 'JSON' }
89 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
91 =head1 COPYRIGHT AND LICENSE
93 Copyright 2006-2016 by Brian Cassidy
95 This library is free software; you can redistribute it and/or modify
96 it under the same terms as Perl itself.
104 =item * L<Config::Any>
106 =item * L<JSON::DWIW>
110 =item * L<JSON::Syck>