<div class="gmail_quote">On Mon, Sep 20, 2010 at 1:46 AM, David Schmidt <span dir="ltr">&lt;<a href="mailto:davewood@gmx.at">davewood@gmx.at</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5">On Mon, Sep 20, 2010 at 4:33 AM, John Romkey &lt;<a href="mailto:romkey@apocalypse.org">romkey@apocalypse.org</a>&gt; wrote:<br>
&gt; On Sep 19, 2010, at 10:02 PM, Pavel A. Karoukin wrote:<br>
&gt;&gt; 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?<br>
&gt;&gt;<br>
&gt;&gt; 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&#39;t feel DRY. Is there some better way? Something plugable and unplugable with their own models/controller/view may be?<br>


&gt;<br>
&gt; 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, &#39;base&#39;) for each controller and then your subclass can map its parent controller to whatever path is best for each app.<br>


&gt;        - john romkey<br>
&gt;        <a href="http://www.romkey.com/" target="_blank">http://www.romkey.com/</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
&gt; Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
&gt; Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" target="_blank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
&gt; Dev site: <a href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br>
&gt;<br>
<br>
</div></div>Another nice approach to reuse Controller Logic is to use Moose Roles.<br>
<br>
I got the basics from t0ms blog<br>
(<a href="http://bobtfish.livejournal.com/#post-bobtfish-264317" target="_blank">http://bobtfish.livejournal.com/#post-bobtfish-264317</a>)<br>
An example how i use it can be found here<br>
<a href="http://wiki.catalystframework.org/wiki/wikicookbook/controllerwithfileupload" target="_blank">http://wiki.catalystframework.org/wiki/wikicookbook/controllerwithfileupload</a><br>
(the interesting part is in the file Resource.pm in the attachment<br>
<a href="http://wiki.catalystframework.org/wiki/wikicookbook/ControllerWithFileUpload.attachment/100" target="_blank">http://wiki.catalystframework.org/wiki/wikicookbook/ControllerWithFileUpload.attachment/100</a>)<br>
<br>
<br>
*************<br>
package CatalystX::TraitFor::Controller::Resource;<br>
use MooseX::MethodAttributes::Role;<br>
use namespace::autoclean;<br>
<br>
sub base : Chained(&#39;&#39;) PathPart(&#39;&#39;) CaptureArgs(0) {<br>
    my ($self, $c ) = @_;<br>
    ...<br>
};<br>
<br>
sub index :Chained(&#39;base&#39;) :PathPart(&#39;&#39;) :Args(0) {<br>
    my ($self, $c ) = @_;<br>
    ...<br>
}<br>
1;<br>
*************<br>
<font color="#888888"><br>
<br><br></font></blockquote><div><br></div><div>Thank you David. This looks very close to what I had in head. I will look more in to it!</div><div><br></div><div>Regards,</div><div>Pavel </div></div>