+ Fix forwarded REST methods, e.g. foo_GET to be more
+ correctly displayed as a forward in the stats info.
+
Tue 29 May 2012 20:19:00 BST - Release 1.01
Add Catalyst::Action::Deserialize::JSON::XS
my ($code, $name);
+ # Execute normal 'foo' action.
+ $c->execute( $self->class, $self, @{ $c->req->args } );
+
# Common case, for foo_GET etc
if ( $code = $controller->action_for($rest_method) ) {
- $c->execute( $self->class, $self, @{ $c->req->args } ); # Execute normal 'foo' action.
return $c->forward( $code, $c->req->args ); # Forward to foo_GET if it's an action
}
elsif ($code = $controller->can($rest_method)) {
- # Execute normal action
- $c->execute( $self->class, $self, @{ $c->req->args } );
$name = $rest_method; # Stash name and code to run 'foo_GET' like an action below.
}
# localise stuff so we can dispatch the action 'as normal, but get
# different stats shown, and different code run.
+ # Also get the full path for the action, and make it look like a forward
local $self->{code} = $code;
- local $self->{reverse} = $name;
+ my @name = split m{/}, $self->reverse;
+ $name[-1] = $name;
+ local $self->{reverse} = "-> " . join('/', @name);
$c->execute( $self->class, $self, @{ $c->req->args } );
}
use warnings;
use Test::More 0.88;
use FindBin;
-
+use Data::Dumper;
use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
use Test::Rest;
use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
-foreach my $method (qw(GET DELETE POST PUT OPTIONS)) {
- my $run_method = lc($method);
- my $res;
- if ( grep /$method/, qw(GET DELETE OPTIONS) ) {
- $res = request( $t->$run_method( url => '/actions/test' ) );
- } else {
- $res = request(
- $t->$run_method(
- url => '/actions/test',
- data => '',
- )
+foreach my $endpoint (qw/ test other_test /) {
+ foreach my $method (qw(GET DELETE POST PUT OPTIONS)) {
+ my $run_method = lc($method);
+ my $res;
+ if ( grep /$method/, qw(GET DELETE OPTIONS) ) {
+ $res = request( $t->$run_method( url => '/actions/' . $endpoint ) );
+ }
+ else {
+ $res = request(
+ $t->$run_method(
+ url => '/actions/' . $endpoint,
+ data => '',
+ )
+ );
+ }
+ ok( $res->is_success, "$method request succeeded" ) or warn Dumper($res);
+ is(
+ $res->content,
+ "$method",
+ "$method request had proper response"
+ );
+ is(
+ $res->header('X-Was-In-TopLevel'),
+ '1',
+ "went through top level action for dispatching to $method"
+ );
+ is(
+ $res->header('Using-Action'),
+ 'STATION',
+ "went through action for dispatching to $method"
);
}
- ok( $res->is_success, "$method request succeeded" );
- is(
- $res->content,
- "$method",
- "$method request had proper response"
- );
- is(
- $res->header('X-Was-In-TopLevel'),
- '1',
- "went through top level action for dispatching to $method"
- );
- is(
- $res->header('Using-Action'),
- 'STATION',
- "went through action for dispatching to $method"
- );
}
my $res = request(
$c->res->body('OPTIONS');
}
+sub other_test :Local :ActionClass('+Catalyst::Action::REST') {
+ my ( $self, $c ) = @_;
+ $c->res->header('X-Was-In-TopLevel', 1);
+}
+
+sub other_test_GET {
+ my ( $self, $c ) = @_;
+ $c->res->body('GET');
+}
+
+sub other_test_POST {
+ my ( $self, $c ) = @_;
+ $c->res->body('POST');
+}
+
+sub other_test_PUT :ActionClass('+Test::Action::Class::Sub') {
+ my ( $self, $c ) = @_;
+ $c->res->body('PUT');
+}
+
+sub other_test_DELETE {
+ my ( $self, $c ) = @_;
+ $c->res->body('DELETE');
+}
+
+sub other_test_OPTIONS {
+ my ( $self, $c ) = @_;
+
+ $c->res->body('OPTIONS');
+}
+
sub end : Private {} # Don't need serialization..
1;