From d0e1d3a931f85a0a3a1eda42e330dff96a6236c8 Mon Sep 17 00:00:00 2001 From: "ian%hixie.ch" Date: Sat, 15 Mar 2003 14:14:21 +0000 Subject: [PATCH] remove DESTROY code, rework the output system to use a single hash instead of passing arguments around, delay the loading of certain modules, fix some bugs with the removal of the built in property system, make the TemplateToolkit module only have one template object, and cache the precompiled documents, remove the HTTP output module, and other optimisations. git-svn-id: svn://10.0.0.236/trunk@139517 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/PLIF/PLIF.pm | 12 +-- mozilla/webtools/PLIF/PLIF/Controller.pm | 1 - .../PLIF/PLIF/DataSource/DebugStrings.pm | 12 +-- .../PLIF/PLIF/DataSource/FileStrings.pm | 23 +++--- .../webtools/PLIF/PLIF/DataSource/Strings.pm | 79 +++++++++++-------- mozilla/webtools/PLIF/PLIF/Database.pm | 6 +- .../PLIF/PLIF/Database/ConfigurationFile.pm | 1 - mozilla/webtools/PLIF/PLIF/Database/DBI.pm | 1 - mozilla/webtools/PLIF/PLIF/Input/CGI/Head.pm | 5 +- mozilla/webtools/PLIF/PLIF/Output/Generic.pm | 45 ++++++----- .../webtools/PLIF/PLIF/Output/Generic/AIM.pm | 1 - .../PLIF/PLIF/Output/Generic/Email.pm | 7 +- .../PLIF/PLIF/Output/Generic/StdOut.pm | 4 +- mozilla/webtools/PLIF/PLIF/Output/HTTP.pm | 71 ----------------- .../PLIF/Service/Components/AdminCommands.pm | 18 +++-- .../PLIF/Service/Components/CosesEditor.pm | 20 ++++- .../PLIF/PLIF/Service/Components/UserPrefs.pm | 2 +- mozilla/webtools/PLIF/PLIF/Service/Coses.pm | 23 ++++-- .../PLIF/PLIF/Service/GenericOutputs.pm | 29 ++++--- .../PLIF/PLIF/Service/TemplateToolkit.pm | 79 ++++++++++++------- mozilla/webtools/PLIF/PLIF/Service/User.pm | 23 ++++-- .../webtools/PLIF/PLIF/Service/UserField.pm | 1 - mozilla/webtools/PLIF/compile-templates.pl | 2 +- 23 files changed, 237 insertions(+), 228 deletions(-) delete mode 100644 mozilla/webtools/PLIF/PLIF/Output/HTTP.pm diff --git a/mozilla/webtools/PLIF/PLIF.pm b/mozilla/webtools/PLIF/PLIF.pm index 2f65da44bec..21f45a41e2a 100644 --- a/mozilla/webtools/PLIF/PLIF.pm +++ b/mozilla/webtools/PLIF/PLIF.pm @@ -136,7 +136,7 @@ sub load { sub AUTOLOAD { my $self = shift; my $name = $AUTOLOAD; - syntaxError "Use of inherited AUTOLOAD for non-method $name is deprecated" if not defined($self); + syntaxError "Use of inherited AUTOLOAD for non-method $name is deprecated", 1 if not defined($self); $name =~ s/^.*://o; # strip fully-qualified portion my $method = $self->can('implyMethod'); # get a function pointer @_ = ($self, $name, @_); # set the arguments @@ -160,7 +160,7 @@ sub propertyGet { sub implyMethod { my $self = shift; my($method) = @_; - syntaxError "Tried to access non-existent method '$method' in object '$self'"; + syntaxError "Tried to access non-existent method '$method' in object '$self'", 1; } @@ -234,7 +234,7 @@ sub getDebugLevel { return \$DEBUG; } -sub DESTROY { - my $self = shift; - $self->dump(10, "Called destructor of object $self..."); -} +sub DESTROY {} +# my $self = shift; +# $self->dump(10, "Called destructor of object $self..."); +#} diff --git a/mozilla/webtools/PLIF/PLIF/Controller.pm b/mozilla/webtools/PLIF/PLIF/Controller.pm index dab487f72a1..46a51833f98 100644 --- a/mozilla/webtools/PLIF/PLIF/Controller.pm +++ b/mozilla/webtools/PLIF/PLIF/Controller.pm @@ -262,7 +262,6 @@ sub DESTROY { ' services registered, of which ' . scalar(keys(%{$self->{servicesHash}})) . ' had been placed in the services hash.'); - $self->SUPER::DESTROY(@_); } diff --git a/mozilla/webtools/PLIF/PLIF/DataSource/DebugStrings.pm b/mozilla/webtools/PLIF/PLIF/DataSource/DebugStrings.pm index a9a0349b847..404a02b1bb8 100644 --- a/mozilla/webtools/PLIF/PLIF/DataSource/DebugStrings.pm +++ b/mozilla/webtools/PLIF/PLIF/DataSource/DebugStrings.pm @@ -43,15 +43,17 @@ __DATA__ sub getDefaultString { my $self = shift; - my($app, $protocol, $string) = @_; + my($args) = @_; # this is protocol agnostic stuff :-) - if ($string eq 'debug.dumpVars') { + if ($args->{'name'} eq 'debug.dumpVars') { # the slashes in regexps below have to be escaped: # once for the regexp # both of those for the TemplateToolkit string # all four of those for Perl's <{'type'} = 'TemplateToolkit'; + $args->{'version'} = 1; + $args->{'string'} = <{'protocol'}, $args->{'name'}) { $piece =~ s/[^a-zA-Z\/0-9.]/_/gos; } # create a couple of paths relative to the application - push(@filenames, "output-compiled/$protocol/$string"); - push(@filenames, "output/$protocol/$string"); + push(@filenames, "output-compiled/$args->{'protocol'}/$args->{'name'}"); + push(@filenames, "output/$args->{'protocol'}/$args->{'name'}"); # and a couple relative to the PLIF library - push(@filenames, $DIR."/../../output-compiled/$protocol/$string"); - push(@filenames, $DIR."/../../output/$protocol/$string"); + push(@filenames, $DIR."/../../output-compiled/$args->{'protocol'}/$args->{'name'}"); + push(@filenames, $DIR."/../../output/$args->{'protocol'}/$args->{'name'}"); } else { $self->error(0, "Platform '$^O' not supported yet."); } @@ -98,11 +98,12 @@ sub getDefaultString { # while we're at it, untaint it (it came from the file system, it's safe). local $/ = undef; =~ m/^(.*)$/os; - push(@data, $1); + $args->{'type'} = $data[0]; + $args->{'version'} = $data[1]; + $args->{'string'} = $1; $self->assert(close(FILE), 3, "Could not close output template file '$filename': $!"); - return @data; + return 1; } - } - # no file exists - return; # no can do, sir + } # else no file exists + return; } diff --git a/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm b/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm index 6c622bf8a34..c2902cc5d04 100644 --- a/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm +++ b/mozilla/webtools/PLIF/PLIF/DataSource/Strings.pm @@ -57,8 +57,7 @@ __DATA__ sub init { my $self = shift; $self->SUPER::init(@_); - require HTTP::Negotiate; import HTTP::Negotiate; # DEPENDENCY - require HTTP::Headers; import HTTP::Headers; # DEPENDENCY + $self->{loadedNegotiationEngine} = 0; $self->{variantsCache} = {}; $self->{stringsCache} = {}; $self->{enabled} = 1; @@ -67,38 +66,40 @@ sub init { # returns ($type, $version, $string) sub getCustomisedString { my $self = shift; - my($app, $session, $protocol, $string) = @_; + my($args) = @_; # error handling makes code ugly :-) if ($self->{enabled}) { my $variant; - if (defined($session)) { - $variant = $session->selectVariant($protocol); + if (defined($args->{'session'})) { + $variant = $args->{'session'}->selectVariant($args->{'protocol'}); } if (not defined($variant)) { - # default session or $session didn't care, get stuff from - # $app->input instead - $variant = $self->selectVariant($app, $protocol); + # default session or $args->{'session'} didn't care, get stuff from + # $args->{'app'}->input instead + $variant = $self->selectVariant($args->{'app'}, $args->{'protocol'}); } if (not defined($self->{stringsCache}->{$variant})) { $self->{stringsCache}->{$variant} = {}; } - if (not defined($self->{stringsCache}->{$variant}->{$string})) { + if (not defined($self->{stringsCache}->{$variant}->{$args->{'name'}})) { my @results; try { - @results = $self->getString($app, $variant, $string); + @results = $self->getString($args->{'app'}, $variant, $args->{'name'}); } except { # ok, so, er, it seems that didn't go to well # XXX do we want to do an error here or something? - $self->warn(4, "While I was looking for the string '$string' in protocol '$protocol' using variant '$variant', I failed with: @_"); + $self->warn(4, "While I was looking for the string '$args->{'name'}' in protocol '$args->{'protocol'}' using variant '$variant', I failed with: @_"); }; if (@results) { - $self->{stringsCache}->{$variant}->{$string} = \@results; - return @results; + $self->{stringsCache}->{$variant}->{$args->{'name'}} = \@results; + ($args->{'type'}, $args->{'version'}, $args->{'string'}) = @results; + return 1; } else { return; } } else { - return @{$self->{stringsCache}->{$variant}->{$string}}; + ($args->{'type'}, $args->{'version'}, $args->{'string'}) = @{$self->{stringsCache}->{$variant}->{$args->{'name'}}}; + return 1; } } else { $self->dump(9, "String datasource is disabled, skipping"); @@ -109,27 +110,32 @@ sub getCustomisedString { sub selectVariant { my $self = shift; my($app, $protocol) = @_; + my $choice; # Find list of options from DB. my $variants = $self->variants($app, $protocol); - # Initialize the fake header - my $request = new HTTP::Headers; - foreach my $header (['Accept', $self->acceptType($app, $protocol)], - ['Accept-Encoding', $self->acceptEncoding($app, $protocol)], - ['Accept-Charset', $self->acceptCharset($app, $protocol)], - ['Accept-Language', $self->acceptLanguage($app, $protocol)]) { - # only add headers that exist -- HTTP::Negotiate isn't very bullet-proof :-) - if ($header->[1]) { - $request->header(@$header); - } - } - # Do Content Negotiation :-D - my $choice; if (scalar(@$variants) > 0) { + if (!$self->{loadedNegotiationEngine}) { + require HTTP::Negotiate; import HTTP::Negotiate; # DEPENDENCY + require HTTP::Headers; import HTTP::Headers; # DEPENDENCY + $self->{loadedNegotiationEngine} = 1; + } + # Initialize the fake header + my $request = new HTTP::Headers; + foreach my $header (['Accept', $self->acceptType($app, $protocol)], + ['Accept-Encoding', $self->acceptEncoding($app, $protocol)], + ['Accept-Charset', $self->acceptCharset($app, $protocol)], + ['Accept-Language', $self->acceptLanguage($app, $protocol)]) { + # only add headers that exist -- HTTP::Negotiate isn't very bullet-proof :-) + if ($header->[1]) { # check if the header exists + $request->header(@$header); # if so, add it to the headers object + } + } + # Do Content Negotiation :-D # $HTTP::Negotiate::DEBUG = 1; # enable debugging $choice = choose($variants, $request); } if (not defined($choice)) { - $choice = 0; # XXX we could maybe not hard code the default variant some how... ;-) + $choice = 0; # XXX we could maybe not hard code the default variant some how... } return $choice; } @@ -182,7 +188,11 @@ sub setupInstall { foreach my $string (@$strings) { # get version of default for $string->name in $string->protocol my($variantID, $variantName, $variantProtocol, $stringName, $stringVersion) = @$string; - my($defaultStringType, $defaultStringVersion, $defaultStringData) = $app->getSelectingService('dataSource.strings.default')->getDefaultString($app, $variantProtocol, $stringName); + my($defaultStringType, $defaultStringVersion, $defaultStringData) = $app->getSelectingService('dataSource.strings.default')->getDefaultString({ + 'app' => $app, + 'protocol' => $variantProtocol, + 'name' => $stringName, + }); # if version < default string's version if ($stringVersion < $defaultStringVersion) { # XXX this is a numeric comparison because I am assuming @@ -220,10 +230,13 @@ sub strings { # dataSource.strings.default sub getDefaultString { my $self = shift; - my($app, $protocol, $string) = @_; - if ($protocol eq 'stdout') { - if ($string eq 'setup.newStringsReport') { - return ('COSES', '1', 'Note: The following strings have had their defaults updated since you last customised them:
(): yours=, new=
') + my($args) = @_; + if ($args->{'protocol'} eq 'stdout') { + if ($args->{'name'} eq 'setup.newStringsReport') { + $args->{'type'} = 'COSES'; + $args->{'version'} = 1; + $args->{'string'} = 'Note: The following strings have had their defaults updated since you last customised them:
(): yours=, new=
'; + return 1; } } return; # nope, sorry diff --git a/mozilla/webtools/PLIF/PLIF/Database.pm b/mozilla/webtools/PLIF/PLIF/Database.pm index b582d7b8c1b..793565d1c14 100644 --- a/mozilla/webtools/PLIF/PLIF/Database.pm +++ b/mozilla/webtools/PLIF/PLIF/Database.pm @@ -53,6 +53,6 @@ sub lastError { } -package PLIF::Exception::Database; use vars qw(@ISA @EXPORT); @ISA = qw(PLIF::Exception); -package PLIF::Exception::Database::Version; use vars qw(@ISA @EXPORT); @ISA = qw(PLIF::Exception::Database); -package PLIF::Exception::Database::Duplicate; use vars qw(@ISA @EXPORT); @ISA = qw(PLIF::Exception::Database); +package PLIF::Exception::Database; use vars qw(@ISA); @ISA = qw(PLIF::Exception); +package PLIF::Exception::Database::Version; use vars qw(@ISA); @ISA = qw(PLIF::Exception::Database); +package PLIF::Exception::Database::Duplicate; use vars qw(@ISA); @ISA = qw(PLIF::Exception::Database); diff --git a/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm b/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm index 1a4fba20941..71a9228d091 100644 --- a/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm +++ b/mozilla/webtools/PLIF/PLIF/Database/ConfigurationFile.pm @@ -136,7 +136,6 @@ sub DESTROY { if ($self->{'_DIRTY'}) { $self->write(); } - $self->SUPER::DESTROY(@_); } diff --git a/mozilla/webtools/PLIF/PLIF/Database/DBI.pm b/mozilla/webtools/PLIF/PLIF/Database/DBI.pm index c2840a084dc..28e7f95f74f 100644 --- a/mozilla/webtools/PLIF/PLIF/Database/DBI.pm +++ b/mozilla/webtools/PLIF/PLIF/Database/DBI.pm @@ -309,5 +309,4 @@ sub setupConfigureDatabase { sub DESTROY { my $self = shift; $self->closeDB(@_); - $self->SUPER::DESTROY(@_); } diff --git a/mozilla/webtools/PLIF/PLIF/Input/CGI/Head.pm b/mozilla/webtools/PLIF/PLIF/Input/CGI/Head.pm index 862384e32f5..9c096bbe423 100644 --- a/mozilla/webtools/PLIF/PLIF/Input/CGI/Head.pm +++ b/mozilla/webtools/PLIF/PLIF/Input/CGI/Head.pm @@ -62,9 +62,8 @@ sub objectProvides { sub filterOutput { my $self = shift; - my($app, $session, $string) = @_; - $string =~ s/\n\n.*$/\n\n/os; # strip out everything after the header - return $string; + my($args) = @_; + $args{'string'} =~ s/\n\n.*$/\n\n/os; # strip out everything after the header } # return 1 if we are not allowed to have side effects diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic.pm index bcad0dcd99c..c7078674365 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic.pm @@ -134,14 +134,18 @@ sub output { } $self->dump(9, "outputting string '$string' on protocol '". ($self->{actualProtocol}) .'\''); $self->fillData($data); - # it's not that anyone would override dataSource.strings, it's just that - # people might call it without calling output(), so the right thing here - # is also to call it through getService(): - $string = $self->{app}->getService('dataSource.strings')->getExpandedString($self->{app}, $session, $self->{actualProtocol}, $string, $data); + my $outputArgs = { + 'app' => $self->{app}, + 'session' => $session, + 'protocol' => $self->{actualProtocol}, + 'name' => $string, + 'data' => $data, + }; + $self->getExpandedString($outputArgs); # modifies $outputArgs in place (adds 'string') foreach my $filter ($self->{app}->getObjectList('output.filter')) { - $string = $filter->filterOutput($self->{app}, $session, $string); + $string = $filter->filterOutput($outputArgs); } - $self->{outputter}->output($self->{app}, $session, $string); + $self->{outputter}->output($outputArgs); } # output.generic service instance method @@ -180,30 +184,33 @@ sub fillData { # dataSource.strings default implementation sub getString { my $self = shift; - my($app, $session, $protocol, $name) = @_; - my @string = $app->getSelectingServiceList('dataSource.strings.customised')->getCustomisedString($app, $session, $protocol, $name); - if (not @string) { - @string = $app->getSelectingServiceList('dataSource.strings.default')->getDefaultString($app, $protocol, $name); - $self->assert(scalar(@string), 1, "No suitable '$name' string available for the '$protocol' protocol"); + my($args) = @_; + $args->{'app'}->getSelectingServiceList('dataSource.strings.customised')->getCustomisedString($args); + if (not defined $args->{'string'}) { + $args->{'app'}->getSelectingServiceList('dataSource.strings.default')->getDefaultString($args); + $self->assert(defined $args->{'string'}, 1, "No suitable '$args->{'name'}' string available for the '$args->{'protocol'}' protocol"); } - return @string; + return 1 if (not defined $args->{'string'}); + return; } # dataSource.strings default implementation sub expandString { my $self = shift; - my($app, $session, $protocol, $name, $type, $string, $data) = @_; - my $expander = $app->getService("string.expander.$type"); - $self->assert($expander, 1, "Could not find a string expander for string '$name' of type '$type'"); - return $expander->expand($app, $self, $session, $protocol, $string, $data, $type); + my($args) = @_; + my $expander = $args->{'app'}->getService("string.expander.$args->{'type'}"); + $self->assert($expander, 1, "Could not find a string expander for string '$args->{'name'}' of type '$args->{'type'}'"); + $expander->expand($args); } # dataSource.strings default implementation sub getExpandedString { my $self = shift; - my($app, $session, $protocol, $name, $data) = @_; - my($type, $version, $string) = $self->getString($app, $session, $protocol, $name); - return $self->expandString($app, $session, $protocol, $name, $type, $string, $data); + my($args) = @_; + $self->getString($args); + $self->expandString($args); + return 1 if (not defined $args->{'string'}); + return; } # dispatcher.commands diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm index d568333ca14..1be1da24f8f 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic/AIM.pm @@ -156,7 +156,6 @@ sub checkAddress { sub DESTROY { my $self = shift; $self->close(); - $self->SUPER::DESTROY(@_); } # dataSource.configuration.client diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm index 70b1f0c2e41..57d9092c220 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic/Email.pm @@ -87,13 +87,13 @@ sub close { # output.generic.email sub output { my $self = shift; - my($app, $session, $string) = @_; + my($args) = @_; $self->assert(defined($self->{handle}), 1, 'No SMTP handle, can\'t send mail'); try { local $SIG{ALRM} = sub { raise PLIF::Exception::Alarm }; $self->assert($self->{handle}->mail($self->from), 1, 'Could not start sending mail'); - $self->assert($self->{handle}->to($session->getAddress('email')), 1, 'Could not set mail recipient (was going to send to '.($session->getAddress('email')).')'); - $self->assert($self->{handle}->data($string), 1, 'Could not send mail body'); + $self->assert($self->{handle}->to($args->{'session'}->getAddress('email')), 1, 'Could not set mail recipient (was going to send to '.($args->{'session'}->getAddress('email')).')'); + $self->assert($self->{handle}->data($args->{'string'}), 1, 'Could not send mail body'); alarm(0); } catch PLIF::Exception::Alarm with { $self->error(1, 'Timed out while trying to send e-mail'); @@ -115,7 +115,6 @@ sub checkAddress { sub DESTROY { my $self = shift; $self->close(); - $self->SUPER::DESTROY(@_); } # dataSource.configuration.client diff --git a/mozilla/webtools/PLIF/PLIF/Output/Generic/StdOut.pm b/mozilla/webtools/PLIF/PLIF/Output/Generic/StdOut.pm index 01b4c915f34..4245862c405 100644 --- a/mozilla/webtools/PLIF/PLIF/Output/Generic/StdOut.pm +++ b/mozilla/webtools/PLIF/PLIF/Output/Generic/StdOut.pm @@ -45,9 +45,9 @@ __DATA__ sub output { my $self = shift; - my($app, $session, $string) = @_; + my($args) = @_; $| = 1; # flush output even if no newline - print $string; + print $args->{'string'}; } sub hash { diff --git a/mozilla/webtools/PLIF/PLIF/Output/HTTP.pm b/mozilla/webtools/PLIF/PLIF/Output/HTTP.pm deleted file mode 100644 index 2bb75b2d2ca..00000000000 --- a/mozilla/webtools/PLIF/PLIF/Output/HTTP.pm +++ /dev/null @@ -1,71 +0,0 @@ -# -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*- -# -# This file is MPL/GPL dual-licensed under the following terms: -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.1 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and -# limitations under the License. -# -# The Original Code is PLIF 1.0. -# The Initial Developer of the Original Code is Ian Hickson. -# -# Alternatively, the contents of this file may be used under the terms -# of the GNU General Public License Version 2 or later (the "GPL"), in -# which case the provisions of the GPL are applicable instead of those -# above. If you wish to allow use of your version of this file only -# under the terms of the GPL and not to allow others to use your -# version of this file under the MPL, indicate your decision by -# deleting the provisions above and replace them with the notice and -# other provisions required by the GPL. If you do not delete the -# provisions above, a recipient may use your version of this file -# under either the MPL or the GPL. - -package PLIF::Output::HTTP; -use strict; -use vars qw(@ISA); -use PLIF::Output; -@ISA = qw(PLIF::Output); -1; - -sub protocol { - return 'http'; -} - -__DATA__ - -sub finaliseHeader { - my $self = shift; - print "Content-Type: " . $self->format . "\n"; - foreach my $header ($self->headers) { - print "$header\n"; - } - print "\n"; -} - -sub authenticate { - my $self = shift; - my $realm = $self->realm; - print "Status: 401 Unauthorized\nWWW-Authenticate: Basic realm=\"$realm\"\n"; - $self->finaliseHeader(); -} - -sub header { - my $self = shift; - print "Status: 200 OK\n"; - $self->finaliseHeader(); -} - -sub realm { - my $self = shift; - $self->notImplemented(); -} - -sub headers { - return (); -} diff --git a/mozilla/webtools/PLIF/PLIF/Service/Components/AdminCommands.pm b/mozilla/webtools/PLIF/PLIF/Service/Components/AdminCommands.pm index 6541045c627..66d8918d370 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/Components/AdminCommands.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/Components/AdminCommands.pm @@ -136,14 +136,20 @@ sub strings { # dataSource.strings.default sub getDefaultString { my $self = shift; - my($app, $protocol, $string) = @_; - if ($protocol eq 'stdout') { - if ($string eq 'setup') { - return ('COSES', '1', 'Can\'t continue: argument is missing.Succeeded!
'); + my($args) = @_; + if ($args->{'protocol'} eq 'stdout') { + if ($args->{'name'} eq 'setup') { + $args->{'type'} = 'COSES'; + $args->{'version'} = 1; + $args->{'string'} = 'Can\'t continue: argument is missing.Succeeded!
'; + return 1; } elsif ($string eq 'setup.progress') { - return ('COSES', '1', 'Setup: ...
'); + $args->{'type'} = 'COSES'; + $args->{'version'} = 1; + $args->{'string'} = 'Setup: ...
'; + return 1; } } - return; # nope, sorry + return; } diff --git a/mozilla/webtools/PLIF/PLIF/Service/Components/CosesEditor.pm b/mozilla/webtools/PLIF/PLIF/Service/Components/CosesEditor.pm index 7e2510e8869..4850a33cb6f 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/Components/CosesEditor.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/Components/CosesEditor.pm @@ -402,10 +402,16 @@ sub getExpectedStrings { if (defined($protocol)) { my $defaults = $app->getSelectingService('dataSource.strings.default'); foreach my $string (keys(%$strings)) { + my $args = { + 'app' => $app, + 'protocol' => $protocol, + 'name' => $string, + }; + $defaults->getDefaultString($args); $strings->{$string} = { - 'description' => $strings->{$string}, - 'default' => $defaults->getDefaultString($app, $protocol, $string), - }; + 'description' => $strings->{$string}, + 'default' => $args->{'string'}, + }; } } return $strings; @@ -418,7 +424,13 @@ sub getDescribedVariants { if (defined($string)) { my $defaults = $app->getSelectingService('dataSource.strings.default'); foreach my $variant (keys(%$variants)) { - push(@{$variants->{$variant}}, $defaults->getDefaultString($app, $variants->{$variant}->[1], $string)); + my $args = { + 'app' => $app, + 'protocol' => $variants->{$variant}->[1], + 'name' => $string, + }; + $defaults->getDefaultString($args); + push(@{$variants->{$variant}}, $args->{'string'}); } } return $variants; diff --git a/mozilla/webtools/PLIF/PLIF/Service/Components/UserPrefs.pm b/mozilla/webtools/PLIF/PLIF/Service/Components/UserPrefs.pm index b5fdccf6e1f..124606a03cc 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/Components/UserPrefs.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/Components/UserPrefs.pm @@ -167,7 +167,7 @@ sub populateUserPrefsHashFieldCategory { $userData->{'fields'}->{$category} = {}; if (defined($targetUser->fields->{$category})) { foreach my $field (values(%{$targetUser->fields->{$category}})) { - $userData->{'fields'}->{$category}->{$field->name} = $field->data; + $userData->{'fields'}->{$category}->{$field->{name}} = $field->data; } } } diff --git a/mozilla/webtools/PLIF/PLIF/Service/Coses.pm b/mozilla/webtools/PLIF/PLIF/Service/Coses.pm index e6aac0278bf..63461467e38 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/Coses.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/Coses.pm @@ -57,7 +57,14 @@ sub init { sub expand { my $self = shift; - my($app, $output, $session, $protocol, $string, $data, $stringType) = @_; + my($args) = @_; + $app = $args->{'app'}; + $output = $args->{'output'}; + $session = $args->{'session'}; + $protocol = $args->{'protocol'}; + $string = $args->{'string'}; + $data = $args->{'data'}; + $stringType = $args->{'stringType'}; my $xmlService = $app->getService('service.xml'); my @index = (); my $index = 0; my @stack = (); my $stack = $xmlService->parseNS($string); @@ -80,7 +87,8 @@ sub expand { $scope = pop(@scope); } else { # end of stack -- have a nice day! - return $result; + $data->{'string'} = $result; + return; } } else { # more data to deal with at this level @@ -191,9 +199,13 @@ sub expand { # insert it into the result. # XXX the nested string will have a corrupted # scope hash. XXX - $result .= $self->escape($app, $app->getService('dataSource.strings')->getExpandedString($app, $session, $protocol, - $self->evaluateExpression($attributes->{'href'}, $scope, $originalKeys), $scope), - $scope); + $result .= $self->escape($app, $app->getService('dataSource.strings')->getExpandedString({ + 'app' => $app, + 'session' => $session, + 'protocol' => $protocol, + 'name' => $self->evaluateExpression($attributes->{'href'}, $scope, $originalKeys), + 'data' => $scope, + }), $scope); } elsif ($attributes->{'parse'} eq 'text') { # raw text inclusion my($type, $version, $string) = $app->getService('dataSource.strings')->getString($app, $session, $protocol, $self->evaluateExpression($attributes->{'href'}, $scope, $originalKeys)); @@ -305,6 +317,7 @@ sub expand { } } } + # can't get here (in theory) } sub appendPendingText { diff --git a/mozilla/webtools/PLIF/PLIF/Service/GenericOutputs.pm b/mozilla/webtools/PLIF/PLIF/Service/GenericOutputs.pm index 8200b10225c..3691bc9d59e 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/GenericOutputs.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/GenericOutputs.pm @@ -84,24 +84,23 @@ sub strings { # dataSource.strings.default sub getDefaultString { my $self = shift; - my($app, $protocol, $string) = @_; - if ($string eq 'error') { + my($args) = @_; + if ($args->{'name'} eq 'error') { $self->dump(9, 'Looks like an error occured, because the string \'error\' is being requested'); } - if ($protocol eq 'stdout') { - if ($string eq 'acknowledge') { - return ('COSES', '1', 'Acknowledged.
'); - } elsif ($string eq 'request') { - return ('COSES', '1', '\'\' (default: \'\', \'\')? '); - } elsif ($string eq 'error') { - return ('COSES', '1', 'Error:

'); + if ($args->{'protocol'} eq 'stdout') { + if ($args->{'name'} eq 'acknowledge') { + $args->{'string'} = ('COSES', '1', 'Acknowledged.
'); + } elsif ($args->{'name'} eq 'request') { + $args->{'string'} = ('COSES', '1', '\'\' (default: \'\', \'\')? '); + } elsif ($args->{'name'} eq 'error') { + $args->{'string'} = ('COSES', '1', 'Error:

'); } - } elsif ($protocol eq 'http') { - if ($string eq 'acknowledge') { - return ('COSES', '1', 'Status: 200 OK
Content-Type: text/plain

Acknowledged.
'); - } elsif ($string eq 'error') { - return ('COSES', '1', 'Status: 500 Internal Error
Content-Type: text/plain

Error:
'); + } elsif ($args->{'protocol'} eq 'http') { + if ($args->{'name'} eq 'acknowledge') { + $args->{'string'} = ('COSES', '1', 'Status: 200 OK
Content-Type: text/plain

Acknowledged.
'); + } elsif ($args->{'name'} eq 'error') { + $args->{'string'} = ('COSES', '1', 'Status: 500 Internal Error
Content-Type: text/plain

Error:
'); } } - return; # nope, sorry } diff --git a/mozilla/webtools/PLIF/PLIF/Service/TemplateToolkit.pm b/mozilla/webtools/PLIF/PLIF/Service/TemplateToolkit.pm index 65d807baf7f..4b19bae376e 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/TemplateToolkit.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/TemplateToolkit.pm @@ -28,9 +28,11 @@ package PLIF::Service::TemplateToolkit; use strict; -use vars qw(@ISA); +use vars qw(@ISA %CACHE); use PLIF::Service; +use PLIF::Exception; @ISA = qw(PLIF::Service); +%CACHE = (); 1; sub provides { @@ -51,39 +53,59 @@ sub init { eval { package PLIF::Service::TemplateToolkit::Context; require Template::Context; import Template::Context; # DEPENDENCY + require POSIX; import POSIX qw(strftime); # DEPENDENCY }; + local $Template::Config::STASH = 'Template::Stash::Context'; # Don't use Template::Stash::XS as we can't currently get a hash back out of it + $self->{template} = Template->new({ + 'CONTEXT' => PLIF::Service::TemplateToolkit::Context->new($app), + }); } sub expand { my $self = shift; - my($app, $output, $session, $protocol, $string, $data, $type) = @_; - local $Template::Config::STASH = 'Template::Stash::Context'; # Don't use Template::Stash::XS as we can't currently get a hash back out of it - my $template = Template->new({ - 'CONTEXT' => PLIF::Service::TemplateToolkit::Context->new($app, $output, $session, $protocol), - }); + my($args) = @_; my $document; - if ($type eq 'TemplateToolkitCompiled') { - # what we have here is a potential Template::Document - # let's try to evaluate it - $document = eval $string; - if ($@) { - $self->error(1, "Error loading compiled template: $@"); + if (exists $CACHE{$args->{'name'}}) { + $document = $CACHE{$args->{'name'}}; + } else { + if ($args->{'type'} eq 'TemplateToolkitCompiled') { + # what we have here is a potential Template::Document + # let's try to evaluate it + $document = eval $args->{'string'}; + if ($@) { + $self->error(1, "Error loading compiled template: $@"); + } + $CACHE{$args->{'name'}} = $document; + } else { # $type eq 'TemplateToolkit' + # what we have is a raw string + $document = \{$args->{'string'}}; } - } else { # $type eq 'TemplateToolkit' - # what we have is a raw string - $document = \$string; } + # $self->{template}->context()->{'__PLIF__output'} = $args->{'output'}; # unused (it's a handle to the dataSource.strings service but we look one up instead of using it directly) + $self->{template}->context()->{'__PLIF__session'} = $args->{'session'}; + $self->{template}->context()->{'__PLIF__protocol'} = $args->{'protocol'}; + $self->{template}->context()->{'__PLIF__app'} = $args->{'app'}; + $self->{template}->context()->{'__PLIF__app_refcount'}++; # ok, let's try to process it - my $result = ''; - if (not $template->process($document, $data, \$result)) { - my $exception = $template->error(); + my $output = ''; + my $result = try { + $self->{template}->process($document, $args->{'data'}, \$output); + } finally { + # prevent circular dependency + if ($self->{template}->context()->{'__PLIF__app_refcount'}-- <= 0) { + $self->{template}->context()->{'__PLIF__app'} = undef; + } + }; + # and now check for errors + if (not $result) { + my $exception = $self->{template}->error(); if ($exception->isa('PLIF::Service::TemplateToolkit::Exception')) { $exception->PLIFException()->raise; } else { $self->error(1, "Error processing template: $exception"); } } - return $result; + $args->{'string'} = $output; } @@ -111,7 +133,7 @@ use vars qw(@ISA $URI_ESCAPES); # subclass the real Context so that we go through PLIF for everything sub new { my $class = shift; - my($app, $output, $session, $protocol) = @_; + my($app) = @_; my $self = $class->SUPER::new({ 'FILTERS' => { 'htmlcomment' => \&html_comment_filter, # for use in an html comment @@ -130,13 +152,6 @@ sub new { 'indentlines' => [\&indent_lines_filter_factory, 1], # different indents on different lines } }); - if (defined($self)) { - # don't worry, this doesn't cause any referential loops, because the Template object is short-lived - $self->{'__PLIF__app'} = $app; - $self->{'__PLIF__output'} = $output; # unused (it's a handle to the dataSource.strings service but we look one up instead of using it directly) - $self->{'__PLIF__session'} = $session; - $self->{'__PLIF__protocol'} = $protocol; - } # else failed return $self; } @@ -212,7 +227,15 @@ sub process { } } # ok, it's not a defined block, do our own thing with it - $result .= $dataSource->getExpandedString($app, $session, $protocol, $string, $self->{'STASH'}); + my $args = { + 'app' => $app, + 'session' => $session, + 'protocol' => $protocol, + 'name' => $string, + 'data' => $self->{'STASH'}, + }; + $dataSource->getExpandedString($args); + $result .= $args->{'string'}; } } diff --git a/mozilla/webtools/PLIF/PLIF/Service/User.pm b/mozilla/webtools/PLIF/PLIF/Service/User.pm index b744f954366..2bed01840a7 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/User.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/User.pm @@ -211,7 +211,7 @@ sub getAddress { my($protocol) = @_; my $field = $self->hasField('contact', $protocol); if (defined($field)) { - return $field->{address}; + return $field->address; } else { return undef; } @@ -237,7 +237,7 @@ sub performFieldChange { return 0; } # perform the change - $self->getFieldByID($fieldID)->data($newData); + $self->getFieldByID($fieldID)->data = $newData; # remove the change from the list of pending changes if ($type == 1) { # XXX HARDCODED CONSTANT ALERT # this is an override change @@ -258,11 +258,11 @@ sub setting { my($variable, $setting) = @_; $self->assert(ref($variable) eq 'SCALAR', 1, 'Internal Error: User object was expecting a scalar ref for setting() but didn\'t get one'); if (defined($$variable)) { - $self->getField('settings', $setting)->data($$variable); + $self->getField('settings', $setting)->data = $$variable; } else { my $field = $self->hasField('settings', $setting); if (defined($field)) { - $$variable = $field->{data}; + $$variable = $field->data; } } } @@ -355,7 +355,7 @@ sub insertField { sub invalidateRights { my $self = shift; my $rights = $self->{app}->getService('dataSource.user')->getRightsForGroups($self->{app}, keys(%{$self->{'groupsByID'}})); - $self->rights({ map {$_ => 1} @$rights }); # map a list of strings into a hash for easy access + $self->{rights} = { map {$_ => 1} @$rights }; # map a list of strings into a hash for easy access # don't set a dirty flag, because rights are merely a convenient # cached expansion of the rights data. Changing this externally # makes no sense -- what rights one has is dependent on what @@ -400,6 +400,18 @@ sub propertyGet { } } +sub implyMethod { + my $self = shift; + my($name, @data) = @_; + if (@data == 1) { + return $self->propertySet($name, @data); + } elsif (@data == 0) { + return $self->propertyGet($name); + } else { + return $self->SUPER::implyMethod(@_); + } +} + sub DESTROY { my $self = shift; if ($self->{'_DIRTY'}->{'properties'}) { @@ -408,7 +420,6 @@ sub DESTROY { if ($self->{'_DIRTY'}->{'groups'}) { $self->writeGroups(); } - $self->SUPER::DESTROY(@_); } sub writeProperties { diff --git a/mozilla/webtools/PLIF/PLIF/Service/UserField.pm b/mozilla/webtools/PLIF/PLIF/Service/UserField.pm index fdb073a76f1..fffecfad829 100644 --- a/mozilla/webtools/PLIF/PLIF/Service/UserField.pm +++ b/mozilla/webtools/PLIF/PLIF/Service/UserField.pm @@ -162,7 +162,6 @@ sub DESTROY { if ($self->{'_DIRTY'}) { $self->write(); } - $self->SUPER::DESTROY(@_); } sub write { diff --git a/mozilla/webtools/PLIF/compile-templates.pl b/mozilla/webtools/PLIF/compile-templates.pl index 0f8f8d3e808..543a7123a14 100644 --- a/mozilla/webtools/PLIF/compile-templates.pl +++ b/mozilla/webtools/PLIF/compile-templates.pl @@ -7,7 +7,7 @@ my @entries = ('output'); while (@entries) { my $file = pop @entries; if (-d $file) { - print "$file: recursing...\n"; + # print "$file: recursing...\n"; my $dir = $file; $dir =~ s/^output/output-compiled/os; mkdir($dir);