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:
- Organizes information hierarchically
- Contains information about resources on the Internet
- Allows users to suggest new resources
- Allows editors to modify the directory content
- Is Simple to maintain
- Takes less than 1 week to develop
- Exports and imports directory content from/to multiple sources
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 thestrict
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.
Produced by Jonathan
Eisenzopf and
Created: Mar. 18, 1999
Revised: Mar. 22, 1999
URL: https://www.webreference.com/perl/tutorial/2/