Ok, so I'd like to do something like


#!/usr/bin/perl my $thing = Stuff->new(); $tt->process("template.tem", $thing);

package Stuff;

sub new {
    return bless {}, shift;
}

sub colour {
    my ($self) = @_;
    return "orange!";
}


And in the template:


<html>
<body>
[% colour %]
</body>
</html>

ie, I'd like to pass a blessed hash to process() and call it's object methods as I would keys/values in it. I can already do this if I pass it as a member:

$tt->process("template.tem", { object=>$thing });
then [% object.colour %]

but I can't pass an object as the top-level thing.

I talked to Mark about this yesterday, and he suggested you could fake it by making a shallow copy of the hash you were going to pass, and then sticking anonymous subs into the copy pointing at the package methods. This feels evil but possible, but I lack the perl-fu to get a list of package methods..

--
.tom

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to