catalyst iconperl icon

Catalyst - Root controller

Posted in , Thu, 01 Jun 2006 15:52:00 GMT

Catalyst 5.66 introduced the Root controller (e.g. MyApp::Controller::Root) as a best practice. It's purpose is to remove the need for the Application Class (a.k.a. App Class; e.g. to have actions or be a controller. Previously, Local top-level actions (e.g. /login) would be put in the App Class; the Root controller replaces this because it's base path is /. I asked mst why the Root controller is important and he told me the following.

Having the Application Class be a controller makes it a controller on a class-based level that can lead to several problems. One problem is name collision between App Class actions and $c methods, for example an App Class login action will cause problems with $c->login used by Catalyst::Plugin::Authentication. This and other problems can now be avoided entirely.

A typical App Class includes:

use Catalyst qw/.../;

This makes the App Class isa Catalyst::Controller because "use Catalyst" automatically injects Catalyst and Catalyst::Controller as base classes if the calling class isn't isa Catalyst. This can be avoided by making the App Class isa Catalyst before calling "use Catalyst" with the following:

use base qw/Catalyst/;
use Catalyst qw/.../;

Once the App Class is no longer isa Catalyst::Controller, it should no longer have any actions or subroutines with attributes, including the auto, default and end subroutines.

The Catalyst helper script will create a MyApp::Controller::Root controller for you, but the name can actually be anything. There's only one line that distinguishes the Root controller from any other one and it's a config setting that sets the name space to ''. You can make any controller the root by simply add the following line, just be sure the action attributes are updated if necessary:

__PACKAGE__->config->{namespace} = '';

Previously, you could avoid actions in the App Class by using Global actions, now you can with Local actions as well. - Root controller digg:Catalyst - Root controller reddit:Catalyst - Root controller spurl:Catalyst - Root controller wists:Catalyst - Root controller simpy:Catalyst - Root controller newsvine:Catalyst - Root controller blinklist:Catalyst - Root controller furl:Catalyst - Root controller fark:Catalyst - Root controller blogmarks:Catalyst - Root controller Y!:Catalyst - Root controller smarking:Catalyst - Root controller magnolia:Catalyst - Root controller segnalo:Catalyst - Root controller

no comments


(leave url/email »)

   Comment Markup Help Preview comment