[Catalyst] Reuse of controllers
romkey at apocalypse.org
Mon Sep 20 02:33:46 GMT 2010
On Sep 19, 2010, at 10:02 PM, Pavel A. Karoukin wrote:
> I started to play more often with Catalyst framework and found that I often need to re-use some controllers logic. What the best DRY way to deal, for example, with Login/Register/Forgotpassword controllers?
> I mean I created one controller for one app. For another app I am doing I need to recreate everything, which ends up in plain copy/pasting and changing class names. I do not like this, this doesn't feel DRY. Is there some better way? Something plugable and unplugable with their own models/controller/view may be?
One approach is to simply inherit from the controller you want to reuse. So, package up the controllers you want to reuse together, then use Moose to extend them in the controller modules in each app that uses them. That allows you quite a bit of flexibility; use a common convention for the start of the dispatch chain (for instance, 'base') for each controller and then your subclass can map its parent controller to whatever path is best for each app.
- john romkey
More information about the Catalyst