If it's a relatively simple configuration file/info, you can just store the data structure in a package variable. It won't be shared among all the Apache children (each will generally have its own copy) but if you're not making changes to the file that's not a big deal. And I think depending on how your OS implements shared memory the memory might be shared among the children until you make a change. (Check out the mod_perl Guide for lots of info on shared memory.

One for something like this is to read in the file and set the config info in a ChildInit handler. To do this, define your routine from above in your startup.pl startup file and then add the routine into the ChildInit handler stack. That way you'll always know it's there.

The downside of this is that you can't do dir_config calls within your startup.pl file because you're not in a directory when Apache is starting up. You can, however, read server configuration variables and work from there. For instance, if you have five different configuration files you could map a configuration name to a file location, read them in at startup and store them in a My::App::Config package, then call the specific configuration from other handlers depending on the configuration name set in a PerlSetVar location directive.

For something like this you might also look into the Singleton pattern (implemented by Class::Singleton) so you can refer to the configuration from any other handler with a simple call like My::App::Config->instance.

As for your second question, the two would be in the same memory/name space. If you want you can separate them by setting an additional PerlSetVar in the two different location directives that specifies which configuration (or whatever) you're using.

Hope this helps.

Chris
M-x auto-bs-mode


In reply to Re: Storing data with mod_perl (are those handlers different) ? by lachoy
in thread Storing data with mod_perl (are those handlers different) ? by lindex

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.