[Catalyst-commits] r14362 -
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Wed Oct 31 04:46:37 GMT 2012
Author: karpet
Date: 2012-10-31 04:46:37 +0000 (Wed, 31 Oct 2012)
New Revision: 14362
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
Log:
fix chaining for rest related view/list
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-10-31 04:00:42 UTC (rev 14361)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2012-10-31 04:46:37 UTC (rev 14362)
@@ -652,9 +652,21 @@
$c->res->status(204); # enacted, no content
}
+=head2 fetch_related
+
+Attribute: chained to fetch() like related() is.
+
+=cut
+
+sub fetch_related : PathPart('') Chained('fetch') CaptureArgs(1) {
+ my ( $self, $c, $rel ) = @_;
+ return if $self->has_errors($c);
+ $c->stash( rel_name => $rel );
+}
+
=head2 list_related
-Attribute: chained to related().
+Attribute: chained to fetch_related().
Returns list of related objects.
@@ -666,23 +678,28 @@
=cut
-sub list_related : PathPart('list') Chained('fetch') CaptureArgs(1) {
+sub list_related : PathPart('list') Chained('fetch_related') Args(0) {
my ( $self, $c, $rel ) = @_;
return if $self->has_errors($c);
- $self->do_model( $c, 'search_related', $c->stash->{object}, $rel, );
+ $c->stash(
+ results => $self->do_model(
+ $c, 'search_related',
+ $c->stash->{object}, $c->stash->{rel_name},
+ )
+ );
}
=head2 view_related
Attribute: chained to related().
-Returns list of related objects.
+Returns list of related objects based on foreign key value.
Example:
http://yoururl/user/123/group/456/view
-will return groups related to user C<123>.
+will return groups of pk C<456> related to user C<123>.
=cut
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 04:00:42 UTC (rev 14361)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2012-10-31 04:46:37 UTC (rev 14362)
@@ -206,10 +206,8 @@
}
}
- my $http_method = $self->req_method($c);
-
- $self->related( $c, $rel_name, $fval );
-
+ my $http_method = $self->req_method($c);
+ my $dispatch_method = 'related';
my $rpc_method;
if ($rpc) {
$rpc_method = $rpc;
@@ -221,7 +219,15 @@
$rpc_method = 'remove';
}
elsif ( $http_method eq 'GET' ) {
- $rpc_method = defined $fval ? 'view_related' : 'list_related';
+ if ( $fval eq 'list' ) {
+ $rpc_method = 'list_related';
+ $dispatch_method = 'fetch_related';
+ }
+ else {
+ $c->res->status(400);
+ $c->res->body("Bad HTTP request for method $http_method");
+ return;
+ }
}
else {
@@ -231,7 +237,7 @@
$c->res->body("Bad HTTP request for method $http_method");
return;
}
-
+ $self->$dispatch_method( $c, $rel_name, $fval );
$self->_call_rpc_method_as_action( $c, $rpc_method, $oid );
}
@@ -362,6 +368,22 @@
sub add { shift->next::method(@_) }
+=head2 view_related( I<context> )
+
+Overrides base method to disable chaining.
+
+=cut
+
+sub view_related { shift->next::method(@_) }
+
+=head2 list_related( I<context> )
+
+Overrides base method to disable chaining.
+
+=cut
+
+sub list_related { shift->next::method(@_) }
+
=head2 delete( I<context> )
Overrides base method to disable chaining.
More information about the Catalyst-commits
mailing list