[Jifty-commit] r4467 - in jifty/trunk: lib/Jifty/Plugin/REST
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Nov 19 18:46:26 EST 2007
Author: sartak
Date: Mon Nov 19 18:46:25 2007
New Revision: 4467
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
Log:
r45310 at onn: sartak | 2007-11-19 18:46:02 -0500
Add better support for dates in the REST plugin, rewrite a somewhat hairy method
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 Mon Nov 19 18:46:25 2007
@@ -98,11 +98,24 @@
sub stringify {
# XXX: allow configuration to specify model fields that are to be
# expanded
- no warnings 'uninitialized';
- my @r = map { ref($_) && UNIVERSAL::isa($_, 'Jifty::Record')
- ? reference_to_data($_) :
- defined $_ ? '' . $_ : undef } @_;
- return wantarray ? @r : pop @r;
+ my @r;
+
+ for (@_) {
+ if (UNIVERSAL::isa($_, 'Jifty::Record')) {
+ push @r, reference_to_data($_);
+ }
+ elsif (UNIVERSAL::isa($_, 'Jifty::DateTime')) {
+ push @r, _datetime_to_data($_);
+ }
+ elsif (defined $_) {
+ push @r, '' . $_; # force stringification
+ }
+ else {
+ push @r, undef;
+ }
+ }
+
+ return wantarray ? @r : $r[-1];
}
=head2 reference_to_data
@@ -125,6 +138,7 @@
Jifty::DBI::Collection
Jifty::DBI::Record
+ Jifty::DateTime
=cut
@@ -134,6 +148,7 @@
my %types = (
'Jifty::DBI::Collection' => \&_collection_to_data,
'Jifty::DBI::Record' => \&_record_to_data,
+ 'Jifty::DateTime' => \&_datetime_to_data,
);
for my $type ( keys %types ) {
@@ -168,6 +183,18 @@
return \%data;
}
+sub _datetime_to_data {
+ my $dt = shift;
+
+ # if it looks like just a date, then return just the date portion
+ return $dt->ymd
+ if lc($dt->time_zone->name) eq 'floating'
+ && $dt->hms('') eq '000000';
+
+ # otherwise let stringification take care of it
+ return $dt;
+}
+
=head2 recurse_object_to_data REF
Takes a reference, and calls C<object_to_data> on it if that is
More information about the Jifty-commit
mailing list