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

Install a global from a plugin?

Quote Reply
Install a global from a plugin?
I am a little confused on putting globals into plugins.

It seems that if a global uses <%sometag%> in a static template then it needs to go somewhere where the return value from this function is global...Crazy I am not sure this makes sense (sorry).

What I am trying to say is:
  • How do I get a plug-in to install and uninstall a global (sub)?
  • How can I do this another way? i.e. insert this global into install.pm or plugin.pm somewhere?


Thanks in advance


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

Last edited by:

Ian: May 20, 2002, 10:29 PM
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
How to add a global from Install.pm: http://gossamer-threads.com/...i?post=191731#191731

You can also add a function to MyPlugin.pm, and then call it from the templates as <%Plugins::MyPlugin::func($args)%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Install a global from a plugin? In reply to
Wow, thanks Ivan. Now how come I could not find that, it was recent too! I must be searching on bad keywords...

I like option 2 better, that is creating and calling a function from plugin.pm. No sense crowding the globals.

Thanks againSmile


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
Ian,

You might want to also think about breaking up your .pm files into a hierarchy, like I've described a few times for the Images/Upload system.

You can set up a directory in the Plugins directory called EditorsX (or something unique) and into that add the extra modules -- including something you can call "Globals.pm" or "Utils.pm" and you would reference that from your templates as described.

The other advantage of that is these modules are now accessible from _any_ area of links and from any other plugin or script that knows they exist. That is a big help for adding in features, maintaining your own library of functions across multiple plug ins and for sharing features between developers.

There is no "standard" for this... :) But if each author puts their stuff in their own directory under Plugins, there will be no name space collisions. I use Pugdog or pugdog for my directories (and need to standardize on one).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Install a global from a plugin? In reply to
What about the idea to have plugin development libraries, where the most often plugin functions, features can be stored?
(of course, only if the original developer of the function allowed to include the function into a plugin function library)

Those libraries could be also installed using their own installer.pm. Some new plugin installers may require, may depend on some of these plugin function libraries.
I mean something similar, like libraries and the RPMs on Linux, which may require a library, and depend on it.

Well, these are just a few ideas, and this is not really based on the current reality, but there may be need for similar features in the future...

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] Install a global from a plugin? In reply to
Hi,

If "Links" was the controlling program, I could see that happening, even in a Windows/compiled environment, but with open source and Unix as the real guy in charge, this would be hard to do.

My suggestion for using your own libraries, would be for cleanliness, and ease of operation. If someone hijacked your libaries, or altered them, you could simply reinstall them, (with changes) and put them out of operation. But, that gets nasty, and should be an effort of last result.

My real suggestion is for something like this:

PUGDOG/Utils.pm
PUGDOG/Utils/FileSave.pm
PUGDOG/Download/Download.pm
PUGDOG/Download/Upload.pm
PUGDOG/Download/Utils.pm

Etc. This would allow you to install new plugins in your own directory, with a file hierarchy, and if you have 2-3 plugins that all used the same basic check, or handling rutines, you could put them in your Utils.pm/Utils hierarchy, and only have to worry about them once. No embedded "bad" coding. :)

Look at the GT or Links subdirectory trees for ideas of how to break up your code.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Install a global from a plugin? In reply to
Hi PugDog,

Quote:


You can set up a directory in the Plugins directory called EditorsX (or something unique) and into that add the extra modules -- including something you can call "Globals.pm" or "Utils.pm" and you would reference that from your templates as described.




I am quite interested in doing this, but I need help on how to make this transformation, if you don't mind.

Lets say I have a global right now, which I want to inlcude in my plugin. I now create a file called Globals.pm and include this into my tar package (wizard helps me do this, so no problem here).
  1. How do I put my existing global into Globals.pm? What should this file look like? just a bunch of subs? (Like what stuff should I put at the start of this file) Do globals have to be modified at all, once they are out of they standard links globals.txt and into my own file?
  2. How do I call a sub/global from my new Globals.pm file in a template or plugin module?


I appreciate your comments.

Gosh, every little thing I learn makes a big difference to my abilities with these plugins! You guys better watch out, I may just have this editor monitor thing working soon!!


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

Last edited by:

Ian: May 28, 2002, 5:48 PM
Quote Reply
Re: [yogi] Install a global from a plugin? In reply to
Hi Ivan (or any expert!):

I put my global and tried to call it from my category.html template. This code works great as a global, but it does not when I put it into my plug-in.

Is there a 'require something' or a statment I have to put into my template file for it to be able call plug-in functions?

When building the build is terminated with the error:

Technical Message Follows:
--------------------------
GT::SQL::Table (86696): Wrong argument passed to this subroutine. Usage: Must pass category id to parents at (eval 54) line 7.


Sure thing, but you worked when you were just an ordinarly global!!

Here are the first few lines of the sub...

Code:


sub EditorLinks {
# -------------------------------------------------------------------
# This subroutine is for generating the list of editors on each
# category page, with links to their profile pages.
# called with <%Plugins::EditorMonitor::EditorLinks%>


my $tags = shift;
my $cat_id = $tags->{'ID'};
my $cat_db = $DB->table('Category');
my $parents = $cat_db->parents($cat_id);
push @$parents, $cat_id;






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

Last edited by:

Ian: May 31, 2002, 12:41 PM
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
I am not quite sure about this. I think, you can only use

my $tags = shift;

in a global (when you don't pass in arguments) to get all the template tags, but probably (certainly?) not in a sub. Somebody enlighten us on this please.

What I suggest is the following: call you function as

<%Plugins::EditorMonitor::EditorLinks($ID)%>

and then leave out the $tags = shift line, and just put

my $cat_id = shift;

This should work.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Install a global from a plugin? In reply to
Thanks for the suggestions Ivan.

Unfortuantley:

Error: Unable to load module: Plugins::EditorMonitor. Reason:
Can't locate Plugins/EditorMonitor.pm in @INC ans so on....Unsure



http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
Please show us the full EditorLinks code. Let we check it.

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] Install a global from a plugin? In reply to
Thanks Webmaster.

Code:


sub {

#Editor Monitor Plug-in

my $tags = shift;
my $cat_id = $tags->{'ID'};
my $cat_db = $DB->table('Category');
my $parents = $cat_db->parents($cat_id);
push @$parents, $cat_id;

my $ed_db = $DB->table('Editors', 'Users');
my $sth = $ed_db->select ( GT::SQL::Condition->new('CategoryID', 'IN', $parents) );
return {} unless ($sth->rows);

# Make any formatting changes you need here.
my $output = qq~<font color="#FF3300" size="3"><b>Editors: </b></font> ~;
my @editors;
my %seen;
while (my $user = $sth->fetchrow_hashref) {
next if ($seen{$user->{Username}}++);
$output .= qq~
<a href="$CFG->{build_root_url}/editors/profiles/$user->{Username}.html">$user->{Username}</a>
~;
push @editors, $user;
}
#return { editors => $output, editors_loop => \@editors };
return $output;
}


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
Hey, this is a global...
Not a plugin you can insert with <%Plugins::EditorMonitor::EditorLinks($ID)%>
Do you have EditorMonitor.pm at all in plugins ?

If yes, also list the first 10-15 lines of your EditorMonitor.pm file, WITHOUT comment lines.

EDIT: Also read Links SQL Developers Guide: Understanding Plugins in LSQL 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...

Last edited by:

webmaster33: Jun 2, 2002, 4:01 AM
Quote Reply
Re: [webmaster33] Install a global from a plugin? In reply to
Ok, here is the top part of EditorMonitor.pm (without comments) down to just before my plug-in hooks commence.

use strict;
use GT::Base;
use Links::SiteHTML;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB $USER/;

@Plugins::EditorMonitor::ISA = qw(GT::Base);

my $Plug_Version = "0.4.1";



I have been reading the Links SQL Developers Guide, and I will it admit it makes more sense each time I look at it... but I find there seems to be many things not mentioned in there, which are critical to it making sense to me. I am getting there though. This is all starting to fall into place! (thanks to the help on this forum). I did not know a line of perl or plugins or globals two months ago.Smile I am going to read through the docs again.

When I tried <%Plugins::EditorMonitor::EditorLinks($ID)%> in the category template. The errors are produced (as in the post above).

EDIT: Webmaster, I think I have this WORKING!!!!!!! I don't know why but this was causing it/and seemed to fix it:

While testing, I have been leaving the old tag to my orginal inbuilt global along side my plug-in tag ie.

<%EditorLinks%> <%Plugins::EditorMonitor::EditorLinks($ID)%>

Either on their own work, and don't cause error, but put the two together and 25 post on the forum from Sooke later it gets solved!!!!

Thanks for all your help Webmaster, and Yogi, and everyone else who helpedCool


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

Last edited by:

Ian: Jun 2, 2002, 8:54 AM
Quote Reply
Re: [Ian] Install a global from a plugin? In reply to
>Hey, this is a global...
>Not a plugin you can insert with <%>Plugins::EditorMonitor::EditorLinks($ID)%>
>Do you have EditorMonitor.pm at all in plugins ?
You did not answered my questions.


So the first thing you should start your plugin, to define your package:
Code:
package Plugins::EditorMonitor;


Also you have to add your path to the INC with the lib:
Code:
use lib 'c:/path/to/your/cgi-bin/lsql/admin';
This make possible to find your plugin in the paths.
However this is only required in .cgi executed files, as I know...

I hope this helps! Good luck!

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] Install a global from a plugin? In reply to
I have package Plugins::EditorMonitor; in both modules. My apologies, I accidently cut it out when removing the comments when posting on hereBlush

I will add : use lib 'c:/path/to/your/cgi-bin/lsql/admin'; thank you for pointing this out... although I don't have seperate cgi in this yet.

Smile


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

Last edited by:

Ian: Jun 2, 2002, 9:21 AM