[Catalyst] KISS - Base Subroutines.

John Napiorkowski jjn1056 at yahoo.com
Fri Jul 15 00:57:32 GMT 2016


I'd consider a Role or maybe a Util package with 'Exporter' depending on what the shared function is intended to do -jnap 

    On Thursday, July 14, 2016 6:47 PM, "anthony.okusanya at usbank.com" <anthony.okusanya at usbank.com> wrote:
 

 Put a subroutine in a separate place, where it can beaccessed / called, by
whatever controllers need to use it?
-------------------------------------------------------------------------------------
Why not put all your subroutines ina Role  and consume the role in your main application class.

Package Role::HelpUtils;
use Moose::Role;

sub redirect_to_action {
        my ($c,$controller, $action, @params) =@_;
        $c->response->redirect($c->uri_for($c->controller($controller)->action_for($action), at params));
        $c->detach;
}

1;

In your main app class, simply use therole
package MyApp;
use Moose; 
use Catalyst::Runtime ;
with 'Role::HelpUtils';

You can then access the subroutinesusing  e.g $c->redirect_to_action()



Thanks

Tony B. Okusanya



From:       "Andrew"<catalystgroup at unitedgames.co.uk>
To:       "The elegant MVCweb framework" <catalyst at lists.scsys.co.uk>, 
Date:       07/14/2016 05:59 PM
Subject:       Re: [Catalyst]KISS - Base Subroutines.



Okay, no worries, I've done it now.

Created a folder called CommonUse to exist alongside Controller, View,and
Model folders, and hold perl modules that are commonly used, =).

Create a file in the folder.

Put my subroutine in the file.

Then in the controller I want to find the subroutine, where it normally
says:
BEGIN { extends 'Catalyst::Controller' }
...I switch it to say:
BEGIN { extends 'MyApp::CommonUse::File' }
....where MyApp is the name of my app, and File is the name of the perl
module file I created in the CommonUse folder.
Then that controller can call the subroutine, and everything seems to work,
=).

I read online, you could also put subrountines inside of Myapp.pm withinthe
lib folder, and all controllers could access it. I did try that, however,I
couldn't get it working, so any pointers on that appreciated.

Yours,
Andrew.



----- Original Message -----
From: "Andrew" <catalystgroup at unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst at lists.scsys.co.uk>
Sent: Thursday, July 14, 2016 9:20 PM
Subject: [Catalyst] KISS - Base Subroutines.


Is there a keep it simple stupid answer to the following question:

Put a subroutine in a separate place, where it can be accessed / called,by
whatever controllers need to use it?






_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/



U.S. BANCORP made the following annotations
---------------------------------------------------------------------
Electronic Privacy Notice. This e-mail, and any attachments, contains information that is, or may be, covered by electronic communications privacy laws, and is also confidential and proprietary in nature. If you are not the intended recipient, please be advised that you are legally prohibited from retaining, using, copying, distributing, or otherwise disclosing this information in any manner. Instead, please reply to the sender that you have received this communication in error, and then immediately delete it. Thank you in advance for your cooperation.

---------------------------------------------------------------------
_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/catalyst/attachments/20160715/46766a50/attachment.htm>


More information about the Catalyst mailing list