[Catalyst] KISS - Base Subroutines.
Andrew
catalystgroup at unitedgames.co.uk
Fri Jul 15 12:55:42 GMT 2016
Thanks for your suggestion, Tony, =).
In your example, is HelpUtils a .pm file?
And if so, where in the Catalyst folder structure would it be placed?
Would I need to create a folder called Role?
----- Original Message -----
From: anthony.okusanya at usbank.com
To: The elegant MVC web framework
Sent: Friday, July 15, 2016 12:46 AM
Subject: Re: [Catalyst] KISS - Base Subroutines.
Put a subroutine in a separate place, where it can be accessed / called, by
whatever controllers need to use it?
-------------------------------------------------------------------------------------
Why not put all your subroutines in a 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), @params));
$c->detach;
}
1;
In your main app class, simply use the role
package MyApp;
use Moose;
use Catalyst::Runtime ;
with 'Role::HelpUtils';
You can then access the subroutines using e.g $c->redirect_to_action()
Thanks
Tony B. Okusanya
From: "Andrew" <catalystgroup at unitedgames.co.uk>
To: "The elegant MVC web 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 within the
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/e34b42d5/attachment.htm>
More information about the Catalyst
mailing list