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.

This commit is contained in:
ian%hixie.ch 2001-09-19 17:56:15 +00:00
Родитель dfdc492a06
Коммит f21e5053e8
2 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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;