-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
* Tom Insam <tom at jerakeen.org> [2003-06-06 09:43]:
> 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.
The stash is takes it parameters (everthing in the $vars hashref) and
does this with it:
sub new {
my $class = shift;
my $params = ref $_[0] eq 'HASH' ? shift(@_) : { @_ };
my $self = {
global => { },
%$params,
%$ROOT_OPS,
'_PARENT' => undef,
};
bless $self, $class;
}
So, if you pass $thing as:
$tt->process("template.tem", $thing);
your object is being passed as $_[0], which means that it will be
wrapped up as { "$thing" => undef } in $params (and "$thing" will be
stringified into something like "HASH(0x4859ef3a)").
You could pass it as:
$tt->process("template.tem", { %$thing });
It occurs to me that if the second line of Template::Stash::new were
changed to:
my $params = UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
It would work the way you expected...
(darren)
- --
Whatever is done for love is beyond good and evil.
-- Friedrich Neitzsche
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: This message is digitally signed and can be verified for authenticity.
iD8DBQE+4J8/zsinjrVhZaoRAj0HAJ994h+3V1BI8TXiKDouabrIMS9i9ACfXUZy
tWIraAym3MW//CsvNPPXOdA=
=fkUB
-----END PGP SIGNATURE-----
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates