Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
XP is just a number
 
PerlMonks  

Re: In CGI::Application cgiapp_prerun vs. cgiapp_init?

by Belgarion (Chaplain)
on Dec 12, 2005 at 11:38 UTC ( [id://516050]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to In CGI::Application cgiapp_prerun vs. cgiapp_init?

The main difference is that cgiapp_init() is called once by new, while cgiapp_prerun() is called everytime a request comes in. In a standard CGI environment, both will always happen, but in a modperl environment, cgiapp_init() will only happen when the server first starts.

The order of operation in a CGI::Application is basically:

  1. cgiapp_init()
  2. setup()
  3. cgiapp_prerun()
  4. your selected run mode
  5. cgiapp_postrun()
  6. teardown()

cgiapp_init() and setup() are called in the class's new() method, while the remaining hooks are run in the class's run() method.

  • Comment on Re: In CGI::Application cgiapp_prerun vs. cgiapp_init?

Replies are listed 'Best First'.
Re^2: In CGI::Application cgiapp_prerun vs. cgiapp_init?
by weierophinney (Pilgrim) on Dec 12, 2005 at 12:35 UTC
    The order of operations you provide does a better job at explaining this than your statement, "cgiapp_init() is called once by new, while cgiapp_prerun() is called everytime a request comes in".

    Basically, cgiapp_init() is called as the object is first created in order to setup the environment for the application. cgiapp_prerun() is called prior to executing the selected run mode for a given request. I typically use cgiapp_prerun() to check if the run mode is allowed at this point by this user -- i.e. I use cgiapp_prerun() as the place to implement ACLs.

Re^2: In CGI::Application cgiapp_prerun vs. cgiapp_init?
by saberworks (Curate) on Jul 17, 2012 at 16:52 UTC
    I know this is an old thread, but I ran into an issue under mod_perl where cgiapp_init was being called on every request, not just at server (or process) start. I did some searches and found this: http://old.nabble.com/cgi%3A%3Aapplication%3A%3Adispatch-and-modperl-td29916199.html Summary: they're both called on every request. Not sure if it's a change since this thread was posted but the information here doesn't seem to be correct.
        Ah, it's so blindingly obvious when you point it out, thanks for this. Of course I'm doing exactly what your first example shows, but not for long.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516050]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.