Example for using method calls |
(Everything not given here is the same as in the example above) /foo/base.htm: [!
sub new
{
my $self = shift ;
# here we attach some data to the request object
$self -> {fontsize} = 3 ;
}
# Here we give a default title
sub title { 'Title 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>
<body>
[- Execute ('head.htm') -]
[- Execute ('*') -]
[- Execute ('foot.htm') -]
</body>
</html> /foo/head.htm: [#
here we use the fontsize
Note that
$foo = $_[0]
is the same as writing
$foo = shift
#]
<font size=[+ $_[0] -> {fontsize} +]>header</font> /foo/sub/page2.htm: [!
sub new
{
my $self = shift ;
# here we overwrite the new method form base.htm
$self -> {fontsize} = 5 ;
}
# Here we overwrite the default title
sub title { 'Title form page 2' } ;
!]
PAGE 2
|