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? 

Yes it HelperUtils is a .pm file 
you can call it whatever you like
in the example I gave the file will be in you Catalyst application's(e.g 
MyApp) lib folder 
  MyApp\lib\Role\HelpUtils.pm  (so yes you will need to create the Role 
folder)
Note that this is just an example. If you decide to name you package 
The::Good::Helper
then the file will be MyApp\lib\The\Good\Helper.pm
hope that helps



Thanks

Tony B. Okusanya
 



From:   "Andrew" <[email protected]>
To:     "The elegant MVC web framework" <[email protected]>, 
Date:   07/15/2016 08:00 AM
Subject:        Re: [Catalyst] KISS - Base Subroutines.



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: [email protected] 
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" <[email protected]> 
To:        "The elegant MVC web framework" <[email protected]>, 
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" <[email protected]>
To: "The elegant MVC web framework" <[email protected]>
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: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/[email protected]/
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: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/[email protected]/
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: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to