Index: t/lib/TestApp/Action/TestMethodsAccessors.pm =================================================================== --- t/lib/TestApp/Action/TestMethodsAccessors.pm (revision 0) +++ t/lib/TestApp/Action/TestMethodsAccessors.pm (revision 0) @@ -0,0 +1,20 @@ +package TestApp::Action::TestMethodsAccessors; + +use strict; +use warnings; + +use base qw/Catalyst::Action/; + +__PACKAGE__->mk_accessors(qw/test_accessor flattened/); + +sub trivial +{ + my ( $self, @args ) = (shift, @_); + + my $flattened = join(':', @args||() ); + $self->flattened( $flattened ); + + return 1; +} + +1; Index: t/lib/TestApp/Controller/ActionMethodsAccessors.pm =================================================================== --- t/lib/TestApp/Controller/ActionMethodsAccessors.pm (revision 0) +++ t/lib/TestApp/Controller/ActionMethodsAccessors.pm (revision 0) @@ -0,0 +1,48 @@ +package TestApp::Controller::ActionMethodsAccessors; + +use strict; +use base 'Catalyst::Controller'; + +## This first action is a simple one. This is the control against which +## the behavior of ->action will be compared to one in a chain. + +sub action_zero :Local ActionClass('+TestApp::Action::TestMethodsAccessors') +{ + my ($self, $c) = @_; + + $c->response->body("Works"); +} + +sub action_one :Local ActionClass('+TestApp::Action::TestMethodsAccessors') +{ + my ($self, $c) = @_; + + my $first_test = $c->action->trivial(1,2,3); ## Should return 1 + my $second_test = $c->action->flattened(); #Should return "1:2:3:4" + + $c->action->test_accessor('Works'); + + my $third_test = $c->action->test_accessor(); #Should return 'works' + + $c->response->body("$first_test, $second_test, $third_test"); +} + +## These next two actions are part of a chain.PathPart('ActionMethodsAccessors') + +sub base :Chained('/') PathPart('actionmethodsaccessors') CaptureArgs(0) {} + +sub action_two :Chained('base') PathPart('action_two') Args(0) ActionClass('+TestApp::Action::TestMethodsAccessors') +{ + my ($self, $c) = @_; + + my $first_test = $c->action->trivial(1,2,3); ## Should return 1 + my $second_test = $c->action->flattened(); #Should return "1:2:3:4" + + $c->action->test_accessor('Works'); + + my $third_test = $c->action->test_accessor(); #Should return 'works' + + $c->response->body("$first_test, $second_test, $third_test"); +} + +1; Index: t/live_component_controller_action_actionclass.t =================================================================== --- t/live_component_controller_action_actionclass.t (revision 0) +++ t/live_component_controller_action_actionclass.t (revision 0) @@ -0,0 +1,44 @@ +## ============================================================================ +## Test to make sure that when you add a custom action class to an action that +## you can correctly access all it's accessors/methods from the controller. +## +## This test was created to illustrate how the $c->action object acts when it's +## part of a chained action and when it's not. +## ============================================================================ + +#!perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; + + +use Test::More tests => 9; +use Catalyst::Test 'TestApp'; + + +## Test the Sanity test first, to make sure we can access the URL with the actionclass + +{ + ok( my $response = request('http://localhost/actionmethodsaccessors/action_zero'), "Got Simple Response"); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, "Works", "Sanity Test Check Out"); +} + +## Test the Simple Actions Now + +{ + ok( my $response = request('http://localhost/actionmethodsaccessors/action_one'), "Got Simple Response"); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, "1, 3, Works", "Simple test is Okay"); +} + +## Test the Chaining Actions + +{ + ok( my $response = request('http://localhost/actionmethodsaccessors/action_two'), "Got Simple Response"); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, "1, 3, Works", "Chained test is Okay"); +} \ No newline at end of file