improved docs for action_namespace and path_prefix and made path configurable
Matt S Trout [Sat, 3 Jun 2006 01:32:01 +0000 (01:32 +0000)]
lib/Catalyst/Base.pm
t/lib/TestApp/Controller/Action/TestRelative.pm [moved from t/lib/TestApp/Controller/Action/Relative.pm with 72% similarity]
t/live_component_controller_action_forward.t

index a90656c..cd14a4c 100644 (file)
@@ -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)
 
@@ -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');
index 5b23653..c8e3286 100644 (file)
@@ -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'),