From: Moritz Onken Date: Sun, 7 Jun 2009 12:28:53 +0000 (+0000) Subject: Added support for ~ prefix to plugins and action classes X-Git-Tag: 5.80006~36^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5d8129e9b7bea385dd6fda9b490e7923f61eedd0 Added support for ~ prefix to plugins and action classes --- diff --git a/Changes b/Changes index 73321fe..969f9fb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ # This file documents the revision history for Perl extension Catalyst. + - Use ~ as prefix for plugins or action classes which are located in MyApp::Plugin / MyApp::Action + + 5.80005 2009-06-06 14:40:00 Behaviour changes: diff --git a/TODO b/TODO index fcade74..6e237a1 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ TODO for brach namespace_handling_refactor: -- refactor code in +- refactor code in * Catalyst::Dispatcher::get_containers # No Idea * Catalyst::Dispatcher::dispatch_type # DONE diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 426cbb3..877c53c 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2502,8 +2502,8 @@ the plugin name does not begin with C. $class->_plugins( {} ) unless $class->_plugins; $plugins ||= []; - - my @plugins = Catalyst::Utils::resolve_namespace('Catalyst::Plugin', @$plugins); + + my @plugins = Catalyst::Utils::resolve_namespace($class . '::Plugin', 'Catalyst::Plugin', @$plugins); for my $plugin ( reverse @plugins ) { Class::MOP::load_class($plugin); diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 6924405..68e8b42 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -390,7 +390,8 @@ sub _parse_PathPrefix_attr { sub _parse_ActionClass_attr { my ( $self, $c, $name, $value ) = @_; - $value = Catalyst::Utils::resolve_namespace($self->_action_class, $value); + my $appname = $self->_application; + $value = Catalyst::Utils::resolve_namespace($appname . '::Action', $self->_action_class, $value); return ( 'ActionClass', $value ); } diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 5df4526..99c46bc 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -640,10 +640,10 @@ sub _load_dispatch_types { my ( $self, @types ) = @_; my @loaded; - # Preload action types for my $type (@types) { - my $class = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $type); + # first param is undef because we cannot get the appclass + my $class = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $type); eval { Class::MOP::load_class($class) }; Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ ) @@ -666,8 +666,9 @@ of course it's being used.) sub dispatch_type { my ($self, $name) = @_; - - $name = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $name); + + # first param is undef because we cannot get the appclass + $name = Catalyst::Utils::resolve_namespace(undef, 'Catalyst::DispatchType', $name); for (@{ $self->_dispatch_types }) { return $_ if ref($_) eq $name; diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 76f0733..e791b4a 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -392,10 +392,11 @@ Method which adds the namespace for plugins and actions. sub resolve_namespace { + my $appnamespace = shift; my $namespace = shift; my @classes = @_; return String::RewritePrefix->rewrite( - { '' => $namespace.'::', '+' => '' }, @classes, + { '' => $namespace.'::', '+' => '', '~' => $appnamespace . '::' }, @classes, ); } diff --git a/t/aggregate/live_component_controller_action_action.t b/t/aggregate/live_component_controller_action_action.t index ea52e78..1e11b18 100644 --- a/t/aggregate/live_component_controller_action_action.t +++ b/t/aggregate/live_component_controller_action_action.t @@ -10,7 +10,7 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } -use Test::More tests => 28 * $iters; +use Test::More tests => 42 * $iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -106,5 +106,46 @@ sub run_tests { 'Content is a serialized Catalyst::Request' ); } + + { + ok( my $response = request('http://localhost/action_action_five'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action_action_five', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Action', + 'Test Class' + ); + is( $response->header('X-Action'), 'works' ); + like( + $response->content, + qr/^bless\( .* 'Catalyst::Request' \)$/s, + 'Content is a serialized Catalyst::Request' + ); + } + + + { + ok( my $response = request('http://localhost/action_action_six'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action_action_six', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Action', + 'Test Class' + ); + is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' ); + like( + $response->content, + qr/^bless\( .* 'Catalyst::Request' \)$/s, + 'Content is a serialized Catalyst::Request' + ); + } } diff --git a/t/lib/TestApp/Controller/Action/Action.pm b/t/lib/TestApp/Controller/Action/Action.pm index 787bb8d..5049427 100644 --- a/t/lib/TestApp/Controller/Action/Action.pm +++ b/t/lib/TestApp/Controller/Action/Action.pm @@ -3,6 +3,8 @@ package TestApp::Controller::Action::Action; use strict; use base 'TestApp::Controller::Action'; +__PACKAGE__->config( actions => { action_action_five => { ActionClass => '+Catalyst::Action::TestBefore' } } ); + sub action_action_one : Global : ActionClass('TestBefore') { my ( $self, $c ) = @_; $c->res->header( 'X-Action', $c->stash->{test} ); @@ -25,4 +27,15 @@ sub action_action_four : Global : MyAction('TestMyAction') { $c->forward('TestApp::View::Dump::Request'); } +sub action_action_five : Global { + my ( $self, $c ) = @_; + $c->res->header( 'X-Action', $c->stash->{test} ); + $c->forward('TestApp::View::Dump::Request'); +} + +sub action_action_six : Global : ActionClass('~TestMyAction') { + my ( $self, $c ) = @_; + $c->forward('TestApp::View::Dump::Request'); +} + 1;