Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've got some nice things working with CGI::Application, however one Runmode that dels with Ajax call. I want it to call another runmode (which sends email based on some input params) then continie to run the calling runmode. Can this be done?
  • Comment on CGI::Application, call another runmode then return

Replies are listed 'Best First'.
Re: CGI::Application, call another runmode then return
by MidLifeXis (Monsignor) on Nov 05, 2010 at 14:04 UTC

    Instead of the runmode doing the email task, have the runmode call a function that does the email task. Then call the same function from your original runmode as well.

    Typically, I use a runmode to collect parameters from the client, and call a function with those parameters (after appropriate validation and conversion). This additional layer of abstraction allows also using the functions in a command line script, gui application, or other type of application.

    --MidLifeXis

Re: CGI::Application, call another runmode then return
by locked_user sundialsvc4 (Abbot) on Nov 05, 2010 at 17:38 UTC

    I use the CGI::Application portion (and its associated concept of “runmodes”) strictly as an initial method of identifying and then dispatching the original web request ... nothing more or less.   From that point forward, “it’s just Perl.”

    Furthermore, it is very helpful to have other, background processes to whom you can delegate potentially time-consuming tasks such as sending e-mails.   Package up a record describing the request, then write it to a pipe somewhere.   Arrange for another process, somewhere else, to be standing around, listening on that pipe and doing what it’s told.   This keeps the web-server itself “lean and mean,” able to handle a large volume of requests because gets each one done quickly.   If a backlog builds up, it will be (stored) in the pipe, and the pipe-listener process(es) will eventually chow through it.