[Jifty-commit] r510 - in jifty/trunk: lib/Jifty lib/Jifty/Script

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Jan 16 05:20:42 EST 2006


Author: autrijus
Date: Mon Jan 16 05:20:40 2006
New Revision: 510

Added:
   jifty/trunk/lib/Jifty/YAML.pm
Modified:
   jifty/trunk/MANIFEST
   jifty/trunk/Makefile.PL
   jifty/trunk/lib/Jifty/Config.pm
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/JSON.pm
   jifty/trunk/lib/Jifty/Request.pm
   jifty/trunk/lib/Jifty/Script/App.pm
   jifty/trunk/lib/Jifty/Script/Schema.pm

Log:
* YAML::Syck and JSON::Syck support.

Modified: jifty/trunk/MANIFEST
==============================================================================
--- jifty/trunk/MANIFEST	(original)
+++ jifty/trunk/MANIFEST	Mon Jan 16 05:20:40 2006
@@ -88,6 +88,7 @@
 lib/Jifty/Web/Menu.pm
 lib/Jifty/Web/PageRegion.pm
 lib/Jifty/Web/Session.pm
+lib/Jifty/YAML.pm
 LICENSE
 Makefile.PL
 MANIFEST			This list of files

Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Mon Jan 16 05:20:40 2006
@@ -37,7 +37,6 @@
 requires('HTTP::Server::Simple::Recorder');
 requires('Hash::Merge');
 requires('Hook::LexWrap');
-requires('JSON');
 requires('Jifty::DBI' => '0.06' );            # Jifty::DBI::Collection Jifty::DBI::Handle Jifty::DBI::Record::Cachable Jifty::DBI::SchemaGenerator
 requires('Locale::Maketext::Simple');
 requires('Log::Log4perl');
@@ -64,7 +63,16 @@
 requires('XML::Writer');
 requires('XML::XPath');
 requires('version');
-requires('YAML');
+
+if (can_cc()) {
+    requires('YAML::Syck' => 0.27) unless can_use('YAML' => 0.35);
+    requires('JSON::Syck' => 0.05) unless can_use('JSON' => 0.01);
+}
+else {
+    requires('YAML' => 0.35) unless can_use('YAML::Syck' => 0.27);
+    requires('JSON' => 0.01) unless can_use('JSON::Syck' => 0.05);
+}
+
 version_from('lib/Jifty.pm');
 #&auto_bundle_deps();
 &auto_install();

Modified: jifty/trunk/lib/Jifty/Config.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Config.pm	(original)
+++ jifty/trunk/lib/Jifty/Config.pm	Mon Jan 16 05:20:40 2006
@@ -15,8 +15,8 @@
 use Jifty::Everything;
 use Jifty::DBI::Handle;
 use Jifty::Util;
+use Jifty::YAML;
 use UNIVERSAL::require;
-use YAML;
 use File::Spec;
 use File::Basename;
 use Log::Log4perl;
@@ -252,7 +252,7 @@
 
     # only try to load files that exist
     return {} unless ( $file && -f $file );
-    my $hashref = YAML::LoadFile($file)
+    my $hashref = Jifty::YAML::LoadFile($file)
         or die "I couldn't load config file $file: $!";
 
     $hashref = $self->_expand_relative_paths($hashref);

Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Mon Jan 16 05:20:40 2006
@@ -614,7 +614,6 @@
 =cut
 
 sub _do_show {
-    use YAML;
     my $self = shift;
     my $path;
     $path = shift if (@_);

Modified: jifty/trunk/lib/Jifty/JSON.pm
==============================================================================
--- jifty/trunk/lib/Jifty/JSON.pm	(original)
+++ jifty/trunk/lib/Jifty/JSON.pm	Mon Jan 16 05:20:40 2006
@@ -9,19 +9,36 @@
 
 =head1 DESCRIPTION
 
-Provides a wrapper around the L<JSON> library.  The JSON specification
-at L<http://www.crockford.com/JSON/> states that only double-quotes
-are possible for specifying strings.  However, for the purposes of
-embedding Javascript-compatible objects in XHTML attributes (which use
+Provides a wrapper around the L<JSON> library.
+
+The JSON specification at L<http://www.crockford.com/JSON/> states that only
+double-quotes are possible for specifying strings.  However, for the purposes
+of embedding Javascript-compatible objects in XHTML attributes (which use
 double-quotes), we sometimes want to provide strings in single quotes.
 This provides a version of L<JSON/objToJson> which allows
 single-quoted string output.
 
+If the faster L<JSON::Syck> is available, it is preferred over the pure-perl
+L<JSON>, as it provides native support for single-quoted strings..
+
 =head1 METHODS
 
 =cut
 
-use JSON ();
+BEGIN {
+    local $@;
+    no strict 'refs';
+    no warnings 'once';
+    if (eval { require JSON::Syck; $JSON::Syck::VERSION >= 0.05 }) {
+        *jsonToObj = *jsonToObj_syck;
+        *objToJson = *objToJson_syck;
+    }
+    else {
+        require JSON;
+        *jsonToObj = *jsonToObj_pp;
+        *objToJson = *objToJson_pp;
+    }
+}
 
 =head2 jsonToObj JSON, [ARGUMENTS]
 
@@ -30,7 +47,12 @@
 
 =cut
 
-sub jsonToObj {
+sub jsonToObj_syck {
+    local $JSON::Syck::SingleQuote = 0;
+    JSON::Syck::Load($_[0]);
+}
+
+sub jsonToObj_pp {
     return JSON::jsonToObj(@_);
 }
 
@@ -44,10 +66,17 @@
 
 =cut
 
+sub objToJson_syck {
+    my ($obj, $args) = @_;
+
+    local $JSON::Syck::SingleQuote = $args->{singlequote};
+    JSON::Syck::Dump($obj);
+}
+
 # We should escape double-quotes somehow, so that we can guarantee
 # that double-quotes *never* appear in the JSON string that is
 # returned.
-sub objToJson {
+sub objToJson_pp {
     my ($obj, $args) = @_;
 
     # Unless we're asking for single-quoting, just do what JSON.pm

Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm	(original)
+++ jifty/trunk/lib/Jifty/Request.pm	Mon Jan 16 05:20:40 2006
@@ -7,7 +7,7 @@
 __PACKAGE__->mk_accessors(qw(arguments just_validating path continuation));
 
 use Jifty::JSON;
-use YAML;
+use Jifty::YAML;
 
 =head1 NAME
 
@@ -112,7 +112,7 @@
         if ($ct eq "text/x-json") {
             return $self->from_data_structure(Jifty::JSON::jsonToObj($data));
         } elsif ($ct eq "text/x-yaml") {
-            return $self->from_data_structure(YAML::Load($data));
+            return $self->from_data_structure(Jifty::YAML::Load($data));
         }
     }
 

Modified: jifty/trunk/lib/Jifty/Script/App.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/App.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/App.pm	Mon Jan 16 05:20:40 2006
@@ -4,9 +4,9 @@
 package Jifty::Script::App;
 use base qw'App::CLI::Command Class::Accessor';
 
-use YAML;
 use File::Copy;
 use Jifty::Config;
+use Jifty::YAML;
 
 __PACKAGE__->mk_accessors(qw/prefix dist_name mod_name/);
 
@@ -136,7 +136,7 @@
     my $default_config = $cfg->guess($self->dist_name);
     my $file = join("/",$self->prefix, 'etc','config.yml');
     print("Creating configuration file $file\n");
-    YAML::DumpFile($file => $default_config);
+    Jifty::YAML::DumpFile($file => $default_config);
 
 }
 

Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm	Mon Jan 16 05:20:40 2006
@@ -6,7 +6,6 @@
 
 use Pod::Usage;
 use UNIVERSAL::require;
-use YAML;
 use version;
 use Jifty::DBI::SchemaGenerator;
 use Jifty::Config;

Added: jifty/trunk/lib/Jifty/YAML.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/YAML.pm	Mon Jan 16 05:20:40 2006
@@ -0,0 +1,36 @@
+use warnings;
+use strict;
+
+package Jifty::YAML;
+
+=head1 NAME
+
+Jifty::YAML -- Wrapper around L<YAML>
+
+=head1 DESCRIPTION
+
+Provides a wrapper around the L<YAML> library.  If the faster L<YAML::Syck>
+is available, then it's used instead.
+
+=cut
+
+BEGIN {
+    local $@;
+    no strict 'refs';
+    no warnings 'once';
+    if (eval { require YAML::Syck; $YAML::Syck::VERSION >= 0.27 }) {
+        *Load = *YAML::Syck::Load;
+        *Dump = *YAML::Syck::Dump;
+        *LoadFile = *YAML::Syck::LoadFile;
+        *DumpFile = *YAML::Syck::DumpFile;
+    }
+    else {
+        require YAML;
+        *Load = *YAML::Load;
+        *Dump = *YAML::Dump;
+        *LoadFile = *YAML::LoadFile;
+        *DumpFile = *YAML::DumpFile;
+    }
+}
+
+1;


More information about the Jifty-commit mailing list