Hi,


I'm trying to use Inline::Java to use the Perl Template Toolkit (http://www.template-toolkit.org/)
from Java.. But I'm having little problems with communicating Hashtables to perl.


The way things work in the template toolkit is that you pass to templates a perl Hash that contains a lot of things..
It can contain functions, objects, hashes, arrays and strings..


What I would like to achieve is having some callbacks from the templates usage of all this to Java objects and functions.. For the moment I'm focusing on variables and objects:

Example template:

Version: [% VERSION %]<br>
Param 1: [% param1 %]<br>
Param 2: [% param2 %]<br>
Param 3: [% param3 %]<br>
Param 5: [% param5 %]<br>
Param 5 name: [% param5.name %]<br>
Param 5 value: [% param5.value %]<br>
Param 4 name: [% param4.name %]<br>
Param 4 value: [% param4.value %]<br>
Function call: [% Param('toto') %] <br>

If I have a perl Hash:

VERSION ->  $vars{'VERSION'}
param1  -> $vars{'param1'}
param2  -> $vars{'param2'}
param3  -> $vars{'param3'}
param5.name -> $vars{'param5'}->{'name'}
param5.value -> $vars{'param5'}->{'value'}
Function call -> $vars{'Param'} is a function

param5.name could also be handled by an AUTOLOAD function if param5 is a perl object.

Using Inline::Java I've seen two solutions to make it work:

Solution 1: Make the template toolkit understand seemlessly the Java objects
In this case the 'vars' variable would be a Hashtable.

So it would be:

VERSION -> vars.get('VERSION')
param1 ->  vars.get('param1')
param5.name -> (Hashtable)vars.get('param1)).get('name')

I've managed to make the Inline::Java code call the 'get' or 'put' method when it doesn't find a member or a method..
I'm blocked because at one point the template toolkit wants to add a perl Hash to the vars Hashtable and Inline::Java does not want to convert such an object..
I'm thinking I would need to build a wrapper object in Java to store by Hash but I don't really know how to store by object, especially if I want to build a wrapper around the perl reference..


With this solution, I'm not sure how I can allow to call Java methods seemlessly.. Maybe just creating the perl wrapper will do it..

Solution 2: Allowing to manipulate perl hashes from Java

This solution is much safer at execution time as the data given to the template toolkit is much more close to what it gets in Perl.
However this can be heavy as it might be needed to copy a lot of data and make a lot of call to perl to fill objects..
By trying this I found the same problem with hashes.. I was trying to store my perl hash in Java and then call perl functions to add data to it, but this was refused by the Inline module as it could not convert the Hash to a java object..


Any toughts in this area ? Is there a chance to make this work ?

Ludovic








Reply via email to