[Catalyst-commits] r9211 - in trunk/Config-Any: . lib/Config/Any

bricas at dev.catalyst.perl.org bricas at dev.catalyst.perl.org
Thu Feb 5 14:32:57 GMT 2009


Author: bricas
Date: 2009-02-05 14:32:56 +0000 (Thu, 05 Feb 2009)
New Revision: 9211

Modified:
   trunk/Config-Any/Changes
   trunk/Config-Any/lib/Config/Any/JSON.pm
   trunk/Config-Any/lib/Config/Any/YAML.pm
Log:
add JSON::XS to the top of the JSON loaders list

Modified: trunk/Config-Any/Changes
===================================================================
--- trunk/Config-Any/Changes	2009-02-05 14:01:11 UTC (rev 9210)
+++ trunk/Config-Any/Changes	2009-02-05 14:32:56 UTC (rev 9211)
@@ -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

Modified: trunk/Config-Any/lib/Config/Any/JSON.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/JSON.pm	2009-02-05 14:01:11 UTC (rev 9210)
+++ trunk/Config-Any/lib/Config/Any/JSON.pm	2009-02-05 14:32:56 UTC (rev 9211)
@@ -49,25 +49,29 @@
     my $content = do { local $/; <$fh> };
     close $fh;
 
+    eval { require JSON::XS; };
+    unless( $@ ) {
+        return JSON::XS::decode_json( $content );
+    }
+
     eval { require JSON::Syck; };
-    if ( $@ ) {
-        require JSON;
-        eval { JSON->VERSION( 2 ); };
-        return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content );
-    }
-    else {
+    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<JSON::Syck> or L<JSON> in 
-order to work.
+Specifies that this modules requires one of,  L<JSON::XS>, L<JSON::Syck> or
+L<JSON> 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 @@
 
 =item * L<JSON::Syck>
 
+=item * L<JSON::XS>
+
 =back
 
 =cut

Modified: trunk/Config-Any/lib/Config/Any/YAML.pm
===================================================================
--- trunk/Config-Any/lib/Config/Any/YAML.pm	2009-02-05 14:01:11 UTC (rev 9210)
+++ trunk/Config-Any/lib/Config/Any/YAML.pm	2009-02-05 14:32:56 UTC (rev 9211)
@@ -44,16 +44,15 @@
     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( )




More information about the Catalyst-commits mailing list