[Catalyst] KISS - Base Subroutines.

Andrew catalystgroup at unitedgames.co.uk
Fri Jul 15 13:10:08 GMT 2016


I'd have to look into how to do that, John.

Right now, I've got something working, so I'll continue to build on that.

One problem I have come across with my approach of a CommonUse folder, and .pm files within it,
is when one of the .pm files needs to be used by another.

I thought I could merely have the first file, extending Catalyst::Controller....

BEGIN { extends 'Catalyst::Controller' }

....and the second file, extending the first file:

BEGIN { extends 'MyApp::CommonUse::FileOne' }

...and then the controller that needs to use FileTwo, extending that...

BEGIN { extends 'MyApp::CommonUse::FileTwo' }

Unfortunately, when FileTwo tries to call a subroutine in FileOne, I get:
"Undefined subroutine &MyApp::CommonUse::FileTwo::subroutinename"
If I stop worrying about the BEGIN/extends block, and instead just type: MyApp::CommonUse::FileOne::subroutinename(); it executes fine. 

In short:
I've a base controller directory called CommonUse.
There are two files in it.
How can FileTwo use subroutines in FileOne, without typing the explicit package path each time?

Many thanks,

Yours,
Andrew.




  ----- Original Message ----- 
  From: John Napiorkowski 
  To: The elegant MVC web framework 
  Sent: Friday, July 15, 2016 1:57 AM
  Subject: Re: [Catalyst] KISS - Base Subroutines.


  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 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/






------------------------------------------------------------------------------


  _______________________________________________
  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/f0306bff/attachment.htm>


More information about the Catalyst mailing list