Made all dependencies load their modules on demand rather than on startup (cuts down the page serving time by about 50%). Also removed some debugging statements in certain high profile areas.
git-svn-id: svn://10.0.0.236/trunk@109373 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
4d79330194
commit
1fde83c771
@ -30,8 +30,6 @@ package PLIF::DataSource::Strings;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::DataSource;
|
||||
use HTTP::Negotiate; # DEPENDENCY
|
||||
use HTTP::Headers; # DEPENDENCY
|
||||
@ISA = qw(PLIF::DataSource);
|
||||
1;
|
||||
|
||||
@ -52,6 +50,8 @@ sub provides {
|
||||
sub init {
|
||||
my $self = shift;
|
||||
$self->SUPER::init(@_);
|
||||
require HTTP::Negotiate; import HTTP::Negotiate; # DEPENDENCY
|
||||
require HTTP::Headers; import HTTP::Headers; # DEPENDENCY
|
||||
$self->variantsCache({});
|
||||
$self->stringsCache({});
|
||||
$self->enabled(1);
|
||||
|
||||
@ -30,7 +30,6 @@ package PLIF::Database::ConfigurationFile;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Database;
|
||||
use Data::Dumper; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Database);
|
||||
1;
|
||||
|
||||
@ -42,8 +41,9 @@ use Data::Dumper; # DEPENDENCY
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
$self->SUPER::init(@_);
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require Data::Dumper; import Data::Dumper; # DEPENDENCY
|
||||
$self->{'_FILENAME'} = $app->getService('dataSource.configuration')->configurationFilename;
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,6 @@ use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Database;
|
||||
use PLIF::Database::ResultsFrame::DBI;
|
||||
use DBI; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Database);
|
||||
1;
|
||||
|
||||
@ -49,6 +48,7 @@ sub class {
|
||||
sub init {
|
||||
my $self = shift;
|
||||
$self->SUPER::init(@_);
|
||||
require DBI; import DBI; # DEPENDENCY
|
||||
$self->openDB(@_);
|
||||
}
|
||||
|
||||
|
||||
@ -30,10 +30,11 @@ package PLIF::Database::ResultsFrame::DBI;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF;
|
||||
use DBI; # DEPENDENCY
|
||||
@ISA = qw(PLIF);
|
||||
1;
|
||||
|
||||
# DEPENDENCY: This assumes the DBI module is already loaded
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
$self->SUPER::init(@_);
|
||||
|
||||
@ -30,7 +30,6 @@ package PLIF::Input::CGI;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Input::Arguments;
|
||||
use MIME::Base64; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Input::Arguments);
|
||||
1;
|
||||
|
||||
@ -38,6 +37,13 @@ use MIME::Base64; # DEPENDENCY
|
||||
# The CommandLine module can't tell the difference between a keyword
|
||||
# query and real command line.
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
require MIME::Base64; import MIME::Base64; # DEPENDENCY
|
||||
$self->SUPER::init(@_);
|
||||
}
|
||||
|
||||
sub applies {
|
||||
return defined($ENV{'GATEWAY_INTERFACE'});
|
||||
}
|
||||
|
||||
@ -30,10 +30,16 @@ package PLIF::Input::CommandLine;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Input::Arguments;
|
||||
use Term::ReadLine; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Input::Arguments);
|
||||
1;
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require Term::ReadLine; import Term::ReadLine; # DEPENDENCY
|
||||
}
|
||||
|
||||
sub applies {
|
||||
return @ARGV > 0;
|
||||
}
|
||||
@ -92,7 +98,6 @@ sub createArgument {
|
||||
if ($self->getArgument('batch')) {
|
||||
$self->SUPER::createArgument(@_);
|
||||
} else {
|
||||
$self->warn(8, "going to request '$argument' from user!");
|
||||
$self->app->output->request(@_);
|
||||
# get input from user
|
||||
my $term = Term::ReadLine->new($self->app->name);
|
||||
|
||||
@ -30,17 +30,7 @@ package PLIF::Output::Generic::AIM;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Service;
|
||||
use Net::AIM; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Service);
|
||||
|
||||
# work around a bug in some releases of Net::AIM::Connection
|
||||
if (not Net::AIM::Connection->can('handler')) {
|
||||
eval {
|
||||
package Net::AIM::Connection;
|
||||
sub handler { }
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# XXX This protocol should check if the user is actually online, and
|
||||
@ -61,6 +51,16 @@ sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
# Load AIM Module
|
||||
require Net::AIM; import Net::AIM; # DEPENDENCY
|
||||
if (not Net::AIM::Connection->can('handler')) {
|
||||
# work around a bug in some releases of Net::AIM::Connection
|
||||
eval {
|
||||
package Net::AIM::Connection;
|
||||
sub handler { }
|
||||
};
|
||||
}
|
||||
# Apply Configuration
|
||||
eval {
|
||||
$app->getService('dataSource.configuration')->getSettings($app, $self, 'protocol.aim');
|
||||
};
|
||||
|
||||
@ -30,7 +30,6 @@ package PLIF::Output::Generic::Email;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Service;
|
||||
use Net::SMTP; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Service);
|
||||
1;
|
||||
|
||||
@ -48,6 +47,7 @@ sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require Net::SMTP; import New::SMTP; # DEPENDENCY
|
||||
eval {
|
||||
$app->getService('dataSource.configuration')->getSettings($app, $self, 'protocol.email');
|
||||
};
|
||||
|
||||
@ -46,13 +46,10 @@ sub dispatch {
|
||||
my $self = shift;
|
||||
my($app, $name, @arguments) = @_;
|
||||
my $method = $self->can($name);
|
||||
local $" = '\', \'';
|
||||
if ($method) {
|
||||
$self->dump(10, "Attempting to dispatch method: $self->$name('$app', ...)"); # can't mention @arguments in string since it might contain undefs
|
||||
&$method($self, $app, @arguments);
|
||||
return 1;
|
||||
return 1; # XXX ??? why not return what the method returns ???
|
||||
} else {
|
||||
$self->dump(10, "There is no method '$name' in object '$self', skipping...");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ package PLIF::Service::Coses;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Service;
|
||||
use HTML::Entities; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Service);
|
||||
1;
|
||||
|
||||
@ -45,6 +44,13 @@ sub provides {
|
||||
return ($service eq 'string.expander.COSES' or $class->SUPER::provides($service));
|
||||
}
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require HTML::Entities; import HTML::Entities; # DEPENDENCY
|
||||
}
|
||||
|
||||
sub expand {
|
||||
my $self = shift;
|
||||
my($app, $output, $session, $protocol, $string, $data) = @_;
|
||||
|
||||
@ -30,7 +30,6 @@ package PLIF::Service::XML;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Service;
|
||||
use XML::Parser; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Service);
|
||||
1;
|
||||
|
||||
@ -40,6 +39,13 @@ sub provides {
|
||||
return ($service eq 'service.xml' or $class->SUPER::provides($service));
|
||||
}
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require XML::Parser; import XML::Parser; # DEPENDENCY
|
||||
}
|
||||
|
||||
sub parse {
|
||||
my $self = shift;
|
||||
my($string) = @_;
|
||||
|
||||
@ -108,16 +108,20 @@ only if they are well commented.
|
||||
13. When creating a new dependency, make sure you mark it with the
|
||||
magic string 'DEPENDENCY', as in:
|
||||
|
||||
package PLIF::Coses;
|
||||
use strict;
|
||||
use vars qw(@ISA);
|
||||
use PLIF::Service;
|
||||
use XML::Parser; # DEPENDENCY
|
||||
@ISA = qw(PLIF::Service);
|
||||
1;
|
||||
sub init {
|
||||
my $self = shift;
|
||||
my($app) = @_;
|
||||
$self->SUPER::init(@_);
|
||||
require Some::Module; import Some::Module; # DEPENDENCY
|
||||
}
|
||||
|
||||
This allows for an easy listing of each dependency using 'find'
|
||||
and 'grep'.
|
||||
and 'grep'. Note also the way that dependencies are generally
|
||||
imported inside service constructors and imported using 'require'
|
||||
and 'import' instead of 'use'. This is to make sure that the
|
||||
overhead of importing the relevant code is not hit unless the
|
||||
module is used. Please make sure that 'import' doesn't end up
|
||||
being called more than once, of course.
|
||||
|
||||
|
||||
14. The order for declaring methods should be something along the
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user