[Templates] Template can not use overloaded @{} operator

Gernot Homma gernot@cyber-atelier.at
Wed, 1 Feb 2006 16:45:58 +0100


Hello everybody,

i have the following package definition:
package Collection;
use overload=20
	'@{}' 	=3D> \&op_deref_array;


sub new {
	# usual new code
	my $self =3D shift;
	$self->{list} =3D [];=09
}

sub op_deref_array {
	my $object =3D shift;
	return $object->{list};
}


as i use this in normal Perl like :

my $c =3D new Collection();
foreach my $x (@{$c}) {
	print $x . "\n";
}

i get the right objects ...

if i use this with template toolkit.
my $c =3D new Collection();
my $t =3D new Template();
$t->process('mytemplate.txt', { list =3D> $c });

and where mytemplate.txt looks like=20
[% c %]
[% FOREACH x =3D c %]
[% x %]
[% END %]

i can not see the 'x' in my output. It seems that the overloading of the
@{} operator doesn't work in TT.

any suggestions.

thanks in advance

Gernot