[Templates] Calling class methods with parameters from templates

Berg, Eric eric.berg@lehman.com
Tue, 3 Jul 2007 11:44:53 -0400


Thanks, Robin and Clinton.

I didn't try Clinton's recommendation to quote the key of the hash I was =
passing in, because I'd already figured out that I had to pass parameters =
in to my subs using references.  Which, BTW, I generally do, however, I've =
been trying to adhere to the standard practices of the development group =
in which I work.  Now we'll do both from now on.

Thanks, guys.

-Eric.

-----Original Message-----
From: Robin Smidsr=F8d =5Bmailto:robin=40smidsrod.no=5D=20
Sent: Tuesday, July 03, 2007 11:31 AM
To: templates=40template-toolkit.org
Cc: Berg, Eric
Subject: Re: =5BTemplates=5D Calling class methods with parameters from =
templates

Berg, Eric wrote:
> I'm traversing a hierarchy, and need to get one object from another from
> within a template.   I'm having difficulty passing in parameters to my
> instance method from the template.  Here's some code to explain:
>
> I have an array of =22suites=22 from which I get an individual =
=22suite=22:
>
>   =5B% FOREACH suite =3D suites %=5D
>
> I need to get a =22suite_runner=22 from the suite which I do in regular=20
> perl code like so:
>
> my =24runner =3D =24suite->get_runner(ENVIRONMENT =3D> 'PROD');
>
> I've tried to:
>
> =5B% runner =3D suite.get_runner(ENVIRONMENT =3D> env) %=5D
>
> But I'm getting errors like:
>
> =5BTue Jul  3 11:01:23 2007=5D regression_builder.cgi: Reference found=20
> where even-sized list expected at .../lib/site_perl//TestSuite.pm line 68.
>  =20
If you allow you get_runner() method take arguments like this (hashref =
instead of hash-as-array-arguments)

=24suite->get_runner(=7BENVIRONMENT =3D> 'PROD' =7D);

You should probably be out of problems.

-- Robin

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
- - - - - - -

This message is intended only for the personal and confidential use of the =
designated recipient(s) named above.  If you are not the intended =
recipient of this message you are hereby notified that any review, =
dissemination, distribution or copying of this message is strictly =
prohibited.  This communication is for information purposes only and =
should not be regarded as an offer to sell or as a solicitation of an =
offer to buy any financial product, an official confirmation of any =
transaction, or as an official statement of Lehman Brothers.  Email =
transmission cannot be guaranteed to be secure or error-free.  Therefore, =
we do not represent that this information is complete or accurate and it =
should not be relied upon as such.  All information is subject to change =
without notice.

--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within =
this communication (including any attachments) is not intended or written =
to be used and cannot be used for the purpose of (i) avoiding U.S. tax =
related penalties or (ii) promoting, marketing or recommending to another =
party any transaction or matter addressed herein.