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.


In reply to Re: Catalyst fcgi engine w. persistent variables by Your Mother
in thread Catalyst fcgi engine w. persistent variables by damian45

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.