Sewi has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I need to access the current context object for a catalyst request outside of the controller and without passing it from the controller.
A typical catalyst controller:
sub index :Path :Args(0) { my ( $self, $c ) = @_; # Hello World $c->response->body( $c->welcome_message ); }
How to get $c in other modules without explicit passing it?
My current solution is setting a global variable in my root controller...
...and accessing it as $MyApp::Controller::Root::C, but I'd prefer to use the "official" way and to be compatible with any Catalyst App without changing it.package MyApp::Controller::Root; our $C; sub auto :Private { my ($self, $c) = @_; $C = $c; }
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get the Catalyst Context object
by Your Mother (Archbishop) on Nov 08, 2015 at 02:04 UTC | |
|
Re: How to get the Catalyst Context object
by Anonymous Monk on Nov 07, 2015 at 07:54 UTC | |
|
Re: How to get the Catalyst Context object
by Anonymous Monk on Nov 07, 2015 at 07:58 UTC |