[Catalyst-commits] r12604 - in
Catalyst-Controller-DBIC-API/1.004/trunk: .
lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API
t/lib/RestTest/Controller/API/RPC
abraxxa at dev.catalyst.perl.org
abraxxa at dev.catalyst.perl.org
Mon Jan 11 14:53:12 GMT 2010
Author: abraxxa
Date: 2010-01-11 14:53:11 +0000 (Mon, 11 Jan 2010)
New Revision: 12604
Modified:
Catalyst-Controller-DBIC-API/1.004/trunk/Changes
Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API.pm
Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/REST.pm
Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/RPC.pm
Catalyst-Controller-DBIC-API/1.004/trunk/t/lib/RestTest/Controller/API/RPC/Any.pm
Log:
Use next instead of NEXT in RPC
Moved sub object from RPC/REST to Base to DRY
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/Changes 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/Changes 2010-01-11 14:53:11 UTC (rev 12604)
@@ -5,6 +5,10 @@
- CGI::Expand'ed search parameters are now also JSON decoded + test
- Fixed pod for parameters using a json string which shouldn't be surrounded
by single quotes
+- Use next instead of NEXT in RPC
+- Moved sub object from RPC/REST to Base to DRY
+ This will break your code if you subclass from REST
+ and had relied on the action name 'object'
1.004001
- Allow for more complex prefetch_allows (multiple keys in hash)
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2010-01-11 14:53:11 UTC (rev 12604)
@@ -42,6 +42,17 @@
$c->stash->{$self->rs_stash_key} = $self->stored_model;
}
+sub object :Chained('setup') :CaptureArgs(1) :PathPart('') {
+ my ($self, $c, $id) = @_;
+
+ my $object = $c->stash->{$self->rs_stash_key}->find( $id );
+ unless ($object) {
+ $self->push_error($c, { message => "Invalid id" });
+ $c->detach; # no point continuing
+ }
+ $c->stash->{$self->object_stash_key} = $object;
+}
+
# from Catalyst::Action::Serialize
sub deserialize :ActionClass('Deserialize') {
my ($self, $c) = @_;
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/REST.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/REST.pm 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/REST.pm 2010-01-11 14:53:11 UTC (rev 12604)
@@ -4,12 +4,13 @@
BEGIN { extends 'Catalyst::Controller::DBIC::API::Base'; }
__PACKAGE__->config(
- 'default' => 'application/json',
- 'stash_key' => 'response',
- 'map' => {
- 'application/x-www-form-urlencoded' => 'JSON',
- 'application/json' => 'JSON',
- });
+ 'default' => 'application/json',
+ 'stash_key' => 'response',
+ 'map' => {
+ 'application/x-www-form-urlencoded' => 'JSON',
+ 'application/json' => 'JSON',
+ });
+
=head1 NAME
Catalyst::Controller::DBIC::API::REST
@@ -73,30 +74,21 @@
=cut
-sub object :Chained('setup') :Args(1) :PathPart('') :ActionClass('REST') {
- my ($self, $c, $id) = @_;
+sub rest :Chained('object') :Args(0) :PathPart('') :ActionClass('REST') {}
- my $object = $self->stored_model->find( $id );
- unless ($object) {
- $self->push_error($c, { message => "Invalid id" });
- $c->detach; # no point continuing
- }
- $c->stash->{$self->object_stash_key} = $object;
-}
-
-sub object_POST {
+sub rest_POST {
my ($self, $c) = @_;
$c->forward('update');
}
-sub object_PUT {
+sub rest_PUT {
my ($self, $c) = @_;
$c->forward('update');
}
-sub object_DELETE {
+sub rest_DELETE {
my ($self, $c) = @_;
$c->forward('delete');
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/RPC.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/RPC.pm 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API/RPC.pm 2010-01-11 14:53:11 UTC (rev 12604)
@@ -4,12 +4,15 @@
BEGIN { extends 'Catalyst::Controller::DBIC::API::Base'; }
__PACKAGE__->config(
- 'default' => 'application/json',
- 'stash_key' => 'response',
- 'map' => {
- 'application/x-www-form-urlencoded' => 'JSON',
- 'application/json' => 'JSON',
- });
+ 'action' => { object => { PathPart => 'id' } },
+ 'default' => 'application/json',
+ 'stash_key' => 'response',
+ 'map' => {
+ 'application/x-www-form-urlencoded' => 'JSON',
+ 'application/json' => 'JSON',
+ },
+);
+
=head1 NAME
Catalyst::Controller::DBIC::API::RPC
@@ -84,18 +87,6 @@
=cut
-sub object :Chained('setup') :CaptureArgs(1) :PathPart('id') {
- my ($self, $c, $id) = @_;
-
- my $object = $c->stash->{$self->rs_stash_key}->find( $id );
- unless ($object) {
- $self->push_error($c, { message => "Invalid id" });
- $c->detach; # no point continuing
- }
-
- $c->stash->{$self->object_stash_key} = $object;
-}
-
sub index : Chained('setup') PathPart('') Args(0) {
my ( $self, $c ) = @_;
@@ -106,25 +97,25 @@
sub create :Chained('setup') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
- $self->NEXT::create($c);
+ $self->next::method($c);
}
sub list :Chained('setup') :PathPart('list') :Args(0) {
my ($self, $c) = @_;
- $self->NEXT::list($c);
+ $self->next::method($c);
}
sub update :Chained('object') :PathPart('update') :Args(0) {
my ($self, $c) = @_;
- $self->NEXT::update($c);
+ $self->next::method($c);
}
sub delete :Chained('object') :PathPart('delete') :Args(0) {
my ($self, $c) = @_;
- $self->NEXT::delete($c);
+ $self->next::method($c);
}
=head1 AUTHOR
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API.pm 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/lib/Catalyst/Controller/DBIC/API.pm 2010-01-11 14:53:11 UTC (rev 12604)
@@ -162,7 +162,7 @@
__PACKAGE__->config
( ...,
search_exposes => [qw/position title custom_column/],
- );
+ );
and then in your custom resultset:
@@ -267,6 +267,7 @@
=head2 object
This action is the chain root for all object level actions (such as delete and update). Takes one argument which is passed to L<DBIx::Class::ResultSet/find>, if an object is returned then it is set in $c->stash->{$self->object_stash_key}.
+The move of sub object in version 1.004002 from RPC/REST to Base will break your code if you subclass from REST and had relied on the 'object' action being an ActionClass('REST').
=head2 create
Modified: Catalyst-Controller-DBIC-API/1.004/trunk/t/lib/RestTest/Controller/API/RPC/Any.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.004/trunk/t/lib/RestTest/Controller/API/RPC/Any.pm 2010-01-11 13:39:28 UTC (rev 12603)
+++ Catalyst-Controller-DBIC-API/1.004/trunk/t/lib/RestTest/Controller/API/RPC/Any.pm 2010-01-11 14:53:11 UTC (rev 12604)
@@ -3,7 +3,6 @@
use strict;
use warnings;
use base qw/Catalyst::Controller::DBIC::API::RPC/;
-use JSON::Syck;
sub setup :Chained('/api/rpc/rpc_base') :CaptureArgs(1) :PathPart('any') {
my ($self, $c, $object_type) = @_;
@@ -21,7 +20,7 @@
return;
}
- $c->stash->{$self->rs_stash_key} = $c->model('RestTestDB::' . $config->{class});
+ $c->stash->{$self->rs_stash_key} = $c->model('RestTestDB')->resultset($config->{class});
$c->stash->{$_} = $config->{$_} for keys %{$config};
}
More information about the Catalyst-commits
mailing list