[Templates] views, inheritance, calliing "super"

[prev] [thread] [next] [Date index for 2004/08/26]

From: Dami Laurent (PJ)
Subject: [Templates] views, inheritance, calliing "super"
Date: 14:06 on 26 Aug 2004
Hi everybody,=20

Some considerations about the VIEW design.

A couple of months ago I asked about object-orientation and
inheritance in TT. Randal Schwarz pointed me to the VIEW construct
which can take a "base" parameter and therefore brings inheritance.

This works fine : methods can call other methods and properly find
the right implementation. However, when it comes to calling "super",
there seems to be a flaw : the late binding to "self" (the current
view) is lost. This is shown in code below, in the view v3.

I found a fix in view v4 : bind again the view to itself (view=3Dview)
and it works fine. However, it seems to me that somehow this should
be part of the VIEW design.=20

Any opinions ?

Regards,=20

Laurent Dami
Etat de Gen=E8ve, Pouvoir Judiciaire
laurent.dami@xxxxxxx.xx.xx

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

[%- VIEW root;
    view.name =3D "root";
    BLOCK whoami; "My name is "  _ view.name; END;
    END; -%]

[%- VIEW v1 base=3Droot; view.name =3D "v1"; END;  -%]

[%- VIEW v2 base=3Droot;
    view.name =3D "v2";
    BLOCK presentMe; view.whoami() _ " and I live in v2"; END;
    END; -%]

[%- VIEW v3 base=3Droot;
    view.name =3D "v3";
    BLOCK whoami; view.base.whoami() _ " and I live in v3"; END;
    END; -%]

[%- VIEW v4 base=3Droot;
    view.name =3D "v4";
    BLOCK whoami; view.base.whoami(view=3Dview) _ " and I live in v4"; =
END;
    END; -%]

[% v1.whoami();    # OK  : My name is v1 %]
[% v2.presentMe(); # OK  : My name is v2 and I live in v2 %]
[% v3.whoami();    # NOK : My name is root and I live in v3 %]
[% v4.whoami();    # OK  : My name is v4 and I live in v4 %]

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] views, inheritance, calliing "super"
Dami Laurent (PJ) 14:06 on 26 Aug 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52