[Catalyst-commits] r8174 - CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD

karpet at dev.catalyst.perl.org karpet at dev.catalyst.perl.org
Fri Aug 1 02:37:45 BST 2008


Author: karpet
Date: 2008-08-01 02:37:45 +0100 (Fri, 01 Aug 2008)
New Revision: 8174

Modified:
   CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
Log:
allow for non-serial PKs by preferring input params if present

Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm	2008-07-31 16:42:52 UTC (rev 8173)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm	2008-08-01 01:37:45 UTC (rev 8174)
@@ -152,7 +152,8 @@
 Should return an array of the name of the field(s) to fetch() I<pk_value> from
 and their respective values.
 
-The default behaviour is to return B<primary_key>.
+The default behaviour is to return B<primary_key> and any corresponding
+value(s) passed via $c->req->params.
 However, if you have other unique fields in your schema, you
 might return a unique field other than the primary key.
 This allows for a more flexible URI scheme.
@@ -172,6 +173,7 @@
 If your primary key is composed of multiple columns, your return value
 should include all those columns and their values as extracted
 from I<pk_value>. Multiple values are assumed to be joined with C<;;>.
+See make_primary_key_string().
 
 =cut
 
@@ -183,11 +185,18 @@
     if ( ref $pk ) {
         my @val = split( m/;;/, $id );
         for my $col (@$pk) {
-            push( @ret, $col => shift @val );
+            my $v
+                = exists $c->req->params->{$col}
+                ? $c->req->params->{$col}
+                : shift(@val);
+            push( @ret, $col => $v );
         }
     }
     else {
-        @ret = ( $pk => $id );
+        @ret
+            = ( $pk => exists $c->req->params->{$pk}
+            ? $c->req->params->{$pk}
+            : $id );
     }
     return @ret;
 }
@@ -203,6 +212,9 @@
 but could be any object that has accessor methods with
 the same names as the field(s) specified by B<primary_key>.
 
+Multiple values are joined with C<;;> and any C<;> characters
+in the column values are URI-escaped.
+
 =cut
 
 sub make_primary_key_string {




More information about the Catalyst-commits mailing list