Discussion:
[cgi-prototype-users] CGIP and eager loading of Template and CGI in mod_perl-like environments
Terrence Brannon
2005-10-29 12:48:35 UTC
Permalink
I just wanted to start a discussion about usage of CGIP in mod_perl
environments. I am happy with CGIP's setup for my webhosting stuff, because
we use plain CGI. However, for corporate work (should that day come), the
fact that the engine slot and the prototype_enter method use autoloads to
load Template and CGI would compromise performance: one would prefer that
both of these be loaded eagerly.

So, since there is no class supplied with the CGIP distro by default which
handles this (should there be?), I think the approach is obvious:

In the startup.pl or whatever pre-loaded handler you will use simply do
use Template;
use CGI;

use base qw(CGI::Prototype);

BEGIN {

# _reset_globals is discussed here:
http://use.perl.org/~merlyn/journal/24641
CGI::_reset_globals();
my $cgi = CGI->new

}

sub engine {
my $self = shift;
# no longer needed: require Template;
Template->new($self->engine_config)
or die "Creating tt: $Template::ERROR\n";
});

sub CGI {
$cgi
});
Randal L. Schwartz
2005-10-29 14:45:27 UTC
Permalink
Terrence> I just wanted to start a discussion about usage of CGIP in mod_perl
Terrence> environments. I am happy with CGIP's setup for my webhosting stuff, because
Terrence> we use plain CGI. However, for corporate work (should that day come), the
Terrence> fact that the engine slot and the prototype_enter method use autoloads to
Terrence> load Template and CGI would compromise performance: one would prefer that
Terrence> both of these be loaded eagerly.

It would be enough to simply list them literally:

use My::App;
use My::App::PageOne;
use My::App::PageTwo;
etc

You can probably automate that if you wanted. I'm sure you can come
up with a BEGIN block that reads the directory and loads all the
plugins.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
A. Pagaltzis
2005-10-29 16:06:18 UTC
Permalink
Post by Randal L. Schwartz
You can probably automate that if you wanted. I'm sure you can
come up with a BEGIN block that reads the directory and loads
all the plugins.
Cf. Module::Pluggable.

Regards,
--
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;
Terrence Brannon
2005-10-30 06:04:54 UTC
Permalink
Post by A. Pagaltzis
You can probably automate that if you wanted. I'm sure you can
come up with a BEGIN block that reads the directory and loads
all the plugins.
Cf. Module::Pluggable.
Yes, also:

http://search.cpan.org/~drolsky/Class-Factory-Util-1.6/lib/Class/Factory/Util.pm
Loading...