You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Volker Hess <Vo...@avmz.uni-siegen.de> on 2000/09/27 07:02:29 UTC
HTML:EmbperlObject and Inheritance
Hi,
Perhaps the following question only derives from a basic misunderstanding
by a poor perlOO newby. If so I beg your pardon!
I tried to use EmbperlObject with inheritance by modifying "The Example
for using method calls" in Geralds docu. I were able to overwrite some
methods in "sub/page2.epl" by holding some others from "base.epl" at them
same time. I failed while trying the same with properties: In "page2.epl"
I set a new property '$self -> {test} = "blafasel"' which implicated that
everything set in "base.epl" ($self -> {fontsize}; $self -> {fontcolor};
...) is no longer available. Where am I wrong?
Volker
------------------------------->8----(base.epl)----------------------
[!
sub new
{
my $self = shift ;
# here we attach some data to the request object
$self -> {fontsize} = 2 ;
$self -> {fontcolor} = "red" ;
}
# Here we give a default title
sub title { 'Title not given' } ;
sub headline { 'Headline not given' } ;
!]
[-
# get the request object of the current request
$req = shift ;
# here we call the method new
$req -> new ;
-]
<html>
<head>
<title>[+ $req -> title +]</title>
</head>
<h1>[+ $req -> headline +]</h1>
<body>
[- Execute ('head.epl') -]
[- Execute ('*') -]
[- Execute ('foot.epl') -]
</body>
</html>
------------------------------->8------------------------------------
------------------------------->8----(page2.epl)---------------------
[!
sub new
{
my $self = shift ;
# here we overwrite the new method form base.htm
# $self -> {fontsize} = 5 ;
# $self -> {fontcolor} = "green" ;
$self -> {test} = "blafasel" ;
}
# Here we overwrite the default title
# sub title { 'Title form page 2' } ;
sub headline { 'Headline from page 2' } ;
!]
PAGE 2 [+ $_[0]->{test} +]
------------------------------->8------------------------------------
------------------------------->8----(head.epl)----------------------
<h2>
<font size=[+ $_[0] -> {fontsize} +]
color=[+ $_[0] -> {fontcolor} +]>
headline2
</font>
</h2>
------------------------------->8------------------------------------
--
Uni Siegen . Medienzentrum ** Volker.Hess@avmz.uni-siegen.de
phone: +49(0)271/740 2282 ** fax: +49(0)271/740 2526
http://www.avmz.uni-siegen.de/ ** http://www.online-h.de/
Re: HTML:EmbperlObject and Inheritance
Posted by Gerald Richter <ri...@ecos.de>.
Hi,
>
> Perhaps the following question only derives from a basic misunderstanding
> by a poor perlOO newby. If so I beg your pardon!
>
... ok, it's really an OO question, not an Embperl one :-)
>
> ------------------------------->8----(page2.epl)---------------------
> [!
>
> sub new
> {
> my $self = shift ;
>
# Here you have to call the new method of the base class, otherwise
# it is never called and can't do it's initialisation
$self -> SUPER::new ;
> # here we overwrite the new method form base.htm
> # $self -> {fontsize} = 5 ;
> # $self -> {fontcolor} = "green" ;
> $self -> {test} = "blafasel" ;
> }
>
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------