[Catalyst-commits] r8154 -
Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC
lukes at dev.catalyst.perl.org
lukes at dev.catalyst.perl.org
Wed Jul 23 18:52:56 BST 2008
Author: lukes
Date: 2008-07-23 18:52:56 +0100 (Wed, 23 Jul 2008)
New Revision: 8154
Modified:
Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
Log:
minor formatting change to jay's patch and docs for stash config support
Modified: Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm 2008-07-23 17:42:08 UTC (rev 8153)
+++ Catalyst-Controller-DBIC-API/1.000/trunk/lib/Catalyst/Controller/DBIC/API.pm 2008-07-23 17:52:56 UTC (rev 8154)
@@ -50,6 +50,25 @@
Each of your controller classes needs to be configured to point at the relevant schema class, specify what can be updated and so on, as shown in the L</SYNOPSIS>.
+The class, create_requires, create_allows and update_requires parameters can also be set in the stash like so:
+
+ sub setup :Chained('/api/rpc/rpc_base') :CaptureArgs(1) :PathPart('any') {
+ my ($self, $c, $object_type) = @_;
+
+ if ($object_type eq 'artist') {
+ $c->stash->{class} = 'MyAppDB::Artist';
+ $c->stash->{create_requires} = [qw/name/];
+ $c->stash->{update_allows} = [qw/name/];
+ } else {
+ $self->push_error($c, { message => "invalid object_type" });
+ return;
+ }
+
+ $self->NEXT::setup($c);
+ }
+
+Generally it's better to have one controller for each DBIC source with the config hardcoded, but in some cases this isn't possible.
+
=head2 class
Whatever you would pass to $c->model to get a resultset for this class. MyAppDB::Track for example.
@@ -97,17 +116,16 @@
search is handed off to DBIC, so you can process the incoming request
parameters, or add your own filters. Below is an example of basic usage:
- __PACKAGE__->config(
- ...,
- setup_list_method => 'filter_search_params'
- );
+ __PACKAGE__->config(
+ ...,
+ setup_list_method => 'filter_search_params'
+ );
- sub filter_search_params : Private {
- my ( $self, $c, $query ) = @_;
- $query->{search}->{'user_id'} = $c->user->id;
- }
+ sub filter_search_params : Private {
+ my ( $self, $c, $query ) = @_;
+ $query->{search}->{'user_id'} = $c->user->id;
+ }
-
=head1 METHODS
Note: see the individual interface classes - L<Catalyst::Controller::DBIC::API::RPC> and L<Catalyst::Controller::DBIC::API::REST> - for details of the endpoints to these abstract methods.
More information about the Catalyst-commits
mailing list