Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-18 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found