Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Bug in subroutine calls via GT::Template

Quote Reply
Bug in subroutine calls via GT::Template
I'm playing very heavy with the template system... Trying to use subroutine calls I found a very strange bug:

If I call a subroutine without any parameter everything works fine, for example, calling:

<%CGI::header%>

will return the header string correctly.
But if I try to use a subroutine passing a value something goes wrong....

<%my_package::sayhello ($Name)%>

in this example the subroutine supposed to get the value of tag <%Name%>, do something, and return a string.
Well, this is not true. The subroutine wont get the correct value <%Name%> but a hash-ref containing all tags in memory in that time.


Does anybody found the same problem?


cheers



Lepo - lepo@lepo.org
Quote Reply
Re: Bug in subroutine calls via GT::Template In reply to
Hi,

This isn't a bug, but a feature. The first argument to function calls is a hash ref of tags available on the page.

We are currently re-evaluating that though. Currently there are a number of ways of running custom code:

1. Use <%Module::function%> tag.
2. Define a tag like 'tag => 'sub { ... }'' and call it via <%tag%>.
3. Define a tag like 'tag => \&code_ref' and call it via <%tag%>.

Currently only the first form supports argument parsing, and all styles get the tags as the first value.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Bug in subroutine calls via GT::Template In reply to
So, let's say..

<%Module::funcion ($alltags, $another_tag, 'hello there')%>

would pass correctly tree parameters: Hashref of all tags, then <%another_tag%> then, at last, the string.

Is this the correct approach?


thaks you for the reponce!!!!


saluti dall'italia


lepo

Lepo - lepo@lepo.org
Quote Reply
Re: Bug in subroutine calls via GT::Template In reply to
Hi,

<%Module::Function ($alltags, $another_tag, 'hello_there')%>

would pass into Function() first a hash ref of available tags, then the <%alltags%>, then <%another_tag%>, then 'hello_there', so four in total.

We are thinking of changing this though.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Bug in subroutine calls via GT::Template In reply to
Alex,

How would you change this passing convention?

There is a benefit to having the hash of available tags already passed in, and also to explicitly passing in all the tags.


<%Module::Function ($alltags, $another_tag, 'hello_there')%>

There would be some benefit to <%Module::Function%> having access to the same values the template does.

I've thought about this awhile. Not all functions are going to expect the same things. The accepted Links format is a Hash reference followed by other values. This is put into an array, which is shifted off the input stack.

The problem comes with passing to external modules. Some may only expect a single parameter, or other types of data. The more you program with links, the more you get used to the idea of passing a hash_ref as the first (or only) value. I think only the ::display routine expects a ($value, $has_ref) for clarity reasons.

What if $alltags was the hash reference to the currently available tags, and a default links call would look like:

<%Module::Function($alltags, $value, $value...)%>

a call to a non-links function, could be anything:

<%Module::Function('99', 'goaway', $tag_value)%>

It would simplify things, I guess, having to explicitly pass in functions. If no passed parameters are given, then $alltags is passed by default, and the routine can use or ignore it. This would make it easy for links programmers, as well as everyone else.



PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Plugins:http://LinkSQL.com/plugin
Quote Reply
Re: Bug in subroutine calls via GT::Template In reply to
Well, I think that just adding some lines in GT::Template documentation specifying how to manipulare input data in subroutine calls would be the only thing needed.

Pugdog, your idea is very interestant but is not suitable for all cases. Let's say I want to insert a CGI::header call in my template...
If I just write <%CGI::header%> (that is the most intuitive way to call it) the system would get the hashref of all tags automatically, and I think the output would be not exactly what expected.


cheers



Lepo - lepo@lepo.org