From f21e5053e814881ff2221abcd61c4549c2719111 Mon Sep 17 00:00:00 2001 From: "ian%hixie.ch" Date: Wed, 19 Sep 2001 17:56:15 +0000 Subject: [PATCH] Corrected an oversight in the service instance creation code: if a service acts as both a service instance and a normal service, it needs a special constructor to force the creation of the instance, otherwise if the service is created first it will be used again for the instances. --- webtools/PLIF/PLIF.pm | 17 +++++++++++++++-- webtools/PLIF/PLIF/Controller.pm | 15 ++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/webtools/PLIF/PLIF.pm b/webtools/PLIF/PLIF.pm index 68a15ec478a9..c449a5e81148 100644 --- a/webtools/PLIF/PLIF.pm +++ b/webtools/PLIF/PLIF.pm @@ -70,7 +70,20 @@ sub create { } } -sub init {} # stub +# provide a constructor that always constructs a new copy of the +# class. This is used to create service instances. +sub serviceCreate { + my $class = shift; + if (ref($class)) { + $class = ref($class); + } + $class->dump(10, "Called service constructor of class $class, creating object..."); + my $self = $class->bless(@_); # call our real constructor + $self->init(@_); + return $self; +} + +sub init {} # stub for services # provide a constructor that always constructs a new copy of the # class. This is used by services that implement factories for objects @@ -86,7 +99,7 @@ sub objectCreate { return $self; } -sub objectInit {} # stub +sub objectInit {} # stub for objects # internals of create and objectCreate sub bless { diff --git a/webtools/PLIF/PLIF/Controller.pm b/webtools/PLIF/PLIF/Controller.pm index 1c9d58830074..a27b1e4a6777 100644 --- a/webtools/PLIF/PLIF/Controller.pm +++ b/webtools/PLIF/PLIF/Controller.pm @@ -74,12 +74,14 @@ sub register { } } -# helper method for input verifiers to add instantiated service +# helper method for (e.g.) input verifiers to add instantiated service # objects specific to the current state (e.g. the current user in an -# event loop). These should be wiped out when the state changes -# (e.g. at the start of an event loop). -# Objects should be created with $service->createObject(), not -# with $app->getServiceInstance(). +# event loop). These should be wiped out when the state changes (e.g. +# at the start of an event loop). +# +# Objects should be created with $service->createObject(), not with +# $app->getServiceInstance(), because they end up calling different +# constructors -- init() vs objectInit(). sub addObject { my $self = shift; foreach my $object (@_) { @@ -200,8 +202,7 @@ sub getServiceInstance { # the service is being held by us, so the moment the # service goes out of scope, it will be freed. # IMPORTANT! DON'T HOLD ON TO A SERVICE INSTANCE OBJECT! - local $" = '\', \''; - return $service->create($self, @data); + return $service->serviceCreate($self, @data); } } return undef;