[Catalyst-commits] r7682 - Catalyst-Controller-REST-DBIC-Item/trunk/0.01/lib/Catalyst/Controller/REST/DBIC

jshirley at dev.catalyst.perl.org jshirley at dev.catalyst.perl.org
Tue May 6 05:27:15 BST 2008


Author: jshirley
Date: 2008-05-06 05:27:15 +0100 (Tue, 06 May 2008)
New Revision: 7682

Modified:
   Catalyst-Controller-REST-DBIC-Item/trunk/0.01/lib/Catalyst/Controller/REST/DBIC/Item.pm
Log:
Additional pod, some hacks to play nicely with REST::ForBrowsers (drolsky++)

Modified: Catalyst-Controller-REST-DBIC-Item/trunk/0.01/lib/Catalyst/Controller/REST/DBIC/Item.pm
===================================================================
--- Catalyst-Controller-REST-DBIC-Item/trunk/0.01/lib/Catalyst/Controller/REST/DBIC/Item.pm	2008-05-06 03:49:24 UTC (rev 7681)
+++ Catalyst-Controller-REST-DBIC-Item/trunk/0.01/lib/Catalyst/Controller/REST/DBIC/Item.pm	2008-05-06 04:27:15 UTC (rev 7682)
@@ -57,9 +57,32 @@
 
 =head1 CONFIGURATION
 
-A list of functions that can be exported.  You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
+=over
 
+=item class
+
+What is your L<DBIx::Class> schema class to attach to?  This is the part you
+would put in C<< $c->model(...) >>
+
+=item item_key
+
+What goes in C<< ->search({ item_key => $identifier }) >>
+
+=item serialize_method
+
+Call this on result sets and items to serialize them.  This is useful as
+a base class in your DBIC schema (or just use get_columns) when you want to
+support serializers that won't touch blessed objects, or don't want to serialize
+the blessed object
+
+=item browser_serialize
+
+Set this value to 0 if you don't want to serialize a browser request.  This
+requires you use L<Catalyst::Request::REST::ForBrowsers>, and will throw an
+exception if you don't use it.
+
+=back
+
 =head1 GENERATED REST METHODS
 
 =head2 rest_list PathPart('')
@@ -70,8 +93,27 @@
 
 }
 
-sub list_GET  { }
+sub list_GET {
+    my ( $self, $c ) = @_;
 
+    my $rs = $self->get_rs($c);
+    my $entity;
+
+    if ( defined $self->{browser_serialize} and 
+         $self->{browser_serialize} == 0 and
+         $c->req->looks_like_browser 
+    ) {
+        $entity = $rs;
+    }
+    elsif ( my $method = $self->{serialize_method} ) {
+        $entity = $rs->can($method) ? $rs->$method : $rs;
+    } else {
+        $entity = $rs;
+    }
+    return $self->status_ok( $c, entity => $entity );
+}
+
+
 =head2 rest_item PathPart('') CaptureArgs(1)
 
 This method is used to handle triggering the single item methods.  Override
@@ -96,10 +138,22 @@
         return $self->status_not_found( $c, 
             message => $c->localize('ITEM_NOT_FOUND') );
     }
-    
-    return $self->status_ok( $c,
-        entity => $item->can('serialize') ? $item->serialize : $item
-    );
+
+    my $entity;
+    if ( defined $self->{browser_serialize} and 
+         $self->{browser_serialize} == 0 and
+         $c->req->looks_like_browser 
+    ) {
+        $entity = $item;
+    }
+    elsif ( my $method = $self->{serialize_method} ) {
+        $c->log->debug("Serializing with $method ($self->{browser_serialize} and " . $c->req->looks_like_browser . ")");
+        $entity = $item->can($method) ? $item->$method : $item;
+    } else {
+        $entity = $item;
+    }
+   
+    return $self->status_ok( $c, entity => $entity );
 }
 
 =head1 get_item($c, $identifier)




More information about the Catalyst-commits mailing list