The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::EmbperlObject - Extents HTML::Embperl for building webpages out of small 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 is basicly a mod_perl handler that helps you to build 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, is searched 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 it reaches DocumentRoot or the directory specified by EMBPERL_OBJECT_STOPDIR.

This page is then called as frame for building the real page. Addtionaly EmbperlObject sets the search path to contain all directories it had to walk before finding that page.

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 in the directories starting at the directory of the original request walking up thru the directory which 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.

Runtime configuration

The runtime configuration is done by setting environment variables, in your web server's configuration file.

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 are separated by ; (on Unix : works also)

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>

 
  

Author

G. Richter (richter@dev.ecos.de)

See Also

perl(1), HTML::Embperl, mod_perl, Apache httpd