[Jifty-commit] r4204 - in jifty/trunk: lib/Jifty/Plugin/REST
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Oct 3 22:55:38 EDT 2007
Author: alexmv
Date: Wed Oct 3 22:55:38 2007
New Revision: 4204
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
Log:
r23400 at zoq-fot-pik: chmrr | 2007-10-03 22:53:18 -0400
* Recursively transform content structures
* Set a flag when we change the method, in case apps care
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 Oct 3 22:55:38 2007
@@ -21,6 +21,7 @@
before POST qr{^ (/=/ .*) ! (DELETE|PUT|GET|POST|OPTIONS|HEAD|TRACE|CONNECT) $}x => run {
$ENV{REQUEST_METHOD} = $2;
+ $ENV{REST_REWROTE_METHOD} = 1;
dispatch $1;
};
@@ -167,6 +168,34 @@
return \%data;
}
+=head2 recurse_object_to_data REF
+
+Takes a reference, and calls C<object_to_data> on it if that is
+meaningful. If it is an arrayref, or recurses on each element. If it
+is a hashref, recurses on each value. Returns the new datastructure.
+
+=cut
+
+sub recurse_object_to_data {
+ my $o = shift;
+ return $o unless ref $o;
+
+ my $updated = object_to_data($o);
+ if ($o ne $updated) {
+ return $updated;
+ } elsif (ref $o eq "ARRAY") {
+ my @a = map {recurse_object_to_data($_)} @{$o};
+ return \@a;
+ } elsif (ref $o eq "HASH") {
+ my %h;
+ $h{$_} = recurse_object_to_data($o->{$_}) for keys %{$o};
+ return \%h;
+ } else {
+ return $o;
+ }
+}
+
+
=head2 list PREFIX items
Takes a URL prefix and a set of items to render. passes them on.
@@ -719,11 +748,7 @@
for (keys %{$out->{field_warnings}}) {
delete $out->{field_warnings}->{$_} unless $out->{field_warnings}->{$_};
}
- $out->{content} = $result->content;
-
- for my $key ( keys %{ $out->{content} } ) {
- $out->{content}{$key} = object_to_data( $out->{content}{$key} );
- }
+ $out->{content} = recurse_object_to_data($result->content);
outs(undef, $out);
More information about the Jifty-commit
mailing list