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 );
71 eval { require JSON::PP; JSON::PP->VERSION( 2 ); };
73 my $decoder = JSON::PP->new->relaxed;
74 return $decoder->decode( $content );
78 eval { JSON->VERSION( 2 ); };
79 return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content );
82 =head2 requires_any_of( )
84 Specifies that this modules requires one of, L<JSON::DWIW>, L<JSON::XS>,
85 L<JSON::Syck> or L<JSON> in order to work.
89 sub requires_any_of { 'JSON::DWIW', 'JSON::XS', 'JSON::Syck', 'JSON::PP', 'JSON' }
93 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
95 =head1 COPYRIGHT AND LICENSE
97 Copyright 2006-2013 by Brian Cassidy
99 This library is free software; you can redistribute it and/or modify
100 it under the same terms as Perl itself.
108 =item * L<Config::Any>
110 =item * L<JSON::DWIW>
114 =item * L<JSON::Syck>