Gossamer Forum
Quote Reply
Hook Question
Ahhh, just when I thought I understood hooks, I don't.

I am trying to trap the event where the admin validates a link (not rejects) and extract the link id of the newly validated link:

Using: 'validate_link', 'POST'

my (@args) = @_;

blah???

return @args;

There is no dispatch reference in tools.pm (like GT::Plugins->dispatch ( $CFG->{admin_root_path} . '/Plugins', 'add_link', sub { return $self->_plg_add (@_); }, $p ); )

so firstly, how do I know what is dispatched to @args? I assume this is everything that is included in the return statement for the sub (in this case _validate).

Secondly, I can't remember how to print out the contents of @args when I have no idea what is in it. other than a hash.

In this case I want the link id.

References:




Code:
'validate_link' => [
{
'subroutine' => 'Links::Tools::_validate',
'filename' => 'Links/Tools.pm',
'hook_name' => 'validate_link',
'input_params' => [
'HASH'
],
'description' => '',
'output_params' => [],
'line' => '415',
'path' => './Plugins'
}
ConfusedUnsure


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Aug 1, 2002, 10:37 PM
Quote Reply
Re: [Ian] Hook Question In reply to
I always put use GT::Dumper at the top of my modules while I am developping.

In the sub that gets called by the hook, put

my (@args) = @_;
print $IN->header; # might be necessary
print Dumper(\@args);
return @args;

Basically Dumper() takes a reference as its argument, so just make your input into a reference.

But, looking at the code in Links/Tools.pm , it looks like @args is empty unless there is an error, so it won't print much. So you might have to set a pre hook (where you can easily get the ID), and then in the post hook you'd have to check if there is an error, and if not do what you want to do (with the ID you got from the pre hook).

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Hook Question In reply to
Thanks very much for the explaination IvanSmile

If I didn't no better, this looks like a forgetton about hook. Validating a link seems like a useful place to hook into for a number of reasons, maybe GT could include the Link ID in a future version of links. (Unless I am misunderstanding).

GT Dumper looks good, I'll try this for other hooks.

For this hook, I think I follow what you are saying.... I should change to a pre_hook, where I can easily trap the Link ID, but then pass the value to the post_hook for use. That makes sense.

Can I pass this value simply by 'push'ing it onto the return, and then 'shift'ing it back off at the start of the post, or might there be a better way to move values between pre and post hooks?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [yogi] Hook Question In reply to
In order to be able to dump and see the contents of args for the pre hook I had to add GT::Plugins->action ( STOP ); Crazy

I can see all the values there now thoughSmile

Example:

Code:
$VAR = [ { 'Description' => 'Test', etc

Just got to pass the id now, in fact the LinkOwner is there so this will be more useful to me in this case.

I could use a global variable, but it would be better to pass the value to the post hook through the return I think.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Aug 2, 2002, 10:09 AM