->controller changes
André Walker [Mon, 11 Jul 2011 16:05:31 +0000 (13:05 -0300)]
lib/Catalyst.pm

index 46d0e8b..e071663 100644 (file)
@@ -558,10 +558,18 @@ If you want to search for controllers, pass in a regexp as the argument.
 sub controller {
     my ( $c, $name, @args ) = @_;
 
-    return $c->container->get_component_from_sub_container( 'controller', $name, $c, @args)
-        if( $name );
+# FIXME: should this be a Catalyst::Utils method?
+    if (!$name) {
+        my $class  = $c->action->class;
+
+        my $prefix = length Catalyst::Utils::class2classprefix($class);
+
+        # MyApp::Controller::Foo becomes Foo
+        # the + 2 is because of the ::
+        $name = substr $class, $prefix + 2;
+    }
 
-    return $c->component( $c->action->class );
+    return $c->container->get_component_from_sub_container( 'controller', $name, $c, @args);
 }
 
 =head2 $c->model($name)