[Jifty-commit] r2753 - jifty/branches/virtual-models/lib/Jifty/Record

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Feb 5 23:06:49 EST 2007


Author: audreyt
Date: Mon Feb  5 23:06:48 2007
New Revision: 2753

Modified:
   jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm

Log:
* Finish off the rest of the Jifty->SVKhooks in the Jifty::Record::Versioned backend.

Modified: jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm	Mon Feb  5 23:06:48 2007
@@ -80,38 +80,55 @@
     return $edit;
 }
 
+sub _dump {
+    local $YAML::Syck::Headless = 1;
+    local $YAML::Syck::ImplicitTyping = 1;
+    local $YAML::Syck::ImplicitBinary = 1;
+    local $YAML::Syck::ImplicitUnicode = 1;
+    YAML::Syck::Dump($_[1]);
+}
+
+sub _edit {
+    my ($self, $code, $rv) = @_;
+    return $rv unless $rv;
+
+    my $edit = $self->new_edit;
+    $code->($edit);
+    $edit->close_edit;
+
+    return $rv;
+}
+
 sub __create {
     my ($self, %attribs) = @_;
     my $uuid = ($attribs{__uuid} ||= Jifty::Util->generate_uuid);
-    my $rv = $self->SUPER::__create(%attribs);
-    if ($rv) {
-        # Write to SQL!
-        my $edit= $self->new_edit;
-
-        local $YAML::Syck::Headless = 1;
-        local $YAML::Syck::ImplicitTyping = 1;
-        local $YAML::Syck::ImplicitBinary = 1;
-        local $YAML::Syck::ImplicitUnicode = 1;
 
+    $self->_edit(sub {
+        my $edit = shift;
         foreach my $key (sort keys %attribs) {
             next if $key eq '__uuid';
             $edit->add_file("=/$uuid/$key");
-            $edit->modify_file("=/$uuid/$key", YAML::Syck::Dump($attribs{$key}));
+            $edit->modify_file("=/$uuid/$key", $self->_dump($attribs{$key}));
         }
-
-        $edit->close_edit;
-    }
-    return $rv;
+    }, $self->SUPER::__create(%attribs));
 }
 
 sub __set {
-    my $self = shift;
-    return $self->SUPER::__set(@_);
+    my ($self, %attribs) = @_;
+    $self->_edit(sub {
+        my $edit = shift;
+        my $uuid = $self->__uuid or return;
+        $edit->modify_file("=/$uuid/$attribs{column}", $self->_dump($attribs{value}));
+    }, $self->SUPER::__set(%attribs));
 }
 
 sub __delete {
     my $self = shift;
-    return $self->SUPER::__set(@_);
+    $self->_edit(sub {
+        my $edit = shift;
+        my $uuid = $self->__uuid or return;
+        $edit->delete_entry("=/$uuid");
+    }, $self->SUPER::__delete(@_));
 }
 
 1;


More information about the Jifty-commit mailing list