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

Sharing variable between install.pm and plugin.pm

Quote Reply
Sharing variable between install.pm and plugin.pm
Perl ignorant question coming up (sorry):

How can I share a variable (scaler) between my install.pm and plugin.pm?

Lets say for example I wanted to show $VERSION in a statement in plugin.pm, when $VERSION is defined in install.pm.

I guess this question is kind of a Perl question, but since it is also about plugins, I will leave it in this forum. Hope this is right!


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

Last edited by:

sooke: May 18, 2002, 10:08 AM
Quote Reply
Re: [sooke] Sharing variable between install.pm and plugin.pm In reply to
Check this post of Alex about plugin registry:
http://www.gossamer-threads.com/...ing=registry;#184893

I'm sure, this is what you want.

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] Sharing variable between install.pm and plugin.pm In reply to
So I could put:

$mgr->install_registry('YourPluginName', { MYSHARED => 'Plugin_Version'});

Then I could access this in my code:

my $reg = Links::Plugins->get_plugin_registry ('YourPluginName');
print $reg->{MYSHARED}; # prints 'Plugin_Version';


OR ASSIGN IT A NEW VALUE:

$reg->{MYSHARED} = '1.0.2';
Links::Plugins->set_plugin_registry('YourPluginName', $reg);



This is like having Global Variables, most excellent.

Thanks for that Webmaster!Smile


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Sharing variable between install.pm and plugin.pm In reply to
>> This is like having Global Variables, most excellent.

:) It's like having a "registry" and with it comes the associated problems -- since _any_ program can modify (or corrupt) the registry.

When it comes to versioning, it's better to install the versions into the code headers, and to use a function call to get at the version.

I'm not sure what system Alex uses in Links (for the registry/plugins), but there are several possible ones on CPAN or in perl references. Every author has a bit of a twist on this issue, but it comes down to OOP paradigms. You don't want to be able to externally access (or modify) values -- use a function call (object method).

The registry is a "shorthand" note pad for information that should be directly accessible through your plugin. Your plugin should be able to rebuild it's registry entries -- or answer a request from the registry monitor to do so.

The best use of the registry, is to allow Links itself to present to you menus, and access to the data through the user interfaces -- such as a list of registered plugins. It's also a way to allow inter-plugin communication on hooks and "right of way" in a quick and centralized fashion, without having to poll each plugin separately on each call.

It's much better, and safer, to directly access the object methods within a plugin to find the true values of the data, not the values the registry "remembers." The Registry could be out of date, which could cause problems if the calling script assumes the response is in version 1.0 format, but the actual module is 1.5 or 2.2.

I know there will probably be disagreement on this :) But this is one point of view.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Sharing variable between install.pm and plugin.pm In reply to
Pugdog, yes, I aggree you.

The registry should be treated very carefully, for the reasons you described.
The installed version would be better to get through an internal function of current plugin.

I passed the registry info to Ian, but I did not mention any problem about usage of the registry.
I'm glad that Pugdog mentioned these problems related to plugin registry.

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: [pugdog] Sharing variable between install.pm and plugin.pm In reply to
Thank you PugDog and Webmaster for the very interesting comments.

This sounds like something which may need looking into by GT.

I think for the simple sakes of passing a Version number around files, it may just be safer not to do this. However, there needs to be a safe way to share variables betweens files of the same plug-in and other plug-ins.

I hope I understood all of your comments, but I will re-read when I am feeling a bit better.

Thanks.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Sharing variable between install.pm and plugin.pm In reply to
You can store a version number for a plugin the following way:
Place the following code, where you want to check your version number.
Code:
my $myplugin_version = GT::Plugins::myplugin::version();

In your myplugin.pm file, insert a version function like this:
Code:
sub version {
my $ver = "1.23";
return $ver;
}

And a shorter version:
Code:
sub version {
return "1.23";
}

I hope this will help.

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] Sharing variable between install.pm and plugin.pm In reply to
Yes, thank you Webmaster.Smile

Just to clear this up in my head, I can call: my $myplugin_version = GT::Plugins::myplugin::version(); from any file or template(the return value), provided the plugin is installed?

This is not specifically related to the version, I also want to apply this concept to a tag I have created for something else. And I could just add a little test around it to see if the plugin is in fact installed.

Thanks again.


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

Last edited by:

Ian: May 27, 2002, 9:22 AM
Quote Reply
Re: [Ian] Sharing variable between install.pm and plugin.pm In reply to
>> Just to clear this up in my head, I can call: my $myplugin_version = GT::Plugins::myplugin::version(); from any file or template(the return value), provided the plugin is installed?

Yes... (and probably no)

my $myplugin_version = GT::Plugins::myplugin::version();

Is a function call, to a function you place in each of your main plugin files ie: PluginName.pm (the one that resides in the ../Plugins directory.

To analyze the above line, briefly:

"my $myplugin_version" is a variable declaration, which defines the scope via "my"

GT::Plugins::myplugin::version();

would be the function declaration. The problem I see, (and I may be wrong, if there is a "version()" function built into Links, is that the :: defines a path structure, so:

GT/Plugins/myplugin.pm would be the file, and the last part, the version() is the function name.

This should be, if I am reading it right, just:

Plugins::MyPluginName::version()

Where MyPluginName is the name of your plugin, without the .pm, case and all preserved, and the version() is the subroutine defined in that file.

So, if you have an installed plugin, called MyPluginName.tar, with a MyPluginName.pm file,

my $myplugin_version = Plugins::MyPluginName::version();

would be how you would call your internal version() routine, to find the version of that file.

Your version() routine can be as complex as you want. for instance, if you passed it a parameter, such as version('file.pm') your version routine could check the version status of that file, and return that, instead of it's own "major"version information.

If I'm wrong about the above -- let's clear it up quickly :)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Sharing variable between install.pm and plugin.pm In reply to
Thanks, that does make sense.

I wonder if there is a version() already in Links also... perhaps something which returns the current version of Links, as oppoesed to your plugin is also useful.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Sharing variable between install.pm and plugin.pm In reply to
Perl uses it's own version variable...

$VERSION

If you notice in most of their modules they have something like:

$VERSION = sprintf "%d.%03d", q$Revision: 1.93 $ =~ /(\d+)\.(\d+)/;

So you can do like:

$Module::SubClass::VERSION;
Quote Reply
Re: [Paul] Sharing variable between install.pm and plugin.pm In reply to
Yes I did notice $VERSION. Hmmm.... tinker time againSmile


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