Embperl - building dynamic websites with Perl


Introduction
[ Content ] [ Next: The Layout >> ]

In the early days of the of the web, (server-side) dynamic web pages meant CGI scripts. However, CGI scripts were lousy to read because of a lot of print statements with a lot of escaping, over long lines and nearly no chance to guess the final output at one glance.

These problems were mostly solved by the so called templating systems. Popular templating systems are PHP, JSP and ASP. In Perl there are multiple templating systems, each which it's own advantages and disadvantages. One of the most powerful and widely used systems is Embperl.

These templating systems embed the program code into the markup and not vice versa as CGI scripts did. This usually made the code more readable and the final output easier to guess. The possibility to include other files made complex web pages manageable, because you can have common portions of the site in just one file and include them in many others. So you could change the layout of the headers, footers or menus each in just one file and the design changed on all pages.

But imagine, you once want to the menu component - which always was on the left side - on the right side. You would have to change all files and move the statement which generates or includes the menu from in front of the content to behind the content. If your site is large, this can be a lot of (dumb) work.

Another disadvantage of this method is, that if you want one branch of your site to have a slightly different layout - let's say it differs in one of the included files - you'll have to change this information in each of the affected files at top level. In object-oriented programming, you would derive a new class from an existing one, overriding just one or a few methods and all other methods will be inherited from it's parent class(es).

So why not carryover the concept of object-oriented programming to creating dynamic websites? Embperl does that by providing Embperl::Object and thereby facilating the conception and implementation of big dynamic component-based websites.

Using Embperl's own website (https://perl.apache.org/embperl/) as example, the following sections will show how Embperl::Object works. The full source code of the Embperl website is included in the distribution of version 2.0 of Embperl in the directory /eg/web


[ Content ] [ Next: The Layout >> ]


© 1997-2023 Gerald Richter / actevy