Mailing List Archive

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@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/
Re: KISS - Base Subroutines. [ In reply to ]
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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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/
Re: KISS - Base Subroutines. [ In reply to ]
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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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.

---------------------------------------------------------------------
Re: KISS - Base Subroutines. [ In reply to ]
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@usbank.com" <anthony.okusanya@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),@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@unitedgames.co.uk>
To:       "The elegant MVCweb framework" <catalyst@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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@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/
Re: KISS - Base Subroutines. [ In reply to ]
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@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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@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/
Re: KISS - Base Subroutines. [ In reply to ]
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@usbank.com" <anthony.okusanya@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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@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@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/
Re: KISS - Base Subroutines. [ In reply to ]
Don't bother with the extends stuff. Just

use MyApp::CommonUse::FileOne;



- - Martin



________________________________
From: Andrew <catalystgroup@unitedgames.co.uk>
Sent: Friday, July 15, 2016 9:10 AM
To: The elegant MVC web framework
Subject: Re: [Catalyst] KISS - Base Subroutines.


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.
Re: KISS - Base Subroutines. [ In reply to ]
"Andrew" <catalystgroup@unitedgames.co.uk> writes:

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

Create MyApp::Model::Whatever then $c->model('Whatever')->subroutine

_______________________________________________
List: Catalyst@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/
Re: KISS - Base Subroutines. [ In reply to ]
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" <catalystgroup@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@lists.scsys.co.uk>,
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: anthony.okusanya@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@unitedgames.co.uk>
To: "The elegant MVC web framework" <catalyst@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@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@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@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@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.

---------------------------------------------------------------------
Re: KISS - Base Subroutines. [ In reply to ]
If your subroutine/method need objects/context associated with them
you could utilize the Plugin system to create your own plugin that
adds data/methods to $c

On Thu, Jul 14, 2016 at 11:52:39PM +0100, Andrew wrote:
> 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@unitedgames.co.uk>
> To: "The elegant MVC web framework" <catalyst@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@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@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/


--
James R. Leu
jleu@mindspring.com

_______________________________________________
List: Catalyst@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/
Re: KISS - Base Subroutines. [ In reply to ]
I want to apologise for saying I was having trouble with extends.

When using extends,
$self->subroutinename(); worked fine,
while just subroutinename(); didn't - and that was my hiccup/mistake.
It's now working fine with $self->subroutinename(); to call the subroutine, although I've obviously had to anticipate the first value of @_ now being $self.

I'm new to Modern Perl, so still a bit iffy on things like $self (I know it's an object - and that's it),
so I'm intrigued to hear you mention simply using Use instead of extends.
I was searching through a lot of online tutorials, and all the older ones have use and use base as examples in base controller tutorials,
and the more recent ones mention extends instead.
The Definitive Guide to Catalyst states: "use base 'Catalyst::Controller' and use Moose; extends 'Catalyst Controller' are essentially the same,".
I also found a Catalyst Advent Calendar post (2008, Day 16) mentioning that in previous Catalysts you would use use, whereas in 5.80+ you could use use Moose, and then extends. I guess it's just another option - good to hear a plain old use could work also. KISS, =).

Yours,
Andrew.

----- Original Message -----
From: Martin Thurn
To: The elegant MVC web framework
Sent: Friday, July 15, 2016 2:21 PM
Subject: Re: [Catalyst] KISS - Base Subroutines.


Don't bother with the extends stuff. Just


use MyApp::CommonUse::FileOne;







- - Martin









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

From: Andrew <catalystgroup@unitedgames.co.uk>
Sent: Friday, July 15, 2016 9:10 AM
To: The elegant MVC web framework
Subject: Re: [Catalyst] KISS - Base Subroutines.


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.








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


_______________________________________________
List: Catalyst@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/