From: Brian Cassidy Date: Thu, 5 Feb 2009 14:32:56 +0000 (+0000) Subject: add JSON::XS to the top of the JSON loaders list X-Git-Tag: v0.17^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=d49610ab8c8f7a8fa979a60fa75eb20ae690135b add JSON::XS to the top of the JSON loaders list --- diff --git a/Changes b/Changes index 61e8313..3718d31 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,8 @@ Revision history for Config-Any -0.17 XXX +0.17 Thu 05 Feb 2009 - ensure require() happens against plugin specified in force_plugins. + - add JSON::XS to the top of the JSON loaders list 0.16 Mon 17 Nov 2008 - fix up branches test which did not handle the errors thrown by diff --git a/lib/Config/Any/JSON.pm b/lib/Config/Any/JSON.pm index 6e39d63..b283b86 100644 --- a/lib/Config/Any/JSON.pm +++ b/lib/Config/Any/JSON.pm @@ -49,25 +49,29 @@ sub load { my $content = do { local $/; <$fh> }; close $fh; - eval { require JSON::Syck; }; - if ( $@ ) { - require JSON; - eval { JSON->VERSION( 2 ); }; - return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $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 ); } =head2 requires_any_of( ) -Specifies that this modules requires one of L or L in -order to work. +Specifies that this modules requires one of, L, L or +L in order to work. =cut -sub requires_any_of { 'JSON::Syck', 'JSON' } +sub requires_any_of { 'JSON::XS', 'JSON::Syck', 'JSON' } =head1 AUTHOR @@ -92,6 +96,8 @@ it under the same terms as Perl itself. =item * L +=item * L + =back =cut diff --git a/lib/Config/Any/YAML.pm b/lib/Config/Any/YAML.pm index 2e800be..c2f852d 100644 --- a/lib/Config/Any/YAML.pm +++ b/lib/Config/Any/YAML.pm @@ -44,16 +44,15 @@ sub load { my $file = shift; eval { require YAML::Syck; YAML::Syck->VERSION( '0.70' ) }; - if ( $@ ) { - require YAML; - return YAML::LoadFile( $file ); - } - else { + unless ( $@ ) { open( my $fh, $file ) or die $!; my $content = do { local $/; <$fh> }; close $fh; return YAML::Syck::Load( $content ); } + + require YAML; + return YAML::LoadFile( $file ); } =head2 requires_any_of( )