Gossamer Forum
Home : Products : DBMan SQL : Development, Plugins and Globals :

Question about GT::Plugins::dispatch_method()

Quote Reply
Question about GT::Plugins::dispatch_method()
Hi,

Can anyone explain me why the inner-pre-hook loop of the subroutineGT::Plugins::dispatch_method (line 157 in version 1.43) looks like this:
Code:
if (exists $PLUGIN_CFG->{_pre_hooks}->{$hook_name}) {
$self->debug ("Plugin: pre $hook_name running => $hook")
if ($self->{_debug});
defined &{$hook} or $self->_load_hook ($hook, 'PRE') or next;
$ACTION = CONTINUE;
@results = $hook->($object, @args);
$ACTION == STOP and last;
}
unless ($ACTION == STOP) {
@results = $object->$method(@args);
}

and not like this
Code:
if (exists $PLUGIN_CFG->{_pre_hooks}->{$hook_name}) {
$self->debug ("Plugin: pre $hook_name running => $hook")
if ($self->{_debug});
defined &{$hook} or $self->_load_hook ($hook, 'PRE') or next;
$ACTION = CONTINUE;
@args = $hook->($object, @args);
$ACTION == STOP and last;
}
if ($ACTION == STOP) {
@results = @args;
} else {
@results = $object->$method(@args);
}



Thanks, Jasper

http://www.bookings.org

Last edited by:

jaspercram: Nov 20, 2002, 4:26 AM
Quote Reply
Re: [jaspercram] Question about GT::Plugins::dispatch_method() In reply to
If @args contains references to data, then it doesn't matter, otherwise it does.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [jaspercram] Question about GT::Plugins::dispatch_method() In reply to
Hi,

I don't know who moved this thread from 'General Perl' to here, but I am using DBMan SQL. As this question is moved to Links SQL, does that mean that all general GT code is discussed here? Seems a bit inconvenient because I have to filter out all posts about Links SQL.

Thanks, Jasper

http://www.bookings.org
Quote Reply
Re: [jaspercram] Question about GT::Plugins::dispatch_method() In reply to
I moved it here because I thought you were using Links SQL. I didn't really see it as a general perl question as it was product specific. I've moved it to the DBMAN SQL plugins forum.

Last edited by:

Paul: Nov 21, 2002, 2:05 AM
Quote Reply
Re: [jaspercram] Question about GT::Plugins::dispatch_method() In reply to
Hi,

No, I don't think I can explain. =) It should probably look like:

Code:
my @results = @args;
if (exists $PLUGIN_CFG->{_pre_hooks}->{$hook_name}) {
local $^W; no strict 'refs';
foreach my $hook (@{$PLUGIN_CFG->{_pre_hooks}->{$hook_name}}) {
$self->debug ("Plugin: pre $hook_name running => $hook") if ($self->{_debug});
defined &{$hook} or $self->_load_hook ($hook, 'PRE') or next;
$ACTION = CONTINUE;
@results = $hook->(@results);
if ($ACTION == STOP) {
$self->debug ("Plugin pre $hook_name stopped further plugins.");
last;
}
}
unless ($ACTION == STOP) {
@results = $code->(@results);
}
}
else {
@results = $code->(@results);
}


So plugins alter the input of the next plugin, but without the ability to specify order of plugins, that could cause problems.

Also, I'm a little scared about how this may break existing pre hook plugins out there that aren't doing the right thing and returning the proper arguments.

You could change the value of the input by modifying it directly:

$_[0] = "new input";

This should alter the input for the main code that is run.

Hope that helps,

Alex
--
Gossamer Threads Inc.