Apache::ASP
<% Web Applications with Apache & mod_perl %>
  INTRO
  INSTALL
  CONFIG
  SYNTAX
  EVENTS
  OBJECTS
  SSI
  SESSIONS
  XML/XSLT
  CGI
  PERLSCRIPT
  STYLE GUIDE
% FAQ
  TUNING
  CREDITS
  SUPPORT
  SITES USING
  TESTIMONIALS
  RESOURCES
  TODO
  CHANGES
  LICENSE

  EXAMPLES

Powered by Apache::ASP
Powered by ModPerl and Apache
Powered by Perl
FAQ
The following are some frequently asked questions about Apache::ASP.

Installation How can I use $Session to store a $dbh database handle ?
Examples don't work, I see the ASP script in the browser?
Apache Expat vs. XML perl parsing causing segfaults, what do I do? Development
Why do variables retain their values between requests? How is database connectivity handled?
Apache errors on the PerlHandler or PerlModule directives ? What is the best way to debug an ASP application ?
Error: no request object (Apache=SCALAR(0x???????):) How are file uploads handled?
I am getting a tie or MLDBM / state error message, what do I do? How do I access the ASP Objects in general?
Can I print() in ASP?
Sessions Do I have access to ActiveX objects?
How can I use $Session to store complex data structures.  
How can I keep search engine spiders from killing the session manager?  

Installation

Examples don't work, I see the ASP script in the browser?

This is most likely that Apache is not configured to execute
the Apache::ASP scripts properly.  Check the INSTALL QuickStart
section for more info on how to quickly set up Apache to 
execute your ASP scripts.
	
	

Apache Expat vs. XML perl parsing causing segfaults, what do I do?

Make sure to compile apache with expat disabled.  The
./make_httpd/build_httpds.sh in the distribution will do 
this for you, with the --disable-rule=EXPAT in particular:
 cd ../$APACHE
 echo "Building apache =============================="
 ./configure \
    --prefix=/usr/local/apache \
    --activate-module=src/modules/perl/libperl.a \
    --enable-module=ssl \
    --enable-module=proxy \
    --enable-module=so \
    --disable-rule=EXPAT

                   ^^^^^
keywords: segmentation fault, segfault seg fault

Why do variables retain their values between requests?

Unless scoped by my() or local(), perl variables in mod_perl
are treated as globals, and values set may persist from one 
request to another. This can be seen in as simple a script
as this:
  <HTML><BODY>
    $counter++;
    $Response->Write("<BR>Counter: $counter");
  </BODY></HTML>
The value for $counter++ will remain between requests. Generally use of globals in this way is a BAD IDEA, and you can spare yourself many headaches if do "use strict" perl programming which forces you to explicity declare globals like:
  use vars qw($counter);
You can make all your Apache::ASP scripts strict by default by setting:
  PerlSetVar UseStrict 1

Apache errors on the PerlHandler or PerlModule directives ?

You get an error message like this:
 Invalid command 'PerlModule', perhaps mis-spelled or defined by a 
 module not included in the server configuration.
You do not have mod_perl correctly installed for Apache. The PerlHandler and PerlModule directives in Apache *.conf files are extensions enabled by mod_perl and will not work if mod_perl is not correctly installed.
Common user errors are not doing a 'make install' for mod_perl, which installs the perl side of mod_perl, and not starting the right httpd after building it. The latter often occurs when you have an old apache server without mod_perl, and you have built a new one without copying over to its proper location.
To get mod_perl, go to http://perl.apache.org

Error: no request object (Apache=SCALAR(0x???????):)

Your Apache + mod_perl build is not working properly, 
and is likely a RedHat Linux RPM DSO build.  Make sure
you statically build your Apache + mod_perl httpd,
recompiled fresh from the sources.
	
	

I am getting a tie or MLDBM / state error message, what do I do?

Make sure the web server or you have write access to the eg directory,
or to the directory specified as Global in the config you are using.
Default for Global is the directory the script is in (e.g. '.'), but should
be set to some directory not under the www server document root,
for security reasons, on a production site.
Usually a
 chmod -R -0777 eg
will take care of the write access issue for initial testing purposes.
Failing write access being the problem, try upgrading your version of Data::Dumper and MLDBM, which are the modules used to write the state files.

Sessions

How can I use $Session to store complex data structures.

Very carefully.  Please read the $Session documentation in 
the OBJECTS section.  You can store very complex objects
in $Session, but you have to understand the limits, and 
the syntax that must be used to make this happen.
In particular, stay away from statements that that have more than one level of indirection on the left side of an assignment like:
  $Session->{complex}{object} = $data;

How can I keep search engine spiders from killing the session manager?

If you want to disallow session creation for certain non web 
browser user agents, like search engine spiders, you can use a mod_perl
PerlInitHandler like this to set configuration variables at runtime:
 # put the following code into httpd.conf and stop/start apache server
 PerlInitHandler My::InitHandler

 <Perl>

  package My::InitHandler;
  use Apache;

  sub handler {
    my $r = shift; # get the Apache request object

    # if not a Mozilla User Agent, then disable sessions explicitly
    unless($r->headers_in('User-Agent') =~ /^Mozilla/) {
       $r->dir_config('AllowSessionState', 'Off');
    }

    return 200; # return OK mod_perl status code
  }

  1;

 </Perl>
This will configure your environment before Apache::ASP executes and sees the configuration settings. You can use the mod_perl API in this way to configure Apache::ASP at runtime.
Note that the Session Manager is very robust on its own, and denial of service attacks of the types that spiders and other web bots normally execute are not likely to affect the Session Manager significantly.

How can I use $Session to store a $dbh database handle ?

You cannot use $Session to store a $dbh handle.  This can 
be awkward for those coming from the IIS/NT world, where
you could store just about anything in $Session, but this
boils down to a difference between threads vs. processes.
Database handles often have per process file handles open, which cannot be shared between requests, so though you have stored the $dbh data in $Session, all the other initializations are not relevant in another httpd process.
All is not lost! Apache::DBI can be used to cache database connections on a per process basis, and will work for most cases.

Development

How is database connectivity handled?

Database connectivity is handled through perl's DBI & DBD interfaces.
In the UNIX world, it seems most databases have cross platform support in perl.
You can find the book on DBI programming at http://www.oreilly.com/catalog/perldbi/
DBD::ODBC is often your ticket on Win32. On UNIX, commercial vendors like OpenLink Software (http://www.openlinksw.com/) provide the nuts and bolts for ODBC.
Database connections can be cached per process with Apache::DBI.

What is the best way to debug an ASP application ?

There are lots of perl-ish tricks to make your life developing
and debugging an ASP application easier.  For starters,
you will find some helpful hints by reading the 
$Response->Debug() API extension, and the Debug
configuration directive.
	
	

How are file uploads handled?

Please see the CGI section.  File uploads are implemented
through CGI.pm which is loaded at runtime only for this purpose.
This is the only time that CGI.pm will be loaded by Apache::ASP,
which implements all other cgi-ish functionality natively.  The
rationale for not implementing file uploads natively is that 
the extra 100K in memory for CGI.pm shouldn't be a big deal if you 
are working with bulky file uploads.
	
	

How do I access the ASP Objects in general?

All the ASP objects can be referenced through the main package with
the following notation:
 $main::Response->Write("html output");
This notation can be used from anywhere in perl, including routines registered with $Server->RegisterCleanup().
You use the normal notation in your scripts, includes, and global.asa:
 $Response->Write("html output");

Can I print() in ASP?

Yes.  You can print() from anywhere in an ASP script as it aliases
to the $Response->Write() method.  Using print() is portable with
PerlScript when using Win32::ASP in that environment.
	
	

Do I have access to ActiveX objects?

Only under Win32 will developers have access to ActiveX objects through
the perl Win32::OLE interface.  This will remain true until there
are free COM ports to the UNIX world.  At this time, there is no ActiveX
for the UNIX world.