Gossamer Forum
Quote Reply
Can't find Hook
My hooks.cfg does not contain any "editor" handling hooks. And it is my understanding that this does not matter, as I can still use any hooks that are referenced in the actual modules.

I want to tap (hook) into the "sub category_related_form" of Browser.pm, more specifically the action of adding or deleting an editor to or from a category.

Webmaster33 suggested a handle_editor hook to me quite a few posts ago. But I am not sure this is the one which will handle this. I am having trouble pinning the exact hook which will do this.

Any suggestions?


EDIT: I notice at the beginning of each function:

$SUBS{category_editors_form} = <<'END_OF_SUB';
sub category_editors_form {


Is the $SUBS part referring to a HOOK that I can use? If so, how can I determine what are the @args passed to the hook, when this function is not listed in hooks.cfg?


Thank you


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

Last edited by:

Ian: Jun 9, 2002, 8:09 PM
Quote Reply
Re: [Ian] Can't find Hook In reply to
It seems that the only hook you can use at the moment is the handle_editor hook.

As much as I am in favour of using plugins, I think it might not be a good idea in this case. I think you should just apply the changes directly to the subs in Browser.pm (make sure you keep a backup copy, an original, and also document your changes well, keep a change log).

The $SUBS part is just to speed up things (compile subs on demand, see the AUTOLOAD function).

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Can't find Hook In reply to
Hi Ivan,

It would be nice if GT put a hook in here, as this is for my editor plug-in, and I don't really want everyone to modify their pm filesUnsure.

Thanks for the explanation of the $SUBS. Very interesting.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Can't find Hook In reply to
I agree as a "non" programmer I really would not like to have to mess with the workings of LinksSQL. It makes me uneasy doing that. Unsure
Quote Reply
Re: [Ian] Can't find Hook In reply to
The more hooks you have, the slower the program will run. Granted,in something like the editors area, where it's not a high-demand or high-performance block of code, it won't matter much.

You can always use a patch-type utility to modify the links .pm file you need. That gets somewhat more complicated, but not terribly so, if the subroutine you want to modify doesn't change name, and you insert the same piece of code in the same place.

I haven't looked at your editors code to see what you are trying to do with it, but I've found in my own programming, it sometimes pays to rewrite a block of code you call from within your own scripts, than to try to plug in to the Links system. Not only does it save time and frustration, it can cut down on the number of nested calls being made as well.

A hook is really one line of code, that sends the program off to wrap the default code in a series of routines that allow other code to be run if it exists. All this requires overhead and checks, and of course program execution if code exists.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Can't find Hook In reply to
Hi Pugdog, thanks for the reply.

I understand what you are saying, and I can appreciate how multiple hooks can have its effects on performance. It is a shame that this is the last part of links I want to tap into, and it is the one without the hook. I am not sure how else you can trap this type of event without it orginating out of the Links code in this case.

I honestly think a patch program is beyond my capabilities (at this stage anyways).

I may have to hold off and hope that maybe this section of links could inlcude a new hook. It is not essential to my plug-in, but it would sure make a lot more things possible.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Can't find Hook In reply to
Hi Ian,

Unfortunately there is only one hook available to you, 'handle_editor'. This allows you to override the editor function completely, but not at the level of control you want.

Your best bet might be to put a global on the template you want to affect. What change do you want to take place?

Quote:
EDIT: I notice at the beginning of each function:

$SUBS{category_editors_form} = <<'END_OF_SUB';
sub category_editors_form {


No, these are autoloaded functions, something entirely different. It's a speed enhancement we use so that code that is never used, never even gets compiled by perl.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Can't find Hook In reply to
Quote:
What change do you want to take place?


Hi Alex,

I want to trap the action of adding or deleting an editor to or from a category. This allows my plugin to automatically assign the same editor to my custom editor tracking table, and tells it to start watching them. At the moment, every time you add or remove an editor completely, I have to run a "Repair" function which scans the Editors table for new or removed editors and their category re-assignments.

I hope that makes sense. Are you planning on adding any additional hooks for the editor functions?

Thanks.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Can't find Hook In reply to
Hi Ian,

Hmm, one neat way to approach this is with the subclass feature of GT::SQL. How's your OO programming? =)

Basically, you can subclass a table by doing:

my $table = $DB->table('TableName');
$table->subclass( table => { TableName => 'Plugins::EditorMonitor::Table' });
$table->save_state;

and create a file Table.pm in the Plugins/EditorMonitor directory with:

use strict;
use GT::SQL::Table;
use vars qw /@ISA/[/url];
@ISA = qw/GT::SQL::Table/;

Now, whenever you call:

my $table = $DB->table('TableName');

you get a Plugins::EditorMonitor::Table object, not a GT::SQL::Table object. The advantadge here is that you can replace functions easily. You can add:

sub insert {
my $self = shift;
my $editor = shift;
my $results = $self->SUPER::insert($editor);
if ($results) {
# A new editor has been successfully added.
...
}
return $results;
}

The tricky part is the $self->SUPER::insert. All this means is to run the main code. Basically this is part of object oriented programming. Have a look through:

http://perldoc.com/....1/pod/perlboot.html

to give you some ideas of how this is all coming together.

If this all seems a bit much (and it may well be overkill as well), another thing you could do is just add a template tag to browser_category_editors_form.html like <%Plugins::EditorMonitor::some_func%> that looks at the tags on the page, and figures out if an editor has been added or delted (use <%GT::Template::dump%> here to see what you need to look for).

Hope this helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Can't find Hook In reply to
Hi Alex,

Well I understood about 70% of what you are doing with the subclass. I do understand the concept of oo and inheritence, just not the style of it with perl I suppose. This is a post I will definetaly have to read over a fair bit before diving into it.

Your idea of the tags does sound simpler, however it may not be as useful as the formentioned subclass suggestion. Both are worthy of looking into. Thanks for the suggestions and example.

I will be back in this thread!

Many thanks again.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Alex] Can't find Hook In reply to
For those of us a bit slow...

This is a cool feature :) But in Ian's case, I think I'm missing how this will intercept the call he wants.

In your own code, a function can be subclassed, and intercepted, but how does this hook into the main links code, so that when a template requests the function, rather than being passed through to the main function, it gets taken by the over-ridden function? I thought that is what the "hook" was for. Control was passed, program flow was diverted.

At what point do you divert the program flow from the default table/table_object to the new one?

In otherwords, I can see how this would work if I was capturing the form submit in my own files, but not how it works when passed through to the default links code.

This is the same problem (sort of) I've been having with aspects of the other programs I've been trying to get to work, mostly with admin features which don't have hooks.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Can't find Hook In reply to
Hi,

If you subclass a table, then anytime you call:

my $table = $DB->table('TableName');

$table will be subclassed. So if you subclass the Editor table, then anywhere in the Links SQL code, or anywhere in any code that gets its table from $DB->table(), it will invoke your code.

This has the benefit of catching the browser adds, as well as any other places that you might insert editors.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Can't find Hook In reply to
Hi Alex,

Please expect a couple of dumb questions coming up.

Where should I create the subclass:

my $table = $DB->table('TableName');
$table->subclass( table => { TableName => 'Plugins::EditorMonitor::Table' });
$table->save_state;


Should this by in my install.pm? or in the newly created module... sorry , I am a little confused about setting it up.

EDIT:

Quote:
then anywhere in the Links SQL code, or anywhere in any code that gets its table from $DB->table(), it will invoke your code.
I should really keep what ever function it calls to a minimum then. Basically retreive the values I need at this point and store them in my other Editors Table (EditorDetails).


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

Last edited by:

Ian: Jun 11, 2002, 9:24 PM
Quote Reply
Re: [Ian] Can't find Hook In reply to
Hi Ian,

you subclass the table in Install.pm. You have to do that only once.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Can't find Hook In reply to
Thanks Ivan. Have you tried this suggestion out yourself?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Can't find Hook In reply to
Yes, for my upcoming PageBuilder plugin.

1. subclass HTML.
Pages can be related to one another through a hierarchy, like the categories in LInks SQL. I subclass the page information table to get a better display for the category structure (i.e. a select field for the add/modify form), very similar to what Jason does in GForum.

2. subclass Table.
Every time a user creates a page, it will automatically create a template for this type of page in the relevant template set directory.

I am also new to it, but it looks like a lot of fun!

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Can't find Hook In reply to
Well, watch this thread... I will be implementing this into my Editors plug-in... as it seems to be the ONLY way I can do some things.

You seem to have a good grasp of it at least. I'll post back once I have added the subclass creation to my install.pm and made the new module file.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Alex] Can't find Hook In reply to
OK,

One more question for the subtle things <G>

In the new subclassed object, if a method does not exist, the one from the base class is called, right?

In the new subclassed object, if a method DOES exist, the one from the base class will not be called.

In the new subclassed object, if a method such as the example 'insert" existed, and all you want to do is play some games with it before or after the default method was called, you do your stuff and call the SUPER:: method to run the base code at the point you want.

My *real* question...

Has links, etc, been cleaned up (or will) so that the display options are always a separate call from a "do work" function? There have been a lot of changes in recent releases, but I wonder if this has been a specific plan.

This sort of overloading functions and subs will be nice, as long as functions that do "WORK", all pass back a hash ref that has not yet been sent to the display routines.

I guess, in effect, every function would be similar to a plugin call, and only the final, before-you-exit code checks to see if something needs to be displayed, then sends the data off to do it.

Something like only *.cgi files call the print routines. Other functions can parse template/code fragments, but you know where to look for them (as a tag in the returned hash). Nothing gets printed to the user until the final pre-exit code in the calling .cgi.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Can't find Hook In reply to
Hi,

Quote:
In the new subclassed object, if a method does not exist, the one from the base class is called, right?


Correct. Perl will use inheritance and look at the modules parent to run the method.

Quote:
In the new subclassed object, if a method DOES exist, the one from the base class will not be called.


Correct. You can call it yourself by using $self->SUPER::method() in your own method if you need to access it.

Can you explain a bit more your display questions? There are two places that links are displayed.

1. In GT::SQL::Display::HTML. This controls the display of a link in the admin area, you can't subclass this as it is already subclassed by Links::Link. However, you could get it to work if your subclass inherits froms Links::Link. There are plugin hooks to override this display.

2. The link.html template. This is pluggable using site_html_link.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Can't find Hook In reply to
My display question was about the functions themselves calling the disply routines -- outside the reach of the wrap around function.

A function can do something, return a success page, and an error code that says success, and the script exits.

That creates a problem for the subclassing.

Pretty much, you want the .cgi program to call the routines, then when they are done, print them out. You don't want the routines printing the results, or you may not be able to intercept them properly.

I realize this may not be clear, but it's a matter of program flow. If an intermediate routine calls a display/print routine, the wrap around function won't be able to intercept or alter it.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [Alex] Can't find Hook In reply to
Trying to understand this way of subclassing:

Alex wrote:
Basically, you can subclass a table by doing:

my $table = $DB->table('TableName');
$table->subclass( table => { TableName => 'Plugins::EditorMonitor::Table' });
$table->save_state;

Where should you put this code?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Can't find Hook In reply to
You run that snippet of code once, and the table subclass is set up. So for a plugin, you'd probably do it on install (don't forget to remove it on uninstall).

Adrian
Quote Reply
Re: [brewt] Can't find Hook In reply to
Ok, so if I understand correctly, I can even put it into add.cgi after the use lines.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Can't find Hook In reply to
You could, but you shouldn't as it will add the subclass every time. Also note that doing that will overwrite any existing subclasses, so your code should probably check for any existing ones (I haven't had a good look at the code, but it looks like you can't have multiple subclasses on the same table).

Adrian