mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-18 06:45:33 +00:00
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.
This commit is contained in:
parent
a7154a78df
commit
56529c19a2
@ -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...");
|
||||
#}
|
||||
|
@ -262,7 +262,6 @@ sub DESTROY {
|
||||
' services registered, of which ' .
|
||||
scalar(keys(%{$self->{servicesHash}})) .
|
||||
' had been placed in the services hash.');
|
||||
$self->SUPER::DESTROY(@_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 <<here document string.
|
||||
# So a single literal slash in a regexp requires eight backslashes.
|
||||
return ('TemplateToolkit', '1', <<eof);
|
||||
$args->{'type'} = 'TemplateToolkit';
|
||||
$args->{'version'} = 1;
|
||||
$args->{'string'} = <<eof;
|
||||
[%-
|
||||
|
||||
MACRO debugDumpVarsEscape(key) BLOCK;
|
||||
@ -145,7 +147,7 @@ sub getDefaultString {
|
||||
|
||||
-%]
|
||||
eof
|
||||
} else {
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -61,19 +61,19 @@ __DATA__
|
||||
|
||||
sub getDefaultString {
|
||||
my $self = shift;
|
||||
my($app, $protocol, $string) = @_;
|
||||
my($args) = @_;
|
||||
my @filenames = ();
|
||||
# XXX THIS IS PLATFORM SPECIFIC CODE XXX
|
||||
if ($^O eq 'linux') {
|
||||
foreach my $piece ($protocol, $string) {
|
||||
foreach my $piece ($args->{'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;
|
||||
<FILE> =~ 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;
|
||||
}
|
||||
|
@ -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', '<text>Note: The following strings have had their defaults updated since you last customised them:<br/><set variable="string" value="(oldStrings)" source="values" order="lexical"><text value="string (string.3) in variant (string.1)"/> (<text value="protocol (string.2)"/>): yours=<text value="(string.4)"/>, new=<text value="(string.5)"/><br/></set></text>')
|
||||
my($args) = @_;
|
||||
if ($args->{'protocol'} eq 'stdout') {
|
||||
if ($args->{'name'} eq 'setup.newStringsReport') {
|
||||
$args->{'type'} = 'COSES';
|
||||
$args->{'version'} = 1;
|
||||
$args->{'string'} = '<text>Note: The following strings have had their defaults updated since you last customised them:<br/><set variable="string" value="(oldStrings)" source="values" order="lexical"><text value="string (string.3) in variant (string.1)"/> (<text value="protocol (string.2)"/>): yours=<text value="(string.4)"/>, new=<text value="(string.5)"/><br/></set></text>';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return; # nope, sorry
|
||||
|
@ -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);
|
||||
|
@ -136,7 +136,6 @@ sub DESTROY {
|
||||
if ($self->{'_DIRTY'}) {
|
||||
$self->write();
|
||||
}
|
||||
$self->SUPER::DESTROY(@_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -309,5 +309,4 @@ sub setupConfigureDatabase {
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
$self->closeDB(@_);
|
||||
$self->SUPER::DESTROY(@_);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -156,7 +156,6 @@ sub checkAddress {
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
$self->close();
|
||||
$self->SUPER::DESTROY(@_);
|
||||
}
|
||||
|
||||
# dataSource.configuration.client
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 ();
|
||||
}
|
@ -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', '<text xmlns="http://bugzilla.mozilla.org/coses"><if lvalue="(failed)" condition="=" rvalue="1">Can\'t continue: argument <text value="(result)"/> is missing.</if><else>Succeeded!</else><br/></text>');
|
||||
my($args) = @_;
|
||||
if ($args->{'protocol'} eq 'stdout') {
|
||||
if ($args->{'name'} eq 'setup') {
|
||||
$args->{'type'} = 'COSES';
|
||||
$args->{'version'} = 1;
|
||||
$args->{'string'} = '<text xmlns="http://bugzilla.mozilla.org/coses"><if lvalue="(failed)" condition="=" rvalue="1">Can\'t continue: argument <text value="(result)"/> is missing.</if><else>Succeeded!</else><br/></text>';
|
||||
return 1;
|
||||
} elsif ($string eq 'setup.progress') {
|
||||
return ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Setup: <text value="(component)"/>...<br/></text>');
|
||||
$args->{'type'} = 'COSES';
|
||||
$args->{'version'} = 1;
|
||||
$args->{'string'} = '<text xmlns="http://bugzilla.mozilla.org/coses">Setup: <text value="(component)"/>...<br/></text>';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return; # nope, sorry
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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', '<text xmlns="http://bugzilla.mozilla.org/coses">Acknowledged.<br/></text>');
|
||||
} elsif ($string eq 'request') {
|
||||
return ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">\'<text value="(argument)"/>\'<if lvalue="(defaults.length)" condition=">" rvalue="0"> (default: \'<set variable="default" value="(defaults)" source="keys" order="default"><text value="(defaults.(default))"/><if lvalue="(default)" condition="!=" rvalue="0">\', \'</if></set>\')</if>? </text>');
|
||||
} elsif ($string eq 'error') {
|
||||
return ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Error:<br/><text value="(error)"/><br/></text>');
|
||||
if ($args->{'protocol'} eq 'stdout') {
|
||||
if ($args->{'name'} eq 'acknowledge') {
|
||||
$args->{'string'} = ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Acknowledged.<br/></text>');
|
||||
} elsif ($args->{'name'} eq 'request') {
|
||||
$args->{'string'} = ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">\'<text value="(argument)"/>\'<if lvalue="(defaults.length)" condition=">" rvalue="0"> (default: \'<set variable="default" value="(defaults)" source="keys" order="default"><text value="(defaults.(default))"/><if lvalue="(default)" condition="!=" rvalue="0">\', \'</if></set>\')</if>? </text>');
|
||||
} elsif ($args->{'name'} eq 'error') {
|
||||
$args->{'string'} = ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Error:<br/><text value="(error)"/><br/></text>');
|
||||
}
|
||||
} elsif ($protocol eq 'http') {
|
||||
if ($string eq 'acknowledge') {
|
||||
return ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Status: 200 OK<br/>Content-Type: text/plain<br/><br/>Acknowledged.</text>');
|
||||
} elsif ($string eq 'error') {
|
||||
return ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Status: 500 Internal Error<br/>Content-Type: text/plain<br/><br/>Error:<br/><text value="(error)"/></text>');
|
||||
} elsif ($args->{'protocol'} eq 'http') {
|
||||
if ($args->{'name'} eq 'acknowledge') {
|
||||
$args->{'string'} = ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Status: 200 OK<br/>Content-Type: text/plain<br/><br/>Acknowledged.</text>');
|
||||
} elsif ($args->{'name'} eq 'error') {
|
||||
$args->{'string'} = ('COSES', '1', '<text xmlns="http://bugzilla.mozilla.org/coses">Status: 500 Internal Error<br/>Content-Type: text/plain<br/><br/>Error:<br/><text value="(error)"/></text>');
|
||||
}
|
||||
}
|
||||
return; # nope, sorry
|
||||
}
|
||||
|
@ -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'};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -162,7 +162,6 @@ sub DESTROY {
|
||||
if ($self->{'_DIRTY'}) {
|
||||
$self->write();
|
||||
}
|
||||
$self->SUPER::DESTROY(@_);
|
||||
}
|
||||
|
||||
sub write {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user