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

Passing data to globals, no tags

Quote Reply
Passing data to globals, no tags
This drove me crazy, until I remembered something from an earlier plugin. I couldn't find it in the docs, either.

Either it's a bug, or it's an overlooked concept that should be investigated.

If you pass parameters to a global:

<%global_name ('param1', 'param2')%>

No tags are passed.

The first element in the passed array, is *not* the tags.
You have to do a

sub {
my $tags = GT::Template->tags;
...
etc
}

And, that's not documented anywhere I could find.

For consistency, and uniformity with OOP, shouldn't the first parameter *always* be the same?

When calling a method, the first parameter is always 'self', when calling a sub from inside the templates, the first parameter should *always* be "tags" ... whether params are passed or not.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Passing data to globals, no tags In reply to
You sure?

<%global_name('something','test')%>

Code:
sub {
my ($val1,$val2) = shift;
return "$val1 and $val2 ";
}


...works for me Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Passing data to globals, no tags In reply to
The problem is in passing tags.

The "tags" hash is supposed to be the first parameter passed to subs, or functions.

What happens is:

<%function ('param1', 'param2')%>

Sends param1 and param2 to the function/sub.

eg:

my ($val1,$val2) = shift;

Not:

my ($tags, $val1, $val2) = shift;

But, <%function%> with no params, sends "tags" as the first param, so you'd get

my ($tags) = shift;

Rather than an empty set, or null value.

As you can see, it's inconsistent, and prone to problems. It's also really hard to write anything that makes sense in a simple fashion, when "tags" appear and disappear.

The code should always pass tags, eg:

<%function (param1, param2)%>

Would yeild:

sub {
my $tags = shift;
my (@optional_params) = @_;
...etc...
}

Which would be consistent, and also consistent with the OOP interface:

my($class, %options) = @_;

And allow you to check to see if any params were actually passed, rather than getting all the default tags, if nothing was explicitly passed.


This was a real pain to work around. Especially since it's changed several times.


*OR* it should *not* pass tags, and you have to request them, like in the earlier versions of Links SQL, so you didn't accidentally miss them, or have them show up unexpectedly.

my $tags = GT::Template->tags;


It's much safer, better, and all around more useful than how it's working now.


FWIW: This was in version 2.1.2, I didn't try it on a 2.2.x site.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Passing data to globals, no tags In reply to
I thought that tags was always the first parameter AFTER any passed in variables. So I think that in your example you should be able to get tags from my ($val1, $val2, $tags) = shift;

At least that's how I've always believed it works.
Quote Reply
Re: [afinlr] Passing data to globals, no tags In reply to
After???

That makes no sense.... but I'll give it a try.

Also, it doesn't solve any of the parameter exists/etc problems. The template tags would still show up, and you' have *no* way to know what tags were there (so I'm sure this doesn't work..... ).

I don't know of any language/convention that passes default parameters _after_ other parameters, for just that reason. Perl does not require all parameters to be there, only that parameters are accessed in order, so any missing parameters between passed parameters must be specified, even if just ''.

I'm not sure why this hasn't been answered/asked before, but I searched all over, and unless it's just not indexed, I can't find any reference to this.

I've made several plugins and globals, Days_Old, Top_xxxx , etc, that take a variable amount of passed in parameters. I did it during the time we needed to call GT::Template->tags explicitly, so I never encountered this.... and I guess maybe (just occurred to me) this is a backwards compatibility thing.

*BUT* I would *really* like to have the consistency of having to explicitly call GT::Template->tags, *OR* have tags as the first parameter in *ALL* situations, rather than the mixed up way it's apparantly done now.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Dec 4, 2004, 8:56 PM
Quote Reply
Re: [pugdog] Passing data to globals, no tags In reply to
It seems, I met the same problem.

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] Passing data to globals, no tags In reply to
Can somebody confirm, that in LSQL v3.x
you can not pass input to global, when used in IF condition?


Here is a test case in template:
Code:
<%test('test_a')%>
<%if test('test_b')%>test_b<%endif%>

The test global itself:
Code:
sub {
my $input = shift;
use GT::Dumper;
print GT::CGI->header();
print "var:" . GT::Dumper::Dumper(\$input) . "<br>\n";
return $input;
}


Result:
Quote:
var:$VAR = \'testa';
var:$VAR = \{ 'CatDepth' => '0', 'CatRoot' => '0', 'Category_Template' => '', 'Description' => '', 'FatherID' => '0', 'Footer' => '', 'Full_Name' => 'test', 'Header' => '', 'ID' => '1', ... including all the tags };
In 1st case, got the input, correctly.
In 2nd case, when using IF condition, did not get the input, but got the tags hashref.


IMHO, this is a bug of the GT::Template in LSQL 3.x, and should be fixed urgently.


There may be a workaround for this, but I don't remember 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: [pugdog] Passing data to globals, no tags In reply to
There is a workaround for my problem here:
http://www.gossamer-threads.com/...i?post=225738#225738


The fixed test template code should be look like this:
Code:
<%test('test_a')%><br>
---<br>
<%if test('test_b')%><%test_b%><%endif%><br>
<%set test_workaround = test('test_b')%> <br>
<%if test_workaround%><%test_workaround%><%endif%><br>


But the bug should be fixed anyway!
It's a bug, which is dated back to 2002, and still NOT FIXED!

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: Jan 17, 2006, 11:28 AM
Quote Reply
Re: [webmaster33] Passing data to globals, no tags In reply to
Quote:
But the bug should be fixed anyway!
It's a bug, which is dated back to 2002, and still NOT FIXED!

Its not a bug =) (i.e there isn't a fix).

You have to just do;

<%set variable = global_name(opts)%>
<%if variable eq "English"%>englsh<%endif%>

..but can't do;

<%if global_name(opts) eq "English"%>englsh<%endif%>

..it won't work, as your trying to pass the paramaters through, which gets passed in as null.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Passing data to globals, no tags In reply to
 
Quote:
Its not a bug =) (i.e there isn't a fix).
If something does NOT have a fix, it does not mean it is not a bug Tongue


Quote:
You have to just do;
<%set variable = global_name(opts)%>
<%if variable eq "English"%>englsh<%endif%>
Yes, I know. I linked the thread explaining this in my previous post.


Quote:
<%if global_name(opts) eq "English"%>englsh<%endif%>
..it won't work, as your trying to pass the paramaters through, which gets passed in as null.
This SHOULD work, so it IS a BUG! We can call it - as Microsoft says [:D] - a "feature", but the truth is, that it is a BUG.

If <%global_name(opts)%> is working, and passing parameter, then <%if global_name(opts) eq "English"%>englsh<%endif%> should also pass parameter to global_name() function.
So it IS a BUG!


Just imagine, if in Perl you could do this:
Code:
is_valid($my_input)

but you could NOT do this:
Code:
if (is_valid($my_input)) {
print "found to be valid";
}
Fortunately Perl does NOT have such BUGs, like the one GT::Template system has... Laugh

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] Passing data to globals, no tags In reply to
Well, IMO, I wouldn't call it a bug Tongue

If you want to, I guess thats up to you Laugh

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Passing data to globals, no tags In reply to
Well we can also call it as "feature", but would that help the users??? Tongue

Pugdog is right: he says "For consistency, and uniformity with OOP, shouldn't the first parameter *always* be the same?"
This is something similar. A feature should be consistent.
IMHO, it is inconsistency, an engineering fault, and it is ridiculous, if a function or method works differently just because we did put into an IF condition...
So Yes, IMHO it is a BUG. An at least 4 years old BUG. Unsure


We can wait another 2 years, and this BUG could go to school... Laugh

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