[Templates] differentiating hash entries / methods with same name
Andrew Strader
astrader@ecnext.com
Tue, 7 Nov 2006 16:31:26 -0500
This is a multi-part message in MIME format.
------_=_NextPart_001_01C702B4.149D2DC4
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
If a blessed hash reference has a key foo and a method foo, TT will
defer to the method call. This is in keeping with the design pattern of
encapsulation. The rationale is that you may want to change the
underlying implementation of the class, such that $obj->{foo} is moved
to $obj->{foo}{main} to distinguish it from, say, $obj->{foo}{special}.
=20
________________________________
From: templates-admin@template-toolkit.org
[mailto:templates-admin@template-toolkit.org] On Behalf Of Dami Laurent
(PJ)
Sent: Tuesday, November 07, 2006 8:47 AM
To: templates@template-toolkit.org
Subject: [Templates] differentiating hash entries / methods with same
name
=20
Hi all,=20
Suppose an object $obj has both a hash entry $obj->{foo} and a method
$obj->foo().=20
If I pass this object to a template, [% obj.foo %] performs a method
call.=20
Is there a way to access the hash entry instead?=20
Thanks in advance, L. Dami=20
------_=_NextPart_001_01C702B4.149D2DC4
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>differentiating hash entries / methods with same name</title>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=3DEN-US link=3Dblue vlink=3Dpurple>
<div class=3DSection1>
<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>If a blessed hash reference has a =
key foo
and a method foo, TT will defer to the method call. This is in keeping =
with the
design pattern of encapsulation. The rationale is that you may want to =
change
the underlying implementation of the class, such that $obj->{foo} is =
moved
to $obj->{foo}{main} to distinguish it from, say, =
$obj->{foo}{special}.<o:p></o:p></span></font></p>
<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>
<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>
</span></font></div>
<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'>
templates-admin@template-toolkit.org
[mailto:templates-admin@template-toolkit.org] <b><span =
style=3D'font-weight:bold'>On
Behalf Of </span></b>Dami Laurent (PJ)<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Tuesday, November =
07, 2006
8:47 AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> =
templates@template-toolkit.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> [Templates] =
differentiating
hash entries / methods with same name</span></font><o:p></o:p></p>
</div>
<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p> </o:p></span></font></p>
<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Hi
all,</span></font> <o:p></o:p></p>
<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Suppose
an object $obj has both a hash entry $obj->{foo} and a method
$obj->foo().</span></font> <o:p></o:p></p>
<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>If
I pass this object to a template, [% obj.foo %] performs a method =
call.</span></font>
<o:p></o:p></p>
<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'> Is
there a way to access the hash entry instead?</span></font> =
<o:p></o:p></p>
<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Thanks
in advance, L. Dami</span></font> <o:p></o:p></p>
</div>
</body>
</html>
------_=_NextPart_001_01C702B4.149D2DC4--