Unformatted text preview:

LibrariesLibrariesCGI Simple Common Gateway Interface ClassAbstractThis perl library uses perl5 objects to make it easy to create Web fill-out forms and parse their contents. This package defines CGI objects, entities that contain the values of the current query string and other state variables. Using a CGI object's methods, you can examine keywords and parameters passed to your script, and create forms whose initial values are taken from the current query (thereby preserving state information). The module provides shortcut functions that produce boilerplate HTML, reducing typing and coding errors. It also provides functionality for some of the more advanced features of CGI scripting, including support for file uploads, cookies, cascading style sheets, server push, and frames.Methods Used in timeTest:new() create a new CGI object$query = new CGIheader() Print out an HTTP header that tells the browser what type of document to expect. You can provide your own MIME type if you choose, otherwise it defaults to text/html.print $query->header;Other Common Usages of CGI:A tutorial on using forms.DBI Database independent interface for PerlAbstractThe Perl DBI is a database access Application Programming Interface (API) for the Perl Language. The DBI defines a set of functions, variables and conventions that provide a consistent database interface independant of the actual database being used. It is important to remember that the DBI is just an interface. A thin layer of 'glue' between an application and one or more Database Drivers. It is the drivers which do the real work. The DBI provides a standard interface and framework for the drivers to operate within.Methods Used in timeTest:connect() Establishes a database connection (session) to the requested DBMS. Returns a database handle object if the connect succeeds.my $dbh = DBI->connect( $dsn, $user, $pass, { RaiseError => 1, AutoCommit => 1 });prepare() Prepares a single statement for later execution by the database engine and returns a reference to a statement handle object.In createTimeTest.cgi: executeSQL($dbh, qq{ CREATE TABLE Parameters ( parameter_id INTEGER NOT NULL, name_full VARCHAR(40), CONSTRAINT PK_Parameters PRIMARY KEY (parameter_id), UNIQUE KEY IDX_Parameters1(parameter_id) )}, { cgi_flag => 1 });In timeTestSubs.pm, subroutine executeSQL(): my ($dbh, $statement, $attr_hash) = @_; my $sth = $dbh->prepare($statement);----------------------------------------In populateTimeTestStations.cgi: my $sql = qq{ REPLACE INTO Stations (station_id, DSTFlag, timeOffset, sstation_id) VALUES (?, ?, ?, ?) }; my $sth = $dbh->prepare( $sql );execute() Perform whatever processing is necessary to execute the prepared statement. An undef is returned if an error occurs, a successful execute always returns true regardless of the number of rows affected.$sth->execute( $station_id, $DSTFlag, $timeOffset, $sstation_id );finish() Indicates that no more data will be fetched from this statement handle before it is either executed again or destroyed. It is rarely needed but can sometimes be helpful in order to allow the server to free up resources currently being held.$sth->finish();disconnect() Disconnects the database from the database handle. Typically only used before exiting the program.Not always used: $dbh->disconnect;bind_columns() bind_columns() is used to get the records out of the database. bind_columns binds each column to a scalar reference.$sth->bind_columns( undef, \$sstationID, \$observedOffset, $timeOffset,\$DSTFlag, \$reportedOffset );fetch() fetch() is called to fill the scalars variables bound above with the values from the database.$sth->fetch()Follow this link for more information on DBI.LWP The World-Wide Web library for PerlAbstractThe libwww-perl collection is a set of Perl modules which provides a simple and consistent application programming interface (API) to the World-Wide Web. The main focus of the library is to provide classes and functions that allow you to write WWW clients. The library also contain modules that are of more general use and even classes that help you implement simple HTTP servers.LWP::UserAgent;Abstract A class for "virtual browsers," which you use for performing requests. It is typically usedin conjunction with HTTP::Response which is a class for the responses (or error messages) that you get back from those requests. Typically, there are two objects that you will need: an object of the class LWP::UserAgent and a response object of the class HTTP::Response. Methods Used in timeTest:new()This class method constructs a new LWP::UserAgent object and returns a reference to it. Key/value pair arguments may be provided to set up the initial state of the user agent.my $ua = LWP::UserAgent->new( %$ua_hash );request() This method will dispatch the given $request object. Normally this will be an instance of the HTTP::Request class, but any object with a similar interface will do. Thereturn value is a response object. $ua->request(POST $source_uri, Content_Type => 'form-data', Content => [@$query_array] )get() This method will dispatch a GET request on the given $url. Further arguments can be given to initialize the headers of the request. These are given as separate name/value pairs. The return value is a response object.$ua->get($source_uri);HTTP::Response Encapsulates HTTP style responsesAbstract The HTTP::Response class encapsulates HTTP style responses. A response consists of a response line, some headers, and a content body. Instances of this class are created and returned by the request() method of an LWP::UserAgent object.Methods Used in timeTest:is_success() Returns true if the request was successfully received, understood or accepted.if ($response->is_success)content() Returns the content body.return $response->content;HTTP::Request Encapsulates HTTP style requestsAbstract Instances of this class are passed to the request() method of an LWP::UserAgent object.Methods Used in timeTest:Definition of a HTTP::RequestobjectNeeded to identify input to request() method$ua->request(POST $source_uri, Content_Type => 'form-data', Content => [@$query_array] )HTML::Template Module to use HTML Templates from CGI Abstract Perl module to use HTML Templates from CGI scripts. Using HTML::Template, the Perlcode and the HTML text are kept totally separate. The HTML is put in a file called a template, and the Perl code is written in separate script files and modules. The HTML is enhanced with a few


View Full Document

UNCA CSCI 343 - Simple Common Gateway Interface Class

Download Simple Common Gateway Interface Class
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Simple Common Gateway Interface Class and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Simple Common Gateway Interface Class 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?