Presenting Static Library Pages

only for RuBoard - do not distribute or recompile

Now we can begin implementing other parts of the site to go along with the store-front page. Let s take care of the easiest thing first, which is to present the areas that consist of static information. These include the privacy policy, the customer satisfaction guarantee, and the contact information pages. The main content for these pages is static, but they need to have boilerplate added to give them the site look. We ll implement display for static pages like these by setting up a page library and writing a simple page processor static.pl. To present any page that has a main content area containing static HTML, the processor reads the library file containing the content, adds the boilerplate, and sends the result to the client. static.pl looks like this:

 #! /usr/bin/perl -w  # static.pl - Handle a PseudEcom site "static" page..  # Read the requested page from the library directory, add the standard  # boilerplate, and send the result to the client.  use strict;  use lib qw(/usr/local/apache/lib/perl);  use IO::File;  use CGI qw(:standard);  use WebDB;  use WebDB::PseudEcom;  # Change this pathname as necessary for your site  my $static_page_dir = "/usr/local/apache/lib/htfiles";  my $page;  my $page_name = WebDB::trim (param ("page"));  $page_name ne ""      or fatal_error ("No page was requested; invocation error");  $page_name = $static_page_dir . "/" .. $page_name;  my $fh = new IO::File ($page_name)      or fatal_error ("Could not open $page_name");  {   # undefine local copy of input separator to disable it      local $/;      undef $/;      $page .= <$fh>;     # slurp entire file  }  undef $fh;          # close file  print header (),          start_html (-title => "PseudEcom Corporation", -bgcolor => "white"),          add_boilerplate ($page),          end_html ();  exit (0); 

The library files need not be stored in the Apache document tree. They just need to be in a location where the page processor can read them. As distributed, static.pl assumes the files are installed in /usr/local/apache/lib/htfiles. (You can find these files in the ecom/htfiles directory of the webdb distribution. Copy them where you want and, if necessary, adjust the pathname to them in the static.pl script.)

Library pages can be as simple or as complex as you like. For example, the customer satisfaction guarantee can be stated quite briefly:

 <h3>PseudEcom's Customer Satisfaction Guarantee</h3>  <p>  We guarantee that you will be delighted with any product you purchase from us.  </p>  <p>  If you are not, we offer the following simple policy:  You keep the product and we will keep the money.  </p>  <p>  No questions asked!  </p> 

Extending the Library Pages

Our static pages are written as HTML that is processed without interpretation. This has certain limitations. For example, if you need to include in a library page a link to some other area of the site, you could hardwire the link in, but then it would become invalid should you rearrange the site. An alternative approach would be to treat the HTML library pages as templates rather than as uninterpreted text. You could include special markers in the page that the page processor can recognize and convert to the proper links on-the-fly when the page is served. Then if you rearrange the site, you need only update the link-generation functions in the WebDB::PseudEcom module. If you want to use templates without writing your own template processor, take a look at Perl modules such as Text::Template and HTML::Mason.

only for RuBoard - do not distribute or recompile


MySQL and Perl for the Web
MySQL and Perl for the Web
ISBN: 0735710546
EAN: 2147483647
Year: 2005
Pages: 77
Authors: Paul DuBois

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net