From: Matt S Trout Date: Sat, 3 Jun 2006 01:32:01 +0000 (+0000) Subject: improved docs for action_namespace and path_prefix and made path configurable X-Git-Tag: 5.7099_04~548 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1b1636b58ce5f1feabd0d125c3928c57e5a5cf3c improved docs for action_namespace and path_prefix and made path configurable --- diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index a90656c..cd14a4c 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -79,7 +79,9 @@ dispatch of actions for controllers. =head2 $self->action_namespace($c) -Determine the namespace for actions in this component. +Returns the private namespace for actions in this component. Defaults to a value +from the controller name (for e.g. MyApp::Controller::Foo::Bar becomes +"foo/bar") or can be overriden from the "namespace" config key. =cut @@ -94,11 +96,18 @@ sub action_namespace { =head2 $self->path_prefix($c) -alias for action_namespace +Returns the default path prefix for :Local, :LocalRegex and relative :Path +actions in this component. Defaults to the action_namespace or can be +overriden from the "path" config key. =cut -sub path_prefix { shift->action_namespace(@_); } +sub path_prefix { + my ( $self, $c ) = @_; + my $hash = (ref $self ? $self : $self->config); # hate app-is-class + return $hash->{path} if exists $hash->{path}; + return shift->action_namespace(@_); +} =head2 $self->register_actions($c) diff --git a/t/lib/TestApp/Controller/Action/Relative.pm b/t/lib/TestApp/Controller/Action/TestRelative.pm similarity index 72% rename from t/lib/TestApp/Controller/Action/Relative.pm rename to t/lib/TestApp/Controller/Action/TestRelative.pm index 84af0fc..951345e 100644 --- a/t/lib/TestApp/Controller/Action/Relative.pm +++ b/t/lib/TestApp/Controller/Action/TestRelative.pm @@ -1,8 +1,12 @@ -package TestApp::Controller::Action::Relative; +package TestApp::Controller::Action::TestRelative; use strict; use base 'TestApp::Controller::Action'; +__PACKAGE__->config( + path => 'action/relative' +); + sub relative : Local { my ( $self, $c ) = @_; $c->forward('/action/forward/one'); diff --git a/t/live_component_controller_action_forward.t b/t/live_component_controller_action_forward.t index 5b23653..c8e3286 100644 --- a/t/live_component_controller_action_forward.t +++ b/t/live_component_controller_action_forward.t @@ -148,8 +148,8 @@ sub run_tests { } { my @expected = qw[ - TestApp::Controller::Action::Relative->begin - TestApp::Controller::Action::Relative->relative + TestApp::Controller::Action::TestRelative->begin + TestApp::Controller::Action::TestRelative->relative TestApp::Controller::Action::Forward->one TestApp::Controller::Action::Forward->two TestApp::Controller::Action::Forward->three @@ -170,7 +170,7 @@ sub run_tests { 'action/relative/relative', 'Test Action' ); is( $response->header('X-Test-Class'), - 'TestApp::Controller::Action::Relative', + 'TestApp::Controller::Action::TestRelative', 'Test Class' ); is( $response->header('X-Catalyst-Executed'), @@ -183,8 +183,8 @@ sub run_tests { } { my @expected = qw[ - TestApp::Controller::Action::Relative->begin - TestApp::Controller::Action::Relative->relative_two + TestApp::Controller::Action::TestRelative->begin + TestApp::Controller::Action::TestRelative->relative_two TestApp::Controller::Action::Forward->one TestApp::Controller::Action::Forward->two TestApp::Controller::Action::Forward->three @@ -211,7 +211,7 @@ sub run_tests { ); is( $response->header('X-Test-Class'), - 'TestApp::Controller::Action::Relative', + 'TestApp::Controller::Action::TestRelative', 'Test Class' ); is( $response->header('X-Catalyst-Executed'),