Home : Introduction : Embperl::Object
Google Web perl.apache.org

Embperl 2 Advanced
More infos
Add info about Embperl

    Stable 2.4.0
    Beta 2.5.0_3
Support the development of Embperl! More...
Hello World
[ << Prev: Getting Started ] [ Content ] [ Next: Website-Global Variables >> ]

The file specified by the EMBPERL_OBJECT_BASE apache directive (usually called base.epl) is the lynchpin of how EmbperlObject operates. Whenever a request comes in for any page on this website, Emperl will look for base.epl - first in the same directory as the request, and if not found there then working up the directory tree to the root dir of the website. For example, if a request comes in for http://www.yoursite.com/foo/bar/file.html, then Embperl first looks for /foo/bar/base.epl. If it doesn't find base.epl there, then it looks in /foo/base.epl. If no luck, then finally /base.epl. (These paths are all relative to the document root for the website). What is the point of all this?

In a nutshell, base.epl is a template for giving a common look-and-feel to your web pages. This file is what is actually used to build the response to any request, regardless of the actual filename which was asked for. So even if file.html was requested, base.epl is what is actually executed. base.epl is a normal file containing valid HTML mixed with Perl code, but with a couple of small differences. Here's a simple 'Hello World' example of this approach:


<HTML> <HEAD> <TITLE>Some title</TITLE> </HEAD> <BODY> Joe's Website <P> [- Execute ('*') -] </BODY> </HTML>


Hello world!

Now, if the file http://www.yoursite.com/hello.html is requested, then base.epl is what will actually get executed initially. So where does the file hello.html get into the picture? Well, the key is the '*' parameter in the call to Execute(). '*' is a special filename, only used in base.epl. It means, literally, "the filename which was actually requested".

What you will see if you try this example is something like this:

Joe's Website

Hello world!

As you can see here, the text "Joe's Website" is from base.epl and the "Hello world!" is from hello.html.

This architecture also means that only base.epl has to have the boilerplate code which every HTML file normally needs to contain - namely the <HTML> <BODY>, </HTML> and so on. Since the '*' file is simply inserted into the code, all it needs to contain is the actual content which is specific to that file. Nothing else is necessary, because base.epl has all the standard HTML trappings. Of course, you'll probably have more interesting content, but you get the point.

[ << Prev: Getting Started ] [ Content ] [ Next: Website-Global Variables >> ]

© 1997-2012 Gerald Richter / ecos gmbh