[Catalyst] Explicit Subroutin Call

Brandon Black blblack at gmail.com
Thu Jan 19 18:14:07 CET 2006


On 1/19/06, Davood Firoozian <davood at sibiran.com> wrote:
> Hi,
>
> I have a controller module called reseller in my application, is this
> true to call getReseller sub from another Controller module and if yes how ?
>
>
> Controller/reseller.pm
> ----------------------------------------------
> package panel::Controller::reseller;
> use strict;
> use warnings;
> use base 'Catalyst::Controller';
> sub getResellers : Private {
>     my $owner = $_;
>
>     return $owner;
> }
> 1

I don't suspect that you want to do that in that way.  getResellers
sounds like something that probably belongs in a Model class
somewhere.

But assuming it's Controller-level code that needs to be shared
between more than one Controller, if the functionality doesn't depend
on $c context, you could simply put it in a seperate library
MyApp::ResellerUtils that isn't Catalyst-aware, and use that library
from the controllers.  If it does need $c to figure things out, then
it could be an application-specific Catalyst::Plugin::.

On the other hand, if what you really want is for one Controller
method to call a public, html-generating method in another controller
and use its output in a larger context of its own, you could try
Catalyst::Plugin::SubRequest.

-- Brandon



More information about the Catalyst mailing list