MAN page from Other HTML-Embperl-1.3.29_1.3.6-3sls.i586.rpm
EmbperlObject
Section: User Contributed Perl Documentation (3)
Updated: 2001-11-13
Index NAME
HTML::EmbperlObject - Extents HTML::Embperl for building whole website with reusable components and objects
SYNOPSIS
<Location /foo> PerlSetEnv EMBPERL_OBJECT_BASE base.htm PerlSetEnv EMBPERL_FILESMATCH "\.htm.?|\.epl$" SetHandler perl-script PerlHandler HTML::EmbperlObject Options ExecCGI </Location>
DESCRIPTION
HTML::EmbperlObject allows you to build object-oriented (
OO) websites using
HTML components which implement inheritance via subdirectories. Thisenables elegant architectures and encourages code reuse. The use ofinheritance also enables a website-wide ``look and feel'' to be specifiedin a single
HTML file, which is then used as a template for every otherpage on the site. This template can include other modules which can beoverridden in subdirectories; even the template itself can beoverridden. In a nutshell,
EmbperlObject makesthe design of large websites much more intuitive, allowingobject-oriented concepts to be utilised to the fullest while stayingwithin the ``rapid application development'' model of Perl and
HTML.
HTML::EmbperlObject is basicly a mod_perl handler or could be invokedoffline and helps you tobuild a whole page out of smaller parts. Basicly it does the following:
When a request comes in, a page, which name is specified by EMBPERL_OBJECT_BASE, issearched in the same directory as the requested page. If the pages isn't found, EmbperlObject walking up the directory tree until it finds the page, or itreaches "DocumentRoot" or the directory specified by EMBPERL_OBJECT_STOPDIR.
This page is then called as frame for building the real page. Addtionaly EmbperlObjectsets the search path to contain all directories it had to walk before finding that page.If EMBPERL_OBJECT_STOPDIR is set the path contains all directories up to thein EMBPERL_OBJECT_STOPDIR specified one.
This frame page can now include other pages, using the "HTML::Embperl::Execute" method.Because the search path is set by EmbperlObject the included files are searched inthe directories starting at the directory of the original request walking up thru the directorywhich contains the base page. This means that you can have common files, like header, footer etc.in the base directory and override them as necessary in the subdirectory.
To include the original requested file, you need to call "Execute" with a '*' as filename.To call the the same file, but in an upper directory you can use thespecial shortcut "../*".
Additionaly EmbperlObject sets up a inherence hierachie for you: The requested pageinherit from the base page and the base page inherit from a class which could bespecified by "EMBPERL_OBJECT_HANDLER_CLASS", or if "EMBPERL_OBJECT_HANDLER_CLASS" isnot set, from "HTML::Embperl::Req". That allows you to define methods in base page andoverwrite them as neccessary in the original requested files. For this purpose a requestobject, which is blessed into the package of the requested page, is given as first parameter to each page (in $_[0]). Because this request object is a hashref, you canalso use it to store additional data, which should be available in all components. Embperl does not use this hash itself, so you are free to store whatever you want.Methods can be ordinary Perl sub's (defined with [! sub foo { ... } !] ) or Embperl sub's(defined with [$sub foo $] .... [$endsub $]) .
Runtime configuration
The runtime configuration is done by setting environment variables,in your webserver's configuration file. Basicly the configuration is the same asfor normal Embperl. All Embperl configuration directives also appliesto EmbperlObject. There are a few addtional configuration directiveslisted below. Addtionaly you have to set the
"PerlHandler" to
"HTML::EmbperlObject" when running under mod_perl or use
"epocgi.pl"instead of
"embpcgi.pl" when running as
CGI Script.
EMBPERL_DECLINE
Perl regex which files should be ignored by
EmbperlObject EMBPERL_FILESMATCH
Perl regex which files should be processed by
EmbperlObject EMBPERL_OBJECT_BASE
Name of the base page to search for
EMBPERL_OBJECT_STOPDIR
Directory where to stop searching for the base page
EMBPERL_OBJECT_ADDPATH
Additional directories where to search for pages. Directories areseparated by
";" (on Unix
":" works also). This path is
always appended to the searchpath.
EMBPERL_OBJECT_FALLBACK
If the requested file is not found the file given by
"EMBPERL_OBJECT_FALLBACK"is displayed instead. If
"EMBPERL_OBJECT_FALLBACK" isn't set astaus 404,
NOT_FOUND is returned as usual. If the fileame given in
"EMBPERL_OBJECT_FALLBACK" doesn't contain a path, it is searched thru the samedirectories as
"EMBPERL_OBJECT_BASE".
EMBPERL_OBJECT_HANDLER_CLASS
If you specify this call the template base and the requested page inherit allmethods from this class. This class must contain
"HTML::Embperl::Req" in his
@ISA array.
Execute
You can use
EmbperlObject also offline. You can do this by calling the function
"HTML::EmbperlObject::Execute".
"Execute" takes a hashref as argument, which cancontains the same parameters as the
"HTML::Embperl::Execute" function. Additionalyyou may specify the following parameters:
- object_base
- same as $ENV{EMBPERL_OBJECT_BASE}
- object_addpath
- same as $ENV{EMBPERL_OBJECT_ADDPATH}
- object_stopdir
- same as $ENV{EMBPERL_OBJECT_STOPDIR}
- object_fallback
- same as $ENV{EMBPERL_OBJECT_FALLBACK}
- object_handler_class
- same as $ENV{EMBPERL_OBJECT_HANDLER_CLASS}
See also the "object" and "isa" parameters in Embperl's Execute function, on howto setup additional inherence and how to create Perl objects out of Embperl pages.
Basic Example
With the following setup:
<Location /foo> PerlSetEnv EMBPERL_OBJECT_BASE base.htm PerlSetEnv EMBPERL_FILESMATCH "\.htm.?|\.epl$" SetHandler perl-script PerlHandler HTML::EmbperlObject Options ExecCGI </Location>
Directory Layout:
/foo/base.htm /foo/head.htm /foo/foot.htm /foo/page1.htm /foo/sub/head.htm /foo/sub/page2.htm
/foo/base.htm:
<html> <head> <title>Example</title> </head> <body> [- Execute ('head.htm') -] [- Execute ('*') -] [- Execute ('foot.htm') -] </body> </html>/foo/head.htm:
<h1>head from foo</h1>
/foo/sub/head.htm:
<h1>another head from sub</h1>
/foo/foot.htm:
<hr> Footer <hr>
/foo/page1.htm:
PAGE 1
/foo/sub/page2.htm:
PAGE 2
/foo/sub/index.htm:
Index of /foo/sub
If you now request http://host/foo/page1.htm you will get the following page
<html> <head> <title>Example</title> </head> <body> <h1>head from foo</h1> PAGE 1 <hr> Footer <hr> </body> </html>
If you now request http://host/foo/sub/page2.htm you will get the following page
<html> <head> <title>Example</title> </head> <body> <h1>another head from sub</h1> PAGE 2 <hr> Footer <hr> </body> </html>
If you now request http://host/foo/sub/ you will get the following page
<html> <head> <title>Example</title> </head> <body> <h1>another head from sub</h1> Index of /foo/sub <hr> Footer <hr> </body> </html>
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
Author
G. Richter (richterAATTdev.ecos.de)
See Also
perl(1), HTML::Embperl, mod_perl, Apache httpd
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- Runtime configuration
- EMBPERL_DECLINE
- EMBPERL_FILESMATCH
- EMBPERL_OBJECT_BASE
- EMBPERL_OBJECT_STOPDIR
- EMBPERL_OBJECT_ADDPATH
- EMBPERL_OBJECT_FALLBACK
- EMBPERL_OBJECT_HANDLER_CLASS
- Execute
- Basic Example
- Example for using method calls
- Author
- See Also
This document was created byman2html,using the manual pages.