diff --git a/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm b/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm index 87d28375d5e..9143f7793db 100644 --- a/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm +++ b/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm @@ -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); diff --git a/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm b/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm index 9d2063f1386..55be091bfcb 100644 --- a/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm +++ b/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm @@ -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; } diff --git a/mozilla/webtools/PLIF/PLIF/Database/DBI.pm b/mozilla/webtools/PLIF/PLIF/Database/DBI.pm index 6f2fdb3522a..e1bfc0c3130 100644 --- a/mozilla/webtools/PLIF/PLIF/Database/DBI.pm +++ b/mozilla/webtools/PLIF/PLIF/Database/DBI.pm @@ -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(@_); } diff --git a/mozilla/webtools/PLIF/PLIF/Database/ResultsFrame/DBI.pm b/mozilla/webtools/PLIF/PLIF/Database/ResultsFrame/DBI.pm index 7687c673f24..ad2d3467d6f 100644 --- a/mozilla/webtools/PLIF/PLIF/Database/ResultsFrame/DBI.pm +++ b/mozilla/webtools/PLIF/PLIF/Database/ResultsFrame/DBI.pm @@ -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(@_); diff --git a/mozilla/webtools/PLIF/PLIF/Input/CGI.pm b/mozilla/webtools/PLIF/PLIF/Input/CGI.pm index 413ac6a4f14..5f30b9bb6ff 100644 --- a/mozilla/webtools/PLIF/PLIF/Input/CGI.pm +++ b/mozilla/webtools/PLIF/PLIF/Input/CGI.pm @@ -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'}); } diff --git a/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm b/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm index 2e01e29d385..3edca486978 100644 --- a/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm +++ b/mozilla/webtools/PLIF/PLIF/Input/CommandLine.pm @@ -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); diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm index 98ffa4ca083..f4d303f73a7 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm @@ -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'); }; diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm index 6ca863584b1..ec0744373ee 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm @@ -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'); }; diff --git a/mozilla/webtools/PLIF/PLIF/Service.pm b/mozilla/webtools/PLIF/PLIF/Service.pm index e57be29b80e..1a93614126e 100644 --- a/mozilla/webtools/PLIF/PLIF/Service.pm +++ b/mozilla/webtools/PLIF/PLIF/Service.pm @@ -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; } } diff --git a/mozilla/webtools/PLIF/PLIF/Service/Coses.pm b/mozilla/webtools/PLIF/PLIF/Service/Coses.pm index d7a6f5db665..983d1d6324c 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/Coses.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/Coses.pm @@ -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) = @_; diff --git a/mozilla/webtools/PLIF/PLIF/Service/XML.pm b/mozilla/webtools/PLIF/PLIF/Service/XML.pm index c0bad8e056f..ffb57299a97 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/XML.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/XML.pm @@ -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) = @_; diff --git a/mozilla/webtools/PLIF/STYLEGUIDE b/mozilla/webtools/PLIF/STYLEGUIDE index ea8082be5f2..c435d29ea1f 100644 --- a/mozilla/webtools/PLIF/STYLEGUIDE +++ b/mozilla/webtools/PLIF/STYLEGUIDE @@ -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