NAME
Apache2::ASP - ASP for a mod_perl2 environment.
SYNOPSIS
<%= "Hello, World!" %>
<%
for( 1...10 ) {
$Response->Write( "Hello from ASP ($_)
" );
}
%>
DESCRIPTION
Apache2::ASP is a new implementation of the ASP web programming for the
mod_perl2 environment. Its aim is high performance, stability,
scalability and ease of use.
If you have used Apache::ASP already then you are already familiar with
the basic idea of ASP under Apache.
INTRODUCTION
What is Apache2::ASP?
Apache2::ASP is a web programming environment that helps simplify web
programming with Perl under mod_perl2. Apache2::ASP allows you to easily
embed Perl into web pages using the "<%" and "%>" tags that are familiar
to anyone who has used ASP or JSP in the past.
What does Apache2::ASP offer?
Apache2::ASP offers programmers the ability to program web pages without
spending time on details like session state management, file uploads or
template systems.
ASP OBJECTS
Like other ASP web programming environments, Apache2::ASP provides the
following global objects:
$Request
Represents the incoming HTTP request. Has methods to handle form data,
file uploads, read cookies, etc.
Learn more by reading the Apache2::ASP::Request documentation.
$Response
Represents the outbound HTTP communication to the client. Has methods to
send content, redirect, set cookies, etc.
Learn more by reading the Apache2::ASP::Response documentation.
$Session
Represents data that should persist beyond the lifetime of a single
request. For example, the user's logged in state, user id, etc.
The contents of the $Session object are stored within an SQL database.
Learn more by reading the Apache2::ASP::Session documentation.
$Server
Represents the webserver itself and offers several utility methods that
don't fit anywhere else.
Learn more by reading the Apache2::ASP::Server documentation.
$Application
Represents data that should be shared and persisted throughout the
entire web application. For example, database connection strings, the
number of active users, etc.
The contents of the $Application object are stored within an SQL
database.
Learn more by reading the Apache2::ASP::Application documentation.
INSTALLATION
% perl Makefile.PL
% make
% make test
% make install
Then, in your httpd.conf:
# Declare this important variable:
PerlSetEnv APACHE2_APPLICATION_ROOT /path/to/your/website
# Needed for CGI::Apache2::Wrapper to work properly:
LoadModule apreq_module /usr/local/apache2/modules/mod_apreq2.so
# Set the directory index:
DirectoryIndex index.asp
# Load up some important modules:
PerlModule Apache::DBI
PerlModule DBI
PerlModule DBD::mysql # or whatever database you will keep your session data in
PerlModule CGI::Apache2::Wrapper
PerlModule Apache2::ASP
PerlModule Apache2::Directive
PerlModule Apache2::RequestRec
PerlModule Apache2::RequestIO
PerlModule Apache2::Connection
PerlModule Apache2::SubRequest
# All *.asp files are handled by Apache2::ASP:
SetHandler perl-script
PerlHandler Apache2::ASP
# All requests to /handlers/* will be handled by their respective handler:
SetHandler perl-script
PerlResponseHandler Apache2::ASP
Then, in "/path/to/your/website/conf" add the file
"apache2-asp-config.xml". It will contain data like this:
mydbusername
secret!password
mysql
my_session_database
localhost
.mywebsite.com
session-id
Then, in your database, create a table with the following structure:
CREATE TABLE sessions (
session_id CHAR(32) PRIMARY KEY NOT NULL,
session_data BLOB,
created_on DATETIME,
modified_on DATETIME
);
Also create a table with the following structure:
CREATE TABLE asp_applications (
application_id VARCHAR(100) PRIMARY KEY NOT NULL,
application_data BLOB
);
Simply restart Apache and installation is complete. Now you need some
ASP scripts.
If your website is in "/var/www/html" then create a file ""index.asp""
in "/var/www/html".
Your "index.asp" could contain something like the following:
<%= "Hello, World!" %>
<%
for( 1...10 ) {
$Response->Write( "Hello from ASP ($_)
" );
}
%>
Then point your browser to "http://yoursite.com/index.asp" and see what
you get.
If everything was configured correctly, the output would look like:
Hello, World!
Hello from ASP (1)
Hello from ASP (2)
Hello from ASP (3)
Hello from ASP (4)
Hello from ASP (5)
Hello from ASP (6)
Hello from ASP (7)
Hello from ASP (8)
Hello from ASP (9)
Hello from ASP (10)
If you get an error instead, check out your error log to find out why.
Directory Structure
You might be wondering, "What does the directory structure for an
Apache2::ASP website look like?"
Well, it looks like this:
.
|-- conf
| |-- apache2-asp-config.xml
| `-- httpd.conf
|--handlers
| |--MyHandler.pm
| `--MyOtherHandler.pm
`-- www
|-- GlobalASA.pm
`-- index.asp
AUTHOR
John Drago jdrago_999@yahoo.com
COPYRIGHT AND LICENSE
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the
same terms as Perl itself.