[Catalyst] Sub-classing Application
J. Shirley
jshirley at gmail.com
Wed Dec 16 16:31:11 GMT 2009
On Wed, Dec 16, 2009 at 8:13 AM, Bill Moseley <moseley at hank.org> wrote:
> I have an existing application Foo. I'd like to create a new application
> Bar that has very similar actions.
>
> What I'm wondering is if there's a way where I could run catalyst.pl Bar to
> create a new empty application and then tell it to inherit from Foo. That
> is load_components would load all of Foo's Models, View, Controllers
> (basically creating in-memory empty sub-classes for each component) and
> setting up all actions as if they were in Bar. I could then override or add
> additinal actions as needed to Bar::Controller::Whatever, which would
> inherit from Foo::Controller::Whatever.
>
> Any ideas how to implement something like that?
>
You can configure the locate_components method (or, subclass it in
your application):
http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80016/lib/Catalyst.pm#$c->locate_components(_$setup_component_config_)
The documentation seems quite sparse, but if you look at the source it
just essentially does:
my $locator = Module::Pluggable::Object->new(
search_path => [ map { s/^(?=::)/$class/; $_; } @paths ],
%$config
);
If you have MyApp->config->{search_extra} = [ 'Foo::Controller',
'Foo::Model' ]; it should DTRT.
I think :)
-J
More information about the Catalyst
mailing list