From: Tomas Doran Date: Mon, 17 Aug 2009 23:14:38 +0000 (+0000) Subject: Switch to catalyst_component_name X-Git-Tag: 5.80008~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8f6cebb2303a0b0eda9422430f926c3f83c72aed Switch to catalyst_component_name --- diff --git a/Changes b/Changes index f253221..d70f917 100644 --- a/Changes +++ b/Changes @@ -34,7 +34,7 @@ expand_component_module (rjbs) - Allow Components to return anon classed from their COMPONENT method correctly, and have action registration work on Controllers returned - as such by adding a _component_name accessor for all components + as such by adding a catalyst_component_name accessor for all components which returns the component instance's name to be used when building actions etc. - Adding X-Forwarded-Port to allow the frontend proxy to dictate the diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 8dfc175..e30d38e 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2154,10 +2154,10 @@ sub setup_components { my @comps = sort { length $a <=> length $b } $class->locate_components($config); - my $deprecated_component_names = grep { /::[CMV]::/ } @comps; + my $deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @comps; $class->log->warn(qq{Your application is using the deprecated ::[MVC]:: type naming scheme.\n}. qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n} - ) if $deprecated_component_names; + ) if $deprecatedcatalyst_component_names; for my $component ( @comps ) { @@ -2251,10 +2251,10 @@ sub setup_component { my $suffix = Catalyst::Utils::class2classsuffix( $component ); my $config = $class->config->{ $suffix } || {}; - # Stash _component_name in the config here, so that custom COMPONENT + # Stash catalyst_component_name in the config here, so that custom COMPONENT # methods also pass it. local to avoid pointlessly shitting in config # for the debug screen, as $component is already the key name. - local $config->{_component_name} = $component; + local $config->{catalyst_component_name} = $component; my $instance = eval { $component->COMPONENT( $class, $config ); }; diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index af65452..87b37fd 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -104,7 +104,7 @@ and so on. This determines how the action is dispatched to. =head2 class Returns the name of the component where this action is defined. -Derived by calling the L +Derived by calling the L method on each component. =head2 code diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 6367a7d..870418c 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -60,15 +60,15 @@ component loader with config() support and a process() method placeholder. __PACKAGE__->mk_classdata('_plugins'); __PACKAGE__->mk_classdata('_config'); -has _component_name => ( is => 'ro' ); # Cannot be required => 1 as context +has catalyst_component_name => ( is => 'ro' ); # Cannot be required => 1 as context # class @ISA component - HATE # Make accessor callable as a class method, as we need to call setup_actions # on the application class, which we don't have an instance of, ewwwww # Also, naughty modules like Catalyst::View::JSON try to write to _everything_, # so spit a warning, ignore that (and try to do the right thing anyway) here.. -around _component_name => sub { +around catalyst_component_name => sub { my ($orig, $self) = (shift, shift); - Carp::cluck("Tried to write to the _component_name accessor - is your component broken or just mad? (Write ignored - using default value.)") if scalar @_; + Carp::cluck("Tried to write to the catalyst_component_name accessor - is your component broken or just mad? (Write ignored - using default value.)") if scalar @_; blessed($self) ? $self->$orig() || blessed($self) : $self; }; diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 3c313c7..972b6a3 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -158,7 +158,7 @@ around action_namespace => sub { } } - my $namespace = Catalyst::Utils::class2prefix($self->_component_name, $case_s) || ''; + my $namespace = Catalyst::Utils::class2prefix($self->catalyst_component_name, $case_s) || ''; $self->$orig($namespace) if ref($self); return $namespace; }; @@ -209,7 +209,7 @@ sub register_actions { sub register_action_methods { my ( $self, $c, @methods ) = @_; - my $class = $self->_component_name; + my $class = $self->catalyst_component_name; #this is still not correct for some reason. my $namespace = $self->action_namespace($c); diff --git a/t/aggregate/live_component_controller_anon.t b/t/aggregate/live_component_controller_anon.t index 73d3f9c..d7a9a2c 100644 --- a/t/aggregate/live_component_controller_anon.t +++ b/t/aggregate/live_component_controller_anon.t @@ -11,13 +11,13 @@ use Catalyst::Test 'TestApp'; my $response = request('http://localhost/anon/test'); ok($response->is_success); is($response->header('X-Component-Name-Action'), - 'TestApp::Controller::Anon', 'Action can see correct _component_name'); + 'TestApp::Controller::Anon', 'Action can see correct catalyst_component_name'); isnt($response->header('X-Component-Instance-Name-Action'), - 'TestApp::Controller::Anon', 'ref($controller) ne _component_name'); + 'TestApp::Controller::Anon', 'ref($controller) ne catalyst_component_name'); is($response->header('X-Component-Name-Controller'), - 'TestApp::Controller::Anon', 'Controller can see correct _component_name'); + 'TestApp::Controller::Anon', 'Controller can see correct catalyst_component_name'); is($response->header('X-Class-In-Action'), - 'TestApp::Controller::Anon', '$action->class is _component_name'); + 'TestApp::Controller::Anon', '$action->class is catalyst_component_name'); is($response->header('X-Anon-Trait-Applied'), '1', 'Anon controller class has trait applied correctly'); } diff --git a/t/lib/TestApp/Action/TestMyAction.pm b/t/lib/TestApp/Action/TestMyAction.pm index 77e2caa..1240b0e 100644 --- a/t/lib/TestApp/Action/TestMyAction.pm +++ b/t/lib/TestApp/Action/TestMyAction.pm @@ -9,7 +9,7 @@ sub execute { my $self = shift; my ( $controller, $c, $test ) = @_; $c->res->header( 'X-TestAppActionTestMyAction', 'MyAction works' ); - $c->res->header( 'X-Component-Name-Action', $controller->_component_name); + $c->res->header( 'X-Component-Name-Action', $controller->catalyst_component_name); $c->res->header( 'X-Component-Instance-Name-Action', ref($controller)); $c->res->header( 'X-Class-In-Action', $self->class); $self->next::method(@_); diff --git a/t/lib/TestApp/Controller/Anon.pm b/t/lib/TestApp/Controller/Anon.pm index 9832715..68b4fd6 100644 --- a/t/lib/TestApp/Controller/Anon.pm +++ b/t/lib/TestApp/Controller/Anon.pm @@ -32,7 +32,7 @@ sub COMPONENT { # Don't do this yourself, use CatalystX::Component::Traits! sub test : Local ActionClass('+TestApp::Action::TestMyAction') { my ($self, $c) = @_; - $c->res->header('X-Component-Name-Controller', $self->_component_name); + $c->res->header('X-Component-Name-Controller', $self->catalyst_component_name); $c->res->body('It works'); }