Much cleaner. The visit class test wasn't actually testing visiting the class, so...
Tomas Doran [Sat, 21 Mar 2009 18:04:06 +0000 (18:04 +0000)]
lib/Catalyst/Dispatcher.pm
t/aggregate/live_component_controller_action_visit.t
t/lib/TestApp/Controller/Action/Visit.pm

index 840342b..68fe551 100644 (file)
@@ -190,7 +190,7 @@ sub _do_visit {
     }
     elsif (!defined $action->namespace) {
         $error .= qq/Action has no namespace: cannot $opname() to a plain /
-                 .qq/method or component, must be a :Action or some sort./
+                 .qq/method or component, must be an :Action of some sort./
     }
     elsif (!$action->class->can('_DISPATCH')) {
         $error .= qq/Action cannot _DISPATCH. /
@@ -320,14 +320,8 @@ sub _invoke_as_component {
 
     my $class = $self->_find_component_class( $c, $component ) || return 0;
 
-    ### XXX FIXME - Horrible hack to get proper action objects for
-    ###             controller paths..
-    if ($class =~ /::C(ontroller)?::/) {
-        my $possible_path = $class . '/' . $method;
-        $possible_path =~ s/.+::C(ontroller)?:://;
-        $possible_path =~ s|::|/|g;
-        $possible_path =~ tr/A-Z/a-z/;
-        my $possible_action = $self->_invoke_as_path( $c, '/' . $possible_path );
+    if (my $code = $component_instance->can('action_for')) {
+        my $possible_action = $component_instance->$code($method);
         return $possible_action if $possible_action;
     }
 
index febf935..468496b 100644 (file)
@@ -253,7 +253,7 @@ sub run_tests {
         );
         ok( !$response->is_success, 'Response Fails' );
         is( $response->content,
-            q{FATAL ERROR: Couldn't visit("TestApp"): Action has no namespace: cannot visit() to a plain method or component, must be a :Action or some sort.},
+            q{FATAL ERROR: Couldn't visit("TestApp"): Action has no namespace: cannot visit() to a plain method or component, must be an :Action of some sort.},
             "Cannot visit app namespace"
         );
     }
index 9f8f9a5..0ddaacb 100644 (file)
@@ -98,7 +98,7 @@ sub embed : Local {
 
 sub class_visit_test_action : Local {
     my ( $self, $c ) = @_;
-    $c->visit(qw/TestApp class_visit_test_method/);
+    $c->visit(qw/TestApp/);
 }
 
 1;