[Catalyst] Sub-classing Application

Bill Moseley moseley at hank.org
Wed Dec 16 17:27:32 GMT 2009


On Wed, Dec 16, 2009 at 8:31 AM, J. Shirley <jshirley at gmail.com> wrote:

>
>
> The documentation seems quite sparse, but if you look at the source it
> just essentially does:
>    my $locator =3D Module::Pluggable::Object->new(
>        search_path =3D> [ map { s/^(?=3D::)/$class/; $_; } @paths ],
>        %$config
>    );
>
> If you have MyApp->config->{search_extra} =3D [ 'Foo::Controller',
> 'Foo::Model' ]; it should DTRT.
>

It almost works, but it sets up actions for both controllers using each
controller's class.

That is, if I start application Bar and pass in search_extra =3D> [qw/
Foo::Controller / ] then indeed actions from Foo::Controller::* will get
added to the application.

But, they are added with the Foo:: namespace.  that is, that controller is
not a parent-class of Bar::Controller::*.

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.

(That sentense make sense?)

I guess that means when Foo::Controller::Whatever is found, register the
actions in the Bar::Whatever namespace and push Foo::Whatever onto
@Bar::Whatever::ISA.


The problem I'm looking at is rebranding applications.  In the past I've
managed to modify config based on, say, domain name and use a different root
(for templates, css, images, etc.)  But, over time the application has to be
forked due to changes in code.  But, 90% of the controller code is still the
same between the two applications.

So, it would be handy to say, this application inheits from Foo, but these
with a few methods added or overridden.





-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091216/be1cf=
7f0/attachment.htm


More information about the Catalyst mailing list