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=954e305c825420b5d04b0d1b6dcc6d274342394f;hb=c793253e5f2ad3ca9d60e96e07a5d87fa344ec31;hpb=f0e3c2214342d0d8a8839009b8b9c7e6bfbc7ab2 diff --git a/lib/Config/Any/JSON.pm b/lib/Config/Any/JSON.pm index 954e305..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,28 +49,37 @@ sub load { my $content = do { local $/; <$fh> }; close $fh; - eval { require JSON::Syck; }; - if( $@ ) { - require JSON; - JSON->import; - return 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. @@ -85,6 +96,8 @@ it under the same terms as Perl itself. =item * L +=item * L + =back =cut