Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

[Suggestion] How to get plugin registry into a global?

Quote Reply
[Suggestion] How to get plugin registry into a global?
Currently we can get plugin registry locally into a variable, by using similar code:

Code:
my $plugin_registry = Links::Plugins->get_plugin_registry("myplugin");
But we have to call this function in every sub we want to use it. To avoid this, would be fine to load plugin Registry for current plugin, into a Global hash variable (%REG), so we will not spend time in each sub to reload the registry.

I mean something similar as we load the main globals using this code:
Code:
use Links qw/$DB $IN $USER $CFG %REG/;

We can load plugin registry into a %REG global, like this:
Code:
$REG{"myplugin"} = Links::Plugins->get_plugin_registry("myplugin");
So this is the way how I will do right now.

Alex may add a way into next release, to import the %REG global variable of plugins, into current package we use...

Waiting opinions! Any of them are welcome.

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...

Last edited by:

webmaster33: Jul 6, 2002, 6:22 AM
Quote Reply
Re: [webmaster33] [Suggestion] How to get plugin registry into a global? In reply to
Do you really need the registry of all the installed plugins for your plugin?

If you just want to define the registry entries of your plugin as a global hashref (and while we're at it also the user configuration options), you could write

use vars qw/$REG $PUC/;
$REG = Links::Plugins->get_plugin_registry("PluginName");
$PUC = Links::Plugins->get_plugin_user_cfg("PluginName");

at the beginning of your plugin module. Then you can access $REG and $PUC in all your subs.

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jul 6, 2002, 7:10 AM
Quote Reply
Re: [yogi] [Suggestion] How to get plugin registry into a global? In reply to
 
Quote:
Do you really need the registry of all the installed plugins for your plugin?
I don't know at the moment, but I can imagine such situation, when for compatibility reasons, I would need to check if an another plugin is installed or not, or a hook is registered or not.

Well, the solution I (finally decided to) use now is similar to the one you suggest, just a bit more complex:
Code:
use vars qw/$PLG/;
# Access the plugin user options.
require Links::Plugins;
# we get plugin name into $PLG->{"NAME"} global hashref
$PLG->{"NAME"} = 'Extended_link';
print "<br>\nplugin_cfg options: " . Dumper("<br>\n\n---PLUGIN OPTIONS - BEGIN-----") . ""
if ($GT::Plugins::DEBUG >= "3");

# we get plugin user options into $PLG->{"OPTS"} global hashref
$PLG->{"OPTS"}{"$PLG->{NAME}"} = Links::Plugins->get_plugin_user_cfg ($PLG->{NAME});
print "<br>\nplugin_cfg options: " . Dumper($PLG->{"OPTS"}{"$PLG->{NAME}"}) . "<br>\n"
if ($GT::Plugins::DEBUG >= "3");

# we get plugin registry into $PLG->{"REG"} global hashref
$PLG->{"REG"}{"$PLG->{NAME}"} = Links::Plugins->get_plugin_registry ($PLG->{NAME});
print "<br>\nplugin registry: " . Dumper($PLG->{"REG"}{"$PLG->{NAME}"}) . "<br>\n"
if ($GT::Plugins::DEBUG >= "3");

# we make the full plugin config accessible through $PLG->{"CFG"} global hashref
# (may be useful for plugin compatibility checking)
$PLG->{"CFG"}{"$PLG->{NAME}"} = GT::Plugins->load_cfg ( $CFG->{admin_root_path} . '/Plugins' );

print "<br>\nPLG->{CFG}{$PLG->{NAME}}: " . Dumper($PLG->{"CFG"}{"$PLG->{NAME}"}) . "<br>\n"
if ($GT::Plugins::DEBUG >= "3");
print Dumper("<br>---PLUGIN OPTIONS - END----<br>\n")
if ($GT::Plugins::DEBUG >= "3");

Later in any sub we can use the $PLG hashref as following:
Code:
sub myfunction {
my $plugin_reg = $PLG->{"REG"}{"$PLG->{NAME}"};
print $plugin_reg->{any_reg_key};
...
}
This way currently works well for me, so I can advice it for others, too.


By the way: How can we know if another plugin already used GT::Plugins->action ( STOP ); to replace an original hook code? This would be very important part of plugin compatibility checking!

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...