PerlHoo, Part I | 3 | WebReference

PerlHoo, Part I | 3

PerlHoo::Design

In most applications, the majority of the written code handles data storage and the user interface. For PerlHoo, we will attempt to offload much of this code by using the inherent capabilities of the operating system and Web server. The functional requirements for PerlHoo are:

  1. Organizes information hierarchically
  2. Contains information about resources on the Internet
  3. Allows users to suggest new resources
  4. Allows editors to modify the directory content
  5. Is Simple to maintain
  6. Takes less than 1 week to develop
  7. Exports and imports directory content from/to multiple sources
Of all the requirements above, the one that stands out is #6. Too often, many of us are asked to do the impossible. The nice thing about Perl is that it often makes the impossible possible. With a little forethought and ingenuity, we will be able to complete the project with time to spare so we can get back to our game of Half-Life. We'll discuss data storage and the interface in the next few pages, but first, let's discuss how we'll structure our script.

Which Web Technology?

While we have the option of using advanced technologies like application servers, Fast CGI, or mod_perl (for Apache), we're going to stick with standard CGI. This will keep us from having to deal with any extraneous communication layers or APIs that might cause confusion. We can always re-visit this issue if we need to.

Perl Modules

We've already mentioned that we will be using the Text::CSV module, but we'll also be using a couple others that should have been bundled with your Perl distribution. Lines 14-16 load the strict pragma and the Text::CSV and CGI modules. Pragmas are features that are built into Perl, unlike modules which reside in external files. The strict pragma forces us to declare all subroutines, references, and subroutines before we use them. This is usually a good idea as it helps us avoid common mistakes related to playing with undefined variables. We'll be using the Text::CSV module to retrieve directory content. The CGI module is of great importance because it handles all communication between the Web server and our application.

Web Server/Script Interaction

Interaction between the Web server and PerlHoo will be performed by passing the directory path relative to $rootdir (Line 20) through the PATH_INFO environment variable. This is done by appending the relative directory path, Computers/Perl for example, to the script URL. For example, the URL for PerlHoo on Webreference is https://www.webreference.com/cgi-bin/perl/perlhoo.pl. If we wanted to look at the resources for Computers/Perl, the url would be https://www.webreference.com/cgi-bin/perl/perlhoo.pl/Computers/Perl. Using the same URL and looking at Lines 27-29, the value of $reldir would be Computers/Perl. Notice that in Line 27, $reldir is assigned the value of $query->path_info which contains the value of the PATH_INFO environment variable, or $ENV{'PATH_INFO'} in Perl. The next page will shed light on the significance of the PATH_INFO environment variable and how it relates to storing Web directory content.

https://www.internet.com

Produced by Jonathan Eisenzopf and
Created: Mar. 18, 1999
Revised: Mar. 22, 1999

URL: https://www.webreference.com/perl/tutorial/2/