[cgiapp] How to lazy-load runmodes

Ron Savage ron at savage.net.au
Tue May 24 00:27:22 EDT 2011


Hi gvim

On Tue, 2011-05-24 at 04:15 +0100, gvim wrote:
> If I have a collection of, say, 15 fairly lengthy Perl scripts and I convert them into a CGI::Application app with 15 runmodes isn't there a huge startup penalty since my app must now load the code for all 15 runmodes prior to dispatch? Is there a way to lazy-load my runmodes? Although I have each one contained in a separate module I still have to 'use' all of them at once when the app starts.

You don't have to use or load them all. If you adopt
CGI::Application::Dispatch and a MVC structure, only 1 controller module
gets loaded, and hence only the run modes in that module get loaded.

There are plenty of modules on CPAN which use this method.

Mine include App::Office::Contacts, App::Office::CMS,
Business::Cart::Generic and CGI::Application::Demo::Dispatch (hint).

Of course, if you run them under plack or Starman, they are permanently
resident anyway, so the startup overhead is only incurred once.

All the above modules include a plack/starman runner httpd/*/*.psgi
using C::A::D.

-- 
Ron Savage
http://savage.net.au/
Ph: 0421 920 622



More information about the cgiapp mailing list