Gossamer Forum
Quote Reply
Creating a hook
It seems that to create a new hook, all you need to do is add:

Code:
$PLG->dispatch('hook_name', \&sub_to_run)


where you want it? Is that true?

And, secondly, in the handle routine, is this the preferred format now (calling the plugin dispatch, then re-assigning $in in the routine, )

Code:
sub handle {
# ------------------------------------------------------------------
# Determine what to do.
#
my $input = $IN->get_hash;
if ($input->{add_review}) { $PLG->dispatch('review_add', \&add_review) }
elsif ($input->{edit_review}) { $PLG->dispatch('review_edit', \&edit_review) }
elsif ($input->{helpful}) { $PLG->dispatch('review_helpful', \&helpful_review) }
else { $PLG->dispatch('review_search', \&review_search_results) }
return;
}
# ==================================================================
Then, in the sub, my $in = $IN->get_hash; ## assign the $in data to the local variable, again



Or, is this way just as acceptable, and in some cases, more logical,

Code:
my $input = $IN->get_hash;
if ($input->{add_review}) { &add_review($input) }
elsif ($input->{edit_review}) { &edit_review($input) }
elsif ($input->{helpful}) { &helpful_review($input) }
else { review_search_results($input) }
return;
sub add_review {
my $in = shift;
$PLG->dispatch('review_add', \&add_review);........
}



Or, basically, make everything go through the handle routine, not bypass it, and
pass the $IN tags into the subroutines, rather than relying on them to get them,
or make "external" requests on their own.

Each sub would "logically" be responsible for checking if it had any plugin actions.

It seems to me that while the first example is "cooler", the second way is more
logical, and all passed-in params are up front, rather than spread throughout the
module.

The second way, also seems more "object oriented" since it's "contained". The call
to the plugin dispatch is not missed if "handle" is bypassed, and $in is passed in
no matter how it's gotten -- whether it's actually from $IN or from another source.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Subject Author Views Date
Thread Creating a hook pugdog 2546 Apr 4, 2005, 6:57 PM
Thread Re: [pugdog] Creating a hook
webmaster33 2473 Apr 10, 2005, 3:40 AM
Thread Re: [webmaster33] Creating a hook
pugdog 2460 Apr 10, 2005, 7:42 AM
Thread Re: [pugdog] Creating a hook
webmaster33 2473 Apr 10, 2005, 8:25 AM
Thread Re: [webmaster33] Creating a hook
pugdog 2456 Apr 10, 2005, 12:03 PM
Thread Re: [pugdog] Creating a hook
webmaster33 2444 Apr 10, 2005, 3:25 PM
Thread Re: [webmaster33] Creating a hook
pugdog 2448 Apr 10, 2005, 3:53 PM
Thread Re: [pugdog] Creating a hook
webmaster33 2457 Apr 10, 2005, 4:52 PM
Thread Re: [webmaster33] Creating a hook
pugdog 2436 Apr 10, 2005, 8:09 PM
Thread Re: [pugdog] Creating a hook
webmaster33 2447 Apr 10, 2005, 9:25 PM
Thread Re: [webmaster33] Creating a hook
pugdog 2434 Apr 11, 2005, 10:20 AM
Post Re: [pugdog] Creating a hook
webmaster33 2420 Apr 12, 2005, 10:49 AM