[Jifty-commit] r3218 - jifty/trunk/lib/Jifty/Plugin/REST

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed May 9 04:06:59 EDT 2007


Author: clkao
Date: Wed May  9 04:06:57 2007
New Revision: 3218

Modified:
   jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm

Log:
REST plugin: render referencing fields in a saner fashion.

Modified: jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm	Wed May  9 04:06:57 2007
@@ -93,11 +93,21 @@
 =cut
 
 sub stringify {
+    # XXX: allow configuration to specify model fields that are to be
+    # expanded
     no warnings 'uninitialized';
-    my @r = map { defined $_ ? '' . $_ : undef } @_;
+    my @r = map { ref($_) && UNIVERSAL::isa($_, 'Jifty::Record')
+                             ? reference_to_data($_) :
+                  defined $_ ? '' . $_               : undef } @_;
     return wantarray ? @r : pop @r;
 }
 
+sub reference_to_data {
+    my $obj = shift;
+    my ($model) = map { s/::/./g; $_ } ref($obj);
+    return { jifty_model_reference => 1, id => $obj->id, model => $model };
+}
+
 =head2 object_to_data OBJ
 
 Takes an object and converts the known types into simple data structures.


More information about the Jifty-commit mailing list