Gossamer Forum
Quote Reply
Plug-ins
Alex,

I'm trying to figure out the plugins. The code you sent helped a lot!

Conceptually, the plug-ins configuration has 4 areas?

1) menu - entries on the plug-ins admin menu
2) meta -- meta info/"about"
3) hooks -- list of connections
4) version -- (not really an area, just a version number)
5) user -- configuration variables --

My real question, is the configuration variables are passed via the $CFG hash? Is that how they are made available to the program?

If so, then module & plug-in conflicts are bound to occur.

Has some convention been developed to handle that?

Because the configuration variables all share the same namespace, some sort of convention has to be agreed because common things such as paths, colors or nams will start to conflict.

One way, I guess, would be to make a new CFG variable PLUGIN, which was a hash of hashes of configuration values. Because it's 2 dimentional, there should be no name-space conflicts, and authors would have to use $PLUGIN->{PluginName}{Key} to get to them.

Another way, is like some of the software development systems have, is to register a prefix for your mods, and all your mods use that as their reserved signature. In my case, it would be pugdog_ It would be relatively easy to trim off anything preceeding the first _ as the author prefix, if you needed to automatically generate "clean" names for the variables.

Right now, I'm still trying to figure out how the plug-ins plug in <G> but I can see that this sort of collision is bound to occur if some development and deployment rules are not used early on.

If a configuration space is going to be shared, like $CFG, even programs and modules from GT should try to adhere to some organizational convention such as Links_, GossMail_, Myman_ etc. That way, as integration occurs, <%db_cgi_url%> would be <%links_db_cgi_url%> or <%GM_db_cgi_url%> etc.

I may be missing something, but the prefix_ option, or the hash of hashes seem to be the only two really reasonable alternatives. When a module initializes, it looks for $PLUGINS->{ModuleName} and takes a slice of the hash with it's associated configuration parameters.

In reality, modules would _NOT_ share configuration variables, unless they knew about each other before hand, and in that case, they will follow certain rules (such as initializing if the $PLUGINS->{OtherModuleName} hash exists), but if the configuration options are being loaded at startup, and $CFG is global, then some separation of the various modules configurations parameters needs to exist, even if it's only relevant at initialization...

Am I making sense, or should I have gone to bed?? <G>


PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: Plug-ins In reply to
Maybe I am missing something:

my $cfg = Links::Plugins::get_plugin_user_cfg ('ModuleName');

It looks like the plugins are initialized when called? and the hash-slice is returned on request, rather than being pre-loaded? How is this affected with mod_perl and speedyCGI now?

If so, how is plug-in intialization handled? With links, it's the

use Links qw / ... / statement.

is the above line the equivalent initialization routine? Unless $cfg was declared globally, you'd have to do this request in each subroutine that needed the configuration variables, or you'd be running into problems with mod_perl and speedy_cgi with the lexical scoping of "global" "my" variables and persistence inside the routines into which they were passed ....

..... I think I am too tired. Maybe it will all be clear after sleep.



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
While on Plug-ins In reply to
How about allowing template files be included with plugins? I know I really need to bundle some admin templates as well as some default templates with my project...

I for one really don't want to be writing all my html in the plugin's cgi. This is especially true for some of the more advanced creations that could be made with this plugin system.

ALEX - Any chance of a few additions to the "Place" drop down box on Plugin Wizard Step 6? Admin Templates and Default Templates ?

It would make things ALOT easier...

Alex-J

Quote Reply
Re: Plug-ins In reply to
In Reply To:
My real question, is the configuration variables are passed via the $CFG hash? Is that how they are made available to the program?
No, $CFG is the program configuration. A plugin author can get it's own configuration by calling:

my $config = Links::Plugins->get_plugin_cfg ('YourModule');

and you will get a hash reference of your config options. They are not mixed in with the program config.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: While on Plug-ins In reply to
Hi,

Currently the place does not do anything and we are most likely going to remove it. Placing a file is very easy, and something you can do in your install routine. Passed into the install function is a GT::Plugins::Installer object and a GT::Tar object.

The tar object has all your files in it. So during install, to extract your template and place it in the users admin directory you would do:

my $file = $tar->files ('my_plugin_admin_tempalte.html');
$file->name ($CFG->{admin_root_path} . '/templates/admin/my_plugin_admin_template.html');
$file->write;

What that does is $tar->files ('name') returns a GT::Tar::File object for that file. Then you change the name of where it should be saved, and then do $file->write to extract and create the file.

Does that make sense? It's probably going to allow more flexibility this way, and with enough documentation it will be better.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Plug-ins In reply to
Ok,

I'm starting to figure this out.

I still think the plug-in needs to set it's own configuration file as a local global, so that it's available throughout the .pm file via the use vars statement.

I sent you a longish reply to the shortish one, since I may be misunderstanding something about the my() scoping.

Basically, it seems to be a _BAD_THING_ to declare my() variables outside a subroutine ie: in the .pm or .cgi file itself, since normal lexical scoping rules seem to break down if the value is subsequently used inside a subroutine without being explicitly passed.


PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ


Quote Reply
Re: While on Plug-ins In reply to
Alex -

Thats great. I like that flexibility even better! Complete docs on the plugin feature would most likely ease our pain... :)

I've had an odd problem develop from your reply. I've had no problem installing any plugins before, from your site, or ones I've been working on. I've also never added any files to my plugins. I added your code to my functioning plugin, and added a template to it as well, uploading via the wizard. From that point on, I get a "Unable to install plugin: 'No error message provided.'" message. I've debugged this down to the file upload feature. If I upload an html file to any plugin, it will no longer work.....

Also, on a seperate note from the uploaded file problem... That little routine you gave me is getting these errors when checking it in perl:

Global symbol "$tar" requires explicit package name at Install.pm line 107.
Global symbol "$CFG" requires explicit package name at Install.pm line 108.

Any good advice on all this?

Thanks,

Alex-J

Quote Reply
Re: While on Plug-ins In reply to
Hi,

Your Install.pm should have:

use Links qw/$CFG/;

at the top. Also, sub install should look like:

sub install {
my ($installer, $tar) = @_;
# any special code.
my $file = $tar->get_file ('name_of_file.html');
$file->name ( $CFG->{admin_root_path} . '/templates/admin/name_of_file.html');
$file->write;
# rest of code
}

I had made a mistake in my post earlier. Check the docs for GT::Tar for the full syntax.

As for the upload, I think this is a problem with the code that we will need to fix up. For now, make sure sub install() returns a string saying the install was successful.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: While on Plug-ins In reply to
Thanks for the quick reply. Following your code, my plugins are now able to extract admin templates or anything else I might need to include with a plugin.

The other problem definately looks like some kind of bug in the routines that add a file to the tar. Its not just the upload routines... I get the same errors when I try to install a plugin if I used the "Body" field to create an included file rather than upload it...

But if I go to shell, untar the plugin I want to add files to, and retar it (in shell) including my templates, everything works just fine...

Well you've heard more than enough from me today...

Signing off...

Alex-J



Quote Reply
Re: While on Plug-ins In reply to
Alex,

The plug-ins under development really should be kept in a different directory, like "in_progress" or something like that.

Then, to test them, they are copied to the Uninstalled directory.

The problem is the files in the uninstalled directory are constantly deleted... It becomes a pain moving them back and forth.


PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://pugdog.com/FAQ