[Catalyst] Sub-classing Application

Tomas Doran bobtfish at bobtfish.net
Wed Dec 16 20:32:13 GMT 2009


On 16 Dec 2009, at 17:27, Bill Moseley wrote:
> It also means I can't easly overide.  If I have hello() in both thes  
> controllers:
>
> Foo::Controller::Whatever::hello()
> Bar::Controller::Whatever::hello()
>
> I then get:
>
> [debug] Loaded Path actions:
> .------------------------------------- 
> +--------------------------------------.
> | Path                                |  
> Private                              |
> +------------------------------------- 
> +--------------------------------------+
> | /                                   | / 
> index                               |
> | /                                   | / 
> index                               |
> | /                                   | / 
> default                             |
> | /                                   | / 
> default                             |
> | /whatever/hello                     | /whatever/ 
> hello                      |
> | /whatever/hello                     | /whatever/ 
> hello                      |
> | /whatever/howdy                     | /whatever/ 
> howdy                      |
> '------------------------------------- 
> +--------------------------------------'
>
> So, I guess what I really would like is a way to have it load the  
> Foo::* modules but register their actions in the associated Bar::  
> namespace
> so that /whatever/hello calls Bar::Whatever::hello but Foo::Whatever  
> is the parent class if hello() doesn't exist in Bar.

Hmmm.

Sooo, what happens is that Catalyst::Component calls the COMPONENT  
method on each component, passing it a 'catalyst_component_name'  
parameter as config.

So in your case, Foo::Controller::Whatever->COMPONENT($app,  
{ catalyst_component_name => 'Foo::Controller::Whatever' } );

should be called.

What should happen is that the component is then registered in the  
component registry with the name found by calling the - 
 >catalyst_component_name accessor on the generated instance.. This  
unfortunately isn't how it works.. :(

As if that worked, then you could return 'Bar::Controller::Whatever',  
and the component system should register the first thing with each  
name...

Ergo, you'd load all the 'real' Bar::Controller::* modules in your  
app, and then load all the Foo::Controller::(.*) modules from the  
alternate namespace, registering them as Bar::Controller::$1 (but not  
doing so if Bar::Controller::$1 already exists).

Tests for this working would be the most arduous part of this  
development. If anyone would like to contribute them, then I'd be  
happy to work on the core changes to make what you want to do  
trivially possible.

Cheers
t0m




More information about the Catalyst mailing list