=pod =head1 NAME Apache2::ASP::Manual::Intro - Introduction to Apache2::ASP =head1 SYNOPSIS <%= "Hello, World!" %>
<% for( 1...10 ) { $Response->Write( "Hello from ASP ($_)
" ); } %> =head1 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 L already then you are already familiar with the basic idea of ASP under Apache. =head1 INTRODUCTION =head2 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. =head2 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. =head1 ASP OBJECTS Like other ASP web programming environments, Apache2::ASP provides the following global objects: =head2 $Request Represents the incoming HTTP request. Has methods to handle form data, file uploads, read cookies, etc. Learn more by reading the L documentation. =head2 $Form The same as $Request->Form, it is a hashref of all incoming form and querystring values. =head2 $Response Represents the outbound HTTP communication to the client. Has methods to send content, redirect, set cookies, etc. Learn more by reading the L documentation. =head2 $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 C<$Session> object are stored within an SQL database. Learn more by reading the L documentation. =head2 $Server Represents the webserver itself and offers several utility methods that don't fit anywhere else. Learn more by reading the L documentation. =head2 $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 C<$Application> object are stored within an SQL database. Learn more by reading the L documentation. =head2 $Config Encapsulates all the configuration information for your web application. Learn more by reading the L documentation. =head1 INSTALLATION - STEP 1 - LINUX =head2 CPAN % perl -MCPAN -e shell cpan> install Apache2::ASP ... cpan> quit Then you're done and can skip ahead to L. =head2 Command Line If (for whatever reason) the CPAN installation doesn't work for you, simply extract Apache2-ASP-xxx.tar.gz, then cd to that directory and run the following commands: % su non-root-user % perl Makefile.PL % make % make test % exit % make install Because Apache2::ASP makes use of the L framework, you cannot run the tests as root unless the "nobody" user can create files in the current directory. That's life. =head2 Directory Structure You might be wondering, "What does the directory structure for an Apache2::ASP website look like?" Well, it looks like this: . |-- conf (+r) | |-- apache2-asp-config.xml | `-- httpd.conf |-- etc (+r) | | | `-- Any other files needed by the site. |-- MEDIA (+rw) |-- PAGE_CACHE (+rw) - Compiled ASP scripts will be placed here automatically. |-- tmp (+rw) | | | `-- SQLite database files go here. |-- lib (+r) | | | `-- your *.pm modules go here (i.e. Class::DBI or DBIx::Class modules, but *not* Handlers). |--handlers (+r) | |--MyHandler.pm | `--MyOtherHandler.pm `-- www (+r) |-- GlobalASA.pm `-- index.asp =head2 httpd.conf You need to add the following to your httpd.conf # 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 # Set this variable: PerlSetEnv APACHE2_ASP_APPLICATION_ROOT /path/to/your/web/application # Load up some important modules: PerlModule Apache2::ASP PerlModule Apache2::ASP::PostConfigHandler PerlPostConfigHandler Apache2::ASP::PostConfigHandler # Configuration for MediaManager: PerlModule Apache2::ASP::TransHandler PerlTransHandler Apache2::ASP::TransHandler # All *.asp files are handled by Apache2::ASP SetHandler perl-script PerlHandler Apache2::ASP # Prevent anyone from getting your GlobalASA.pm Order allow,deny Deny from all # All requests to /handlers/* will be handled by their respective handler: SetHandler perl-script PerlHandler Apache2::ASP # Main website: ServerName yoursite.yourhost.com DocumentRoot /path/to/your/web/application/htdocs =head2 XML Config File Then create a directory at C at the root of your application. The Apache server process should be able to read and write in this directory. Then, in C add the file C. It will contain data like this: .* 1 DefaultApp @ServerRoot@ @ServerRoot@/handlers @ServerRoot@/MEDIA @ServerRoot@/htdocs @ServerRoot@/PAGE_CACHE Apache2::ASP::ApplicationStateManager::SQLite DBI:SQLite:dbname=/tmp/apache2_asp_state Apache2::ASP::SessionStateManager::SQLite localhost session-id DBI:SQLite:dbname=/tmp/apache2_asp_state 30 @ServerRoot@/lib DBI:mysql:databasename:localhost abc 123 =head1 INSTALLATION - STEP 1 - WINDOWS Although performance is poor on Windows, it works fine for testing or developing. I would not recommend running a production web application on Windows however. =head1 INSTALLATION - STEP 2 Then, in your database, create a table with the following structure: CREATE TABLE asp_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 (re)start Apache and installation is complete. Now you need some ASP scripts. If your website is in C then create a file "C" in C. Your C could contain something like the following: <%= "Hello, World!" %>
<% for( 1...10 ) { $Response->Write( "Hello from ASP ($_)
" ); } %> Then point your browser to C 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. =head1 BUGS It's possible that some bugs have found their way into this release. Use RT L to submit bug reports. =head1 HOMEPAGE Please visit the Apache2::ASP homepage at L to see examples of Apache2::ASP in action. =head1 AUTHOR John Drago L =head1 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. =cut