in reply to Catalyst fcgi engine w. persistent variables
This sounds like an XY Problem and any design that suggests global variables is probably a bad one, so I say. Here is a pretty simple way regardless-
package MyApp; use Moose; use namespace::autoclean; use Catalyst::Runtime 5.80; use Catalyst qw( -Debug ); # etc... extends "Catalyst"; __PACKAGE__->config( name => "MyApp" ); our $MY_COUNTER = 0; sub my_counter { $MY_COUNTER; } before "dispatch" => sub { $MY_COUNTER++ }; __PACKAGE__->setup(); 1;
package MyApp::Controller::Root; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller' } __PACKAGE__->config(namespace => ''); sub counter :Local Args(0) { my ( $self, $c ) = @_; $c->response->body("Count #" . $c->my_counter); } 1; __END__ http://localhost:3000/counter
What you would want to do in any real-world case I can imagine is create a model class or perhaps use Plack middleware. If the information belongs to the application, it would best go in a model. If it's meta/tracking info it could go in the server or a logger. In fact the code could be standalone and then it can go in either the model or server layer or both. Suggested reading: Catalyst::Model::Adaptor and Plack::Middleware.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Catalyst fcgi engine w. persistent variables
by damian45 (Novice) on Jul 07, 2011 at 18:31 UTC | |
by Your Mother (Archbishop) on Jul 07, 2011 at 21:20 UTC | |
by damian45 (Novice) on Jul 07, 2011 at 19:24 UTC |