X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=lib%2FConfig%2FAny%2FJSON.pm;h=ce2954906b287afb9c8cefbf525e793888559451;hp=5e4edf3ddbcf3c6679a19c9a0ae085e950961ade;hb=c793253e5f2ad3ca9d60e96e07a5d87fa344ec31;hpb=92a04e78451078b33f75e7c44d247b024c27b4f7 diff --git a/lib/Config/Any/JSON.pm b/lib/Config/Any/JSON.pm index 5e4edf3..ce29549 100644 --- a/lib/Config/Any/JSON.pm +++ b/lib/Config/Any/JSON.pm @@ -3,6 +3,8 @@ package Config::Any::JSON; use strict; use warnings; +use base 'Config::Any::Base'; + =head1 NAME Config::Any::JSON - Load JSON config files @@ -47,27 +49,37 @@ sub load { my $content = do { local $/; <$fh> }; close $fh; - eval { require JSON::Syck; }; - if ( $@ ) { - require JSON; - return JSON::jsonToObj( $content ); + eval { require JSON::XS; }; + unless( $@ ) { + return JSON::XS::decode_json( $content ); } - else { + + eval { require JSON::Syck; }; + unless( $@ ) { return JSON::Syck::Load( $content ); } + + require JSON; + eval { JSON->VERSION( 2 ); }; + return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content ); } -=head1 AUTHOR +=head2 requires_any_of( ) -=over 4 +Specifies that this modules requires one of, L, L or +L in order to work. -=item * Brian Cassidy Ebricas@cpan.orgE +=cut -=back +sub requires_any_of { 'JSON::XS', 'JSON::Syck', 'JSON' } + +=head1 AUTHOR + +Brian Cassidy Ebricas@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Brian Cassidy +Copyright 2006-2009 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -84,6 +96,8 @@ it under the same terms as Perl itself. =item * L +=item * L + =back =cut