view release on metacpan or search on metacpan
} else {
return &DSOError($rtest);
}
}
# better error checking ?
$filename ||= $r->filename();
# using _ is optimized to use last stat() record
return(404) if (! -e $filename or -d _);
# alias $0 to filename, bind to glob for bug workaround
local *0 = \$filename;
# ASP object creation, a lot goes on in there!
# method call used for speed optimization, as OO calls are slow
my $self = &Apache::ASP::new('Apache::ASP', $r, $filename);
# for runtime use/require library loads from global/INCDir
# do this in the handler section to cover all the execution stages
# following object set up as possible.
local @INC = ($self->{global}, $INCDir, @INC);
# Execute if no errors
$self->{errs} || &Run($self);
# moved print of object to the end, so we'll pick up all the
# runtime config directives set while the code is running
$self->{dbg} && $self->Debug("ASP Done Processing $self", $self );
# error processing
my $dirname = $1 || '.';
my $basename = $2;
chdir($dirname) || die("can't chdir to $dirname: $!");
# temp object just to call config() on, do not bless since we
# do not want the object to be DESTROY()'d
my $dir_config = $r->dir_config;
my $headers_in = $r->headers_in;
my $self = { r => $r, dir_config => $dir_config };
# global is the default for the state dir and also
# a default lib path for perl, as well as where global.asa
# can be found
my $global = &get_dir_config($dir_config, 'Global') || '.';
$global = &AbsPath($global, $dirname);
# asp object is handy for passing state around
$self = bless
{
'basename' => $basename,
'cleanup' => [],
'dbg' => &get_dir_config($dir_config, 'Debug') || 0, # debug level
'destroy' => 1,
'dir_config' => $dir_config,
'headers_in' => $headers_in,
filename => $filename,
global => $global,
global_package => &get_dir_config($dir_config, 'GlobalPackage'),
inode_names => &get_dir_config($dir_config, 'InodeNames'),
no_cache => &get_dir_config($dir_config, 'NoCache'),
'r' => $r, # apache request object
start_time => $start_time,
stat_scripts => &config($self, 'StatScripts', undef, 1),
stat_inc => &get_dir_config($dir_config, 'StatINC'),
stat_inc_match => &get_dir_config($dir_config, 'StatINCMatch'),
use_strict => &get_dir_config($dir_config, 'UseStrict'),
win32 => ($^O eq 'MSWin32') ? 1 : 0,
xslt => &get_dir_config($dir_config, 'XSLT'),
}
# gzip content encoding option by ime@iae.nl 28/4/2000
my $compressgzip_config = &get_dir_config($dir_config, 'CompressGzip');
if($compressgzip_config) {
if($self->LoadModule('Gzip','Compress::Zlib')) {
$self->{compressgzip} = 1;
}
}
# must have global directory into which we put the global.asa
# and possibly state files, optimize out the case of . or ..
if($self->{global} !~ /^(\.|\.\.)$/) {
-d $self->{global} or
$self->Error("global path, $self->{global}, is not a directory");
}
# includes_dir calculation
if($filename =~ m,^((/|[a-zA-Z]:).*[/\\])[^/\\]+?$,) {
$self->{dirname} = $1;
} else {
$self->{dirname} = '.';
}
$self->{includes_dir} = [
$self->{dirname},
$self->{global},
split(/;/, &config($self, 'IncludesDir') || ''),
];
# register cleanup before the state files get set in InitObjects
# this way DESTROY gets called every time this script is done
# we must cache $self for lookups later
&RegisterCleanup($self, sub { $self->DESTROY });
#### WAS INIT OBJECTS, REMOVED DECOMP FOR SPEED
# GLOBALASA, RESPONSE, REQUEST, SERVER
# always create these
# global_asa assigns itself to parent object automatically
my $global_asa = &Apache::ASP::GlobalASA::new($self);
$self->{Request} = &Apache::ASP::Request::new($self);
$self->{Response} = &Apache::ASP::Response::new($self);
# Server::new() is just one line, so execute directly
$self->{Server} = bless {asp => $self}, 'Apache::ASP::Server';
#&Apache::ASP::Server::new($self);
# After GlobalASA Init, init the package that this script will execute in
# must be here, and not end of new before things like Application_OnStart get run
# UniquePackages & NoCache configs do not work together, NoCache wins here
if(&config($self, 'UniquePackages')) {
# id is not generally useful for the ASP object now, so calculate
# it here now, only to twist the package object for this script
# pass in basename for where to find the file for InodeNames, and the full path
# for the FileId otherwise
my $package = $global_asa->{'package'}.'::'.&FileId($self, $self->{basename}, $self->{filename});
$self->{'package'} = $package;
$self->{init_packages} = ['main', $global_asa->{'package'}, $self->{'package'}];
} else {
$self->{'package'} = $global_asa->{'package'};
$self->{init_packages} = ['main', $global_asa->{'package'}];
}
$self->{state_dir} = &config($self, 'StateDir', undef, $self->{global}.'/.state');
$self->{state_dir} =~ tr///; # untaint
# if no state has been config'd, then set up none of the
# state objects: Application, Internal, Session
unless(&get_dir_config($dir_config, 'NoState')) {
# load at runtime for CGI environments, preloaded for mod_perl
require Apache::ASP::StateManager;
&InitState($self);
}
}
# compiled include args handling
my $has_args = $3;
my $args = undef;
if($has_args) {
$args = $has_args;
$args =~ s/^\s+args\s*\=\s*\"?//sgo;
}
# global directory, as well as includes dirs
my $include = &SearchDirs($self, $file);
unless(defined $include) {
$self->Error("include file with name $file does not exist");
return;
}
if($self->{dbg}) {
if($include ne $file) {
$self->{dbg} && $self->Debug("found $file at $include");
}
}
# trap the includes here, at 100 levels like perl debugger
if(defined($args) || $self->{compile_includes}) {
# because the script is literally different whether there
# are includes or not, whether we are compiling includes
# need to be part of the script identifier, so the global
# caching does not return a script with different preferences.
$args ||= '';
$self->{dbg} && $self->Debug("runtime exec of dynamic include $file args (".
($args).')');
$data .= "<% \$Response->Include('$include', $args); %>";
# compile include now, so Loading() works for dynamic includes too
unless($self->CompileInclude($include)) {
$self->Error("compiling include $include failed when compiling script");
}
$self->Error("error compiling $self->{basename}: $@");
return;
}
$self->{run_perl_script} = $compiled->{perl};
}
# must have all the variabled defined outside the scope
# of the eval in case End() jumps to the goto below, since
# the variables in the local eval{} scope will be cleared
# upon return.
my $global_asa = $self->{GlobalASA};
eval {
$global_asa->{'exists'} && $global_asa->ScriptOnStart;
$self->{errs} || $self->Execute($compiled->{code});
APACHE_ASP_EXECUTE_END:
$self->{errs} || ( $global_asa->{'exists'} && $global_asa->ScriptOnEnd() );
$self->{errs} || $self->{Response}->EndSoft();
};
if($@) {
# its not really a compile time error, but might be useful
# to render for a runtime error anyway
# $self->CompileError($compiled->{perl});
$self->Error("error executing $self->{basename}: $@");
}
! $@;
}
sub Execute {
my($self, $code) = @_;
$code || die("no subroutine passed to Execute()");
$self->{dbg} && $self->Debug("executing $code");
# set up globals as early as Application_OnStart, also
# allows variables to be changed in Script_OnStart for running script
&InitPackageGlobals($self);
if(my $ref = ref $code) {
if($ref eq 'CODE') {
eval { &$code(); };
} elsif($ref eq 'SCALAR') {
# $self->{dbg} && $self->Debug("writing cached static file data $code, length: ".length($$code));
$self->{Response}->WriteRef($code);
} else {
Please be sure to add this configuration before Apache::ASP is loaded
via PerlModule, or a PerlRequire statement.
=head1 CONFIG
You may use a <Files ...> directive in your httpd.conf
Apache configuration file to make Apache::ASP start ticking. Configure the
optional settings if you want, the defaults are fine to get started.
The settings are documented below.
Make sure Global is set to where your web applications global.asa is
if you have one!
PerlModule Apache::ASP
<Files ~ (\.asp)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global .
PerlSetVar StateDir /tmp/asp
</Files>
to mixed media per directory. For building many separate
ASP sites, you might want to use separate .htaccess files,
or <Files> tags in <VirtualHost> sections, the latter being
better for performance.
=head2 Core
=item Global
Global is the nerve center of an Apache::ASP application, in which
the global.asa may reside defining the web application's
event handlers.
This directory is pushed onto @INC, so you will be able
to "use" and "require" files in this directory, and perl modules
developed for this application may be dropped into this directory,
for easy use.
Unless StateDir is configured, this directory must be some
writeable directory by the web server. $Session and $Application
object state files will be stored in this directory. If StateDir
Global directory for this purpose.
Includes, specified with <!--#include file=somefile.inc-->
or $Response->Include() syntax, may also be in this directory,
please see section on includes for more information.
PerlSetVar Global /tmp
=item GlobalPackage
Perl package namespace that all scripts, includes, & global.asa
events are compiled into. By default, GlobalPackage is some
obscure name that is uniquely generated from the file path of
the Global directory, and global.asa file. The use of explicitly
naming the GlobalPackage is to allow scripts access to globals
and subs defined in a perl module that is included with commands like:
in perl script: use Some::Package;
in apache conf: PerlModule Some::Package
PerlSetVar GlobalPackage Some::Package
=item UniquePackages
default 0. Set to 1 to compile each script into its own perl package,
so that subroutines defined in one script will not collide with another.
By default, ASP scripts in a web application are compiled into the
*same* perl package, so these scripts, their includes, and the
global.asa events all share common globals & subroutines defined by each other.
The problem for some developers was that they would at times define a
subroutine of the same name in 2+ scripts, and one subroutine definition would
redefine the other one because of the namespace collision.
PerlSetVar UniquePackages 0
=item DynamicIncludes
default 0. SSI file includes are normally inlined in the calling
script, and the text gets compiled with the script as a whole.
Also, multiple includes directories may be set by creating
a directory list separated by a semicolon ';' as in
PerlSetVar IncludesDir ../shared;/usr/local/asp/shared
Using IncludesDir in this way creates an includes search
path that would look like ., Global, ../shared, /usr/local/asp/shared
The current directory of the executing script is checked first
whenever an include is specified, then the Global directory
in which the global.asa resides, and finally the IncludesDir
setting.
=item NoCache
Default 0, if set to 1 will make it so that neither script nor
include compilations are cached by the server. Using this configuration
will save on memory but will slow down script execution. Please
see the TUNING section for other strategies on improving site performance.
PerlSetVar NoCache 0
This way one may point StateDir to /tmp/myaspapp, and make one's ASP
application scream with speed.
PerlSetVar StateDir ./.state
=item StateManager
default 10, this number specifies the numbers of times per SessionTimeout
that timed out sessions are garbage collected. The bigger the number,
the slower your system, but the more precise Session_OnEnd's will be
run from global.asa, which occur when a timed out session is cleaned up,
and the better able to withstand Session guessing hacking attempts.
The lower the number, the faster a normal system will run.
The defaults of 20 minutes for SessionTimeout and 10 times for
StateManager, has dead Sessions being cleaned up every 2 minutes.
PerlSetVar StateManager 10
=item StateDB
Default 0, this NON-PORTABLE configuration will allow sessions to span
multiple web sites that match the same domain root. This is useful if
your web sites are hosted on the same machine and can share the same
StateDir configuration, and you want to shared the $Session data
across web sites. Whatever this is set to, that will add a
; domain=$CookieDomain
part to the Set-Cookie: header set for the session-id cookie.
PerlSetVar CookieDomain .your.global.domain
=item SessionTimeout
Default 20 minutes, when a user's session has been inactive for this
period of time, the Session_OnEnd event is run, if defined, for
that session, and the contents of that session are destroyed.
PerlSetVar SessionTimeout 20
=item SecureSession
default 0, set to 1 if you want to disallow the use of cookies
for session id passing, and only allow session ids to be passed
on the query string via SessionQuery and SessionQueryParse settings.
PerlSetVar SessionQueryForce 1
=head2 Developer Environment
=item UseStrict
default 0, if set to 1, will compile all scripts, global.asa
and includes with "use strict;" inserted at the head of
the file, saving you from the painful process of strictifying
code that was not strict to begin with.
Because of how essential "use strict" programming is in
a mod_perl environment, this default might be set to 1
one day, but this will be up for discussion before that
decision is made.
Note too that errors triggered by "use strict" are
The StatINCMatch setting should be a regular expression like: Struct|LWP
which would match on reloading Class/Struct.pm, and all the LWP/.*
libraries.
If you define StatINCMatch, you do not need to define StatINC.
PerlSetVar StatINCMatch .*
=item StatScripts
default 1, if set to 0, changed scripts, global.asa, and includes
will not be reloaded. Coupled with Apache mod_perl startup and restart
handlers executing Apache::ASP->Loader() for your application
this allows your application to be frozen, and only reloaded on the
next server restart or stop/start.
There are a few advantages for not reloading scripts and modules
in production. First there is a slight performance improvement
by not having to stat() the script, its includes and the global.asa
every request.
From an application deployment standpoint, you
also gain the ability to deploy your application as a
snapshot taken when the server starts and restarts.
This provides you with the reassurance that during a
production server update from development sources, you
do not have to worry with sources being used for the
wrong libraries and such, while they are all being
copied over.
Please feel free to suggest your favorite development
environment for this list.
=head1 EVENTS
=head2 Overview
The ASP platform allows developers to create Web Applications.
In fulfillment of real software requirements, ASP allows
event-triggered actions to be taken, which are defined in
a global.asa file. The global.asa file resides in the
Global directory, defined as a config option, and may
define the following actions:
Action Event
------ ------
Script_OnStart * Beginning of Script execution
Script_OnEnd * End of Script execution
Script_OnFlush * Before $Response being flushed to client.
Script_OnParse * Before script compilation
Application_OnStart Beginning of Application
Application_OnEnd End of Application
Session_OnStart Beginning of user Session.
Session_OnEnd End of user Session.
* These are API extensions that are not portable, but were
added because they are incredibly useful
These actions must be defined in the $Global/global.asa file
as subroutines, for example:
sub Session_OnStart {
$Application->{$Session->SessionID()} = started;
}
Sessions are easy to understand. When visiting a page in a
web application, each user has one unique $Session. This
session expires, after which the user will have a new
$Session upon revisiting.
A web application starts when the user visits a page in that
application, and has a new $Session created. Right before
the first $Session is created, the $Application is created.
When the last user $Session expires, that $Application
expires also. For some web applications that are always busy,
the Application_OnEnd event may never occur.
=head2 Script_OnStart & Script_OnEnd
The script events are used to run any code for all scripts
in an application defined by a global.asa. Often, you would
like to run the same code for every script, which you would
otherwise have to add by hand, or add with a file include,
but with these events, just add your code to the global.asa,
and it will be run.
There is one caveat. Code in Script_OnEnd is not guaranteed
to be run when $Response->End() is called, since the program
execution ends immediately at this event. To always run critical
code, use the API extension:
$Server->RegisterCleanup()
=head2 Session_OnStart
of an application ever run will never have its Session_OnEnd run.
Thus I would not put anything mission-critical in the Session_OnEnd,
just stuff that would be nice to run whenever it gets run.
=head2 Script_OnFlush
API extension. This event will be called prior to flushing
the $Response buffer to the web client. At this time,
the $Response->{BinaryRef} buffer reference may be used to modify
the buffered output at runtime to apply global changes to scripts
output without having to modify all the scripts.
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
Check out the ./site/eg/global.asa for an example of its use.
=head2 Script_OnParse
This event allows one to set up a source filter on the script text,
allowing one to change the script on the fly before the compilation
stage occurs. The script text is available in the $Server->{ScriptRef}
scalar reference, and can be accessed like so:
sub Script_OnParse {
my $code = $Server->{ScriptRef}
PerlFixupHandler
PerlHandler
PerlLogHandler
PerlCleanupHandler
For straight Apache::ASP programming, there are some
equivalents, say Script_OnStart event instead of Init/Fixup
stages, or $Server->RegisterCleanup() for Log/Cleanup stages,
but you can do things in the mod_perl handlers that you
cannot do in Apache::ASP, especially if you want to handle
all files globally, and not just ASP scripts.
For many Apache::* modules for use with mod_perl, of which
Apache::ASP is just one, check out
http://perl.apache.org/src/apache-modlist.html
To gain access to the ASP objects like $Session outside
in a non-PerlHandler mod_perl handler, you may use this API:
my $ASP = Apache::ASP->new($r); # $r is Apache->request object
}
1;
=head1 OBJECTS
The beauty of the ASP Object Model is that it takes the
burden of CGI and Session Management off the developer,
and puts them in objects accessible from any
ASP script & include. For the perl programmer, treat these objects
as globals accessible from anywhere in your ASP application.
The Apache::ASP object model supports the following:
Object Function
------ --------
$Session - user session state
$Response - output to browser
$Request - input from browser
$Application - application state
$Server - general methods
These objects, and their methods are further defined in the
following sections.
If you would like to define your own global objects for use
in your scripts and includes, you can initialize them in
the global.asa Script_OnStart like:
use vars qw( $Form $Site ); # declare globals
sub Script_OnStart {
$Site = My::Site->new; # init $Site object
$Form = $Request->Form; # alias form data
$Server->RegisterCleanup(sub { # garbage collection
$Site->DESTROY;
$Site = $Form = undef;
});
}
In this way you can create site wide application objects
This object manages the output from the ASP Application and the
client web browser. It does not store state information like the
$Session object but does have a wide array of methods to call.
=over
=item $Response->{BinaryRef}
API extension. This is a perl reference to the buffered output of
the $Response object, and can be used in the Script_OnFlush
global.asa event to modify the buffered output at runtime
to apply global changes to scripts output without having to
modify all the scripts. These changes take place before
content is flushed to the client web browser.
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
Check out the ./site/eg/global.asa for an example of its use.
=item $Response->{Buffer}
Default 1, when TRUE sends output from script to client only at
the end of processing the script. When 0, response is not buffered,
and client is sent output as output is generated by the script.
=item $Response->{CacheControl}
Default "private", when set to public allows proxy servers to
=item $Response->{IsClientConnected}
1 if web client is connected, 0 if not. This value
starts set to 1, and will be updated whenever a
$Response->Flush() is called. If BufferingOn is
set, by default $Response->Flush() will only be
called at the end of the HTML output.
As of version 2.23 this value is updated correctly
before global.asa Script_OnStart is called, so
global script termination may be correctly handled
during that event, which one might want to do
with excessive user STOP/RELOADS when the web
server is very busy.
An API extension $Response->IsClientConnected
may be called for refreshed connection status
without calling first a $Response->Flush
=item $Response->{PICS}
$fileup->{Mime-Header};
$fileup->{TempFile};
=item $Request->Form($name)
Returns the value of the input of name $name used in a form
with POST method. If $name is not specified, returns a ref to
a hash of all the form data. One can use this hash to
create a nice alias to the form data like:
# in global.asa
use vars qw( $Form );
sub Script_OnStart {
$Form = $Request->Form;
}
# then in ASP scripts
<%= $Form->{var} %>
File upload data will be loaded into $Request->Form('file_field'),
where the value is the actual file name of the file uploaded, and
the contents of the file can be found by reading from the file
samples ./site/eg/file_upload.asp
=item $Request->Params($name)
API extension. If RequestParams CONFIG is set, the $Request->Params
object is created with combined contents of $Request->QueryString
and $Request->Form. This is for developer convenience simlar
to CGI.pm's param() method. Just like for $Response->Form,
one could create a nice alias like:
# in global.asa
use vars qw( $Params );
sub Script_OnStart {
$Params = $Request->Params;
}
=item $Request->QueryString($name)
Returns the value of the input of name $name used in a form
with GET method, or passed by appending a query string to the end of
a url as in http://localhost/?data=value.
session ids are stored in $Application during Session_OnStart, with
full access to these sessions for administrative purposes.
Be careful not to expose full session ids over the net, as they
could be used by a hacker to impersonate another user. So when
creating a session manager, for example, you could create
some other id to reference the SessionID internally, which
would allow you to control the sessions. This kind of application
would best be served under a secure web server.
The ./site/eg/global_asa_demo.asp script makes use of this routine
to display all the data in current user sessions.
=item $Application->SessionCount()
This NON-PORTABLE method returns the current number of active sessions
in the application, and is enabled by the SessionCount configuration setting.
This method is not implemented as part of the original ASP
object model, but is implemented here because it is useful. In particular,
when accessing databases with license requirements, one can monitor usage
effectively through accessing this value.
,the .inc being merely a convention, text from the included
file will be inserted directly into the script being executed
and the script will be compiled as a whole. Whenever the
script or any of its includes change, the script will be
recompiled.
Includes go a great length to promote good decomposition
and code sharing in ASP scripts, but they are still
fairly static. As of version .09, includes may have dynamic
runtime execution, as subroutines compiled into the global.asa
namespace. The first way to invoke includes dynamically is
<!--#include file=filename.inc args=@args-->
If @args is specified, Apache::ASP knows to execute the
include at runtime instead of inlining it directly into
the compiled code of the script. It does this by
compiling the script at runtime as a subroutine, and
caching it for future invocations. Then the compiled
subroutine is executed and has @args passed into its
> The ->{Item} property does not work, use the ->Item() method.
=head1 STYLE GUIDE
Here are some general style guidelines. Treat these as tips for
best practices on Apache::ASP development if you will.
=head2 UseStrict
One of perl's blessings is also its bane, variables do not need to be
declared, and are by default globally scoped. The problem with this in
mod_perl is that global variables persist from one request to another
even if a different web browser is viewing a page.
To avoid this problem, perl programmers have often been advised to
add to the top of their perl scripts:
use strict;
In Apache::ASP, you can do this better by setting:
PerlSetVar UseStrict 1
which will cover both script & global.asa compilation and will catch
"use strict" errors correctly. For perl modules, please continue to
add "use strict" to the top of them.
Because its so essential in catching hard to find errors, this
configuration will likely become the default in some future release.
For now, keep setting it.
=head2 Do not define subroutines in scripts.
DO NOT add subroutine declarations in scripts. Apache::ASP is optimized
}
The biggest problem with subroutines defined in subroutines is the
side effect of creating closures, which will not behave as usually
desired in a mod_perl environment. To understand more about closures,
please read up on them & "Nested Subroutines" at:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html
Instead of defining subroutines in scripts, you may add them to your sites
global.asa, or you may create a perl package or module to share
with your scripts. For more on perl objects & modules, please see:
http://perldoc.perl.org/perlobj.html
=head2 Use global.asa's Script_On* Events
Chances are that you will find yourself doing the same thing repeatedly
in each of your web application's scripts. You can use Script_OnStart
and Script_OnEnd to automate these routine tasks. These events are
called before and after each script request.
For example, let's say you have a header & footer you would like to
include in the output of every page, then you might:
# global.asa
sub Script_OnStart {
$Response->Include('header.inc');
}
sub Script_OnEnd {
$Response->Include('footer.inc');
}
Or let's say you want to initialize a global database connection
for use in your scripts:
# global.asa
use Apache::DBI; # automatic persistent database connections
use DBI;
use vars qw($dbh); # declare global $dbh
sub Script_OnStart {
# initialize $dbh
$dbh = DBI->connect(...);
# force you to explicitly commit when you want to save data
$Server->RegisterCleanup(sub { $dbh->rollback; });
}
sub Script_OnEnd {
--enable-module=so \
--disable-rule=EXPAT
^^^^^
keywords: segmentation fault, segfault seg fault
=item 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
=item Apache errors on the PerlHandler or PerlModule directives ?
=item 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");
=item 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.
=item Do I have access to ActiveX objects?
a RAM disk and would be a good place to set the "StateDir" config
setting to. When cached file systems are used there is little
performance penalty for using state files. Linux tends to do a good job
caching its file systems, so pick a StateDir for ease of system
administration.
On Win32 systems, where mod_perl requests are serialized, you
can freely use SessionSerialize to make your $Session requests
faster, and you can achieve similar performance benefits for
$Application if you call $Application->Lock() in your
global.asa's Script_OnStart.
=head2 Low MaxClients
Set your MaxClients low, such that if you have that
many httpd servers running, which will happen on busy site,
your system will not start swapping to disk because of
excessive RAM usage. Typical settings are less than 100
even with 1 gig RAM! To handle more client connections,
look into a dual server, mod_proxy front end.
(d) Updated documention for the $Application->SessionCount API
+ Scripts with named subroutines, which is warned against in the style guide,
will not be cached to help prevent my closure problems that often
hurt new developers working in mod_perl environments. The downside
is that these script will have a performance penalty having to be
recompiled each invocation, but this will kill many closure caching
bugs that are hard to detect.
- $Request->FileUpload('upload_file', 'BrowserFile') would return
a glob before that would be the file name in scalar form. However
this would be interpreted as a reference incorrectly. The fix
is to make sure this is always a scalar by stringifying
this data internally. Thanks to Richard Curtis for pointing
out this bug.
=item $VERSION = 2.51; $DATE="02/10/2003"
+ added t/session_query_parse.t test to cover use of SessionQueryParse
and $Server->URL APIs
in case this was set to something else before the error occured.
Thanks to Philip Mak for reporting.
- Couple of minor bug fixes under PerlWarn use, thanks Peter Galbavy
for reporting.
+ Added automatic load of "use Apache2" for compat with mod_perl2
request objects when Apache::ASP is loaded via "PerlModule Apache::ASP"
Thanks to Richard Curtis for reporting bug & subsequent testing.
- When GlobalPackage config changes, but global.asa has not, global.asa
will be recompiled anyway to update the GlobalPackage correctly.
Changing GlobalPackage before would cause errors if global.asa was
already compiled.
++ For ANY PerlSetVar type config, OFF/Off/off will be assumed
to have value of 0 for that setting. Before, only a couple settings
had this semantics, but they all do now for consistency.
- Fix for InodeNames config on OpenBSD, or any OS that might have
a device # of 0 for the file being stat()'d, thanks to Peter Galbavy
for bug report.
+ removed useless Apache::ASP::Collection::DESTROY
+ removed useless Apache::ASP::Server::DESTROY
+ removed useless Apache::ASP::GlobalASA::DESTROY
+ removed useless Apache::ASP::Response::DESTROY
- Default path for $Response->{Cookies} was from CookiePath
config, but this was incorrect as CookiePath config is only
for $Session cookie, so now path for $Response->{Cookies}
defaults to /
- Fixed bug where global.asa events would get undefined with
StatINC and GlobalPackage set when the GlobalPackage library
changed & get reloaded.
(d) Documented long time config NoCache.
-- Fixed use with Apache::Filter, capable as both source
and destination filter. Added ./site/eg/filter.filter example
to demonstrate these abilities.
+ Use $r->err_headers_out->add Apache::Table API for cookies
+ made deprecated warnings for use of certain $Response->Member
calls more loudly write to error_log, so I can remove the AUTOLOAD
for Response one day
- Probably fixed behavior in CgiHeaders, at least under perl 5.8.0, and
added t/cgi_headers.t to cover this config.
+ removed $Apache::ASP::CompressGzip setting ability, used to possibly
set CompressGzip in the module before, not documented anyway
+ removed $Apache::ASP::Filter setting ability to set Filter globally,
not documented anyway
+ removed old work around for setting ServerStarting to 0
at runtime, which was bad for Apache::DBI on win32 a long
time ago:
$Apache::ServerStarting and $Apache::ServerStarting = 0;
If this code is still needed in Apache::ASP->handler() let
me know.
++Optimization for static HTML/XML files that are served up
via Apache::ASP so that they are not compiled into perl subroutines
first. This makes especially native XSLT both faster & take
less memory to serve, before XSL & XML files being transformed
by XSLT would both be compiled as normal ASP script first, so
now this will happen if they really are ASP scripts with embedded
<% %> code blocks & XMLSubs being executed.
+Consolidate some config data for Apache::ASP->Loader to use
globals in @Apache::ASP::CompileChecksumKeys to know which
config data is important for precompiling ASP scripts.
+Further streamlined code compilation. Now both base
scripts and includes use the internal CompileInclude() API
to generate code.
-Fixed runtime HTML error output when Debug is set to -2/2,
so that script correctly again gets rendered in final perl form.
Added compile time error output to ./site/eg/syntax_error.asp
when a special link is clicked for a quick visual test.
-Cleaned up some bad coding practices in ./site/eg/global.asa
associated changes in other example files. Comment example
global.asa some for the first time reader
-DemoASP.pm examples module needed "use strict" fix, thanks
to Allan Vest for bug report
--$rv = $Response->Include({ File => ..., Cache => 1});
now works to get the first returned value fetched from
the cache. Before, because a list was always returned,
$rv would have been equal to the number of items returned,
even if the return value list has just one element.
-Removed CVS Revision tag from Apache::ASP::Date, which
was causing bad revision numbers in CPAN after CVS integration
of Apache::ASP
+removed cgi/asp link to ../asp-perl from distribution. This
link was for the deprecated asp script which is now asp-perl
=item $VERSION = 2.39; $DATE="09/10/2002"
-Turn off $^W explicitly before reloading global.asa. Reloading
global.asa when $^W is set will trigger subroutine redefinition
warnings. Reloading global.asa should occur without any problems
under normal usage of the system, thus this work around.
This fix is important to UseStrict functionality because warnings
automatically become thrown as die() errors with UseStrict enabled,
so we have to disable normal soft warnings here.
-$Response->Include() runtime errors now throw a die() that
can be trapped. This was old functionality that has been restored.
Other compile time errors should still trigger a hard error
like script compilation, global.asa, or $Response->Include()
without an eval()
+Some better error handling with Debug 3 or -3 set, cleaned
up developer errors messages somewhat.
=item $VERSION = 2.37; $DATE="07/03/2002"
-Fixed the testing directory structures for t/long_names.t
so that tar software like Archive::Tar & Solaris tar that
have problems with long file names will still be able
- Fixed bug where XMLSubs where removing <?xml version ... ?> tag
when it was needed in XSLT mode.
+ $Server->Mail({ CC => '...', BCC => '...' }), now works to send
CC & BCC headers/recipients.
+ Removed $Apache::ASP::Register definition which defined the current
executing Apache::ASP object. Only one part of the application was
using it, and this has been fixed. This would have been an unsafe
use of globals for a threaded environment.
+ Decreased latency when doing Application_OnStart, used to sleep(1)
for CleanupMaster sync, but this is not necessary for Application_OnStart
scenario
+ Restructure code / core templates for MailErrorsTo funcationality.
Wrote test mail_error.t to cover this. $ENV{REMOTE_USER} will now
be displayed in the MailErrorsTo message when defined from 401 basic auth.
+ $Server->RegisterCleanup should be thread safe now, as it no longer relies
for runtime configuration via %Config defined there. Update docs
for running in standalone CGI mode
+ Make use of MANFEST.SKIP to not publish the dev/* files anymore.
- Script_OnEnd guaranteed to run after $Response->End, but
it will not run if there was an error earlier in the request.
+ lots of new test cases covering behaviour of $Response->End
and $Response->Redirect under various conditions like XMLSubs
and SoftRedirect and global.asa Script_OnStart
+ asp-perl will be installed into the bin executables when
Apache::ASP is installed. asp-perl is the command line version
of Apache::ASP that can also be used to run script in CGI mode.
Test case covering asp-perl functionality.
+ asp CGI/command line script now called asp-perl. I picked this
name because Apache::ASP often has the name asp-perl in distributions
of the module.
-Make Apache::ASP script run under perl taint checking -T for perl 5.6.1...
$code =~ tr///; does not work to untaint here, so much use the slower:
$code =~ /^(.*)$/s; $code = $1; method to untaint.
-Check for inline includes changing, included in a dynamic included
loaded at runtime via $Response->Include(). Added test case for
this at t/include_change.t. If an inline include of a dynamic include
changes, the dynamic include should get recompiled now.
-Make OK to use again with PerlTaintCheck On, with MLDBM::Sync 2.25.
Fixed in ASP.pm, t/global.asa, and created new t/taint_check.t test script
+Load more modules when Apache::ASP is loaded so parent will share more
with children httpd:
Apache::Symbol
Devel::Symdump
Config
lib
MLDBM::Sync::SDBM_File
+When FileUploadMax bytes is exceeded for a file upload, there will not
versions to cache, like for XSLTCache, where the site is
mostly static.
+ Better RESOURCES section to web site, especially with adding
some links to past Apache::ASP articles & presentations.
=item $VERSION = 2.25; $DATE="10/11/2001";
+ Improved ./site/apps/search application, for better
search results at Apache::ASP site. Also, reengineered
application better, with more perl code moved to global.asa.
Make use of MLDBM::Sync::SDBM_File, where search database
before was engineering around SDBM_File's shortcomings.
- Fix for SessionSerialize config, which broke in 2.23
Also, added t/session_serialize.t to test suite to catch
this problem in the future.
=item $VERSION = 2.23; $DATE="10/11/2001";
+Make sure a couple other small standard modules get loaded
upon "PerlModule Apache::ASP", like Time::HiRes, Class::Struct,
and MLDBM::Serializer::Data::Dumper. If not available
these modules won't cause errors, but will promote child httpd
RAM sharing if they are.
-XMLSubs args parsing fix so an arg like z-index
does not error under UseStrict. This is OK now:
<my:layer z-index=3 top=0 left=0> HTML </my:layer>
-Only remove outermost <SCRIPT> tags from global.asa
for IIS/PerlScript compatibility. Used to remove
all <SCRIPT> tags, which hurt when some subs in globa.asa
would be printing some JavaScript.
+$Response->{IsClientConnected} now updated correctly
before global.asa Script_OnStart. $Response->IsClientConnect()
can be used for accurate accounting, while
$Response->{IsClientConnected} only gets updated
after $Response->Flush(). Added test cases to response.t
+$Server->HTMLEncode(\$data) API extension, now can take
scalar ref, which can give a 5% improvement in benchmarks
for data 100K in size.
-Access to $Application is locked when Application_OnEnd &
Application_OnStart is called, creating a critical section
sub My::Auth::handler {
my $r = shift;
my $ASP = Apache::ASP->new($r)
my $Session = $ASP->Session;
}
In the above example, $Session would be the same $Session
object created later while running the ASP script for this
same request.
Added t/asp_object.t test for this. Fixed global.asa to only
init StateDir when application.asp starts which is the first
test script to run.
-Fixed on Win32 to make Apache::ASP->new($r) able to create
multiple master ASP objects per request. Was not reentrant
safe before, particularly with state locking for dbms like
$Application & $Session.
++Output caching for includes, built on same layer ( extended )
as XSLTCache, test suite at t/cache.t. Enabled with special
=item $VERSION = 2.21; $DATE="8/5/2001";
+Documented RequestParams config in CONFIG misc section.
+Documented new XSLT caching directives.
+Updated ./site/eg/.htaccess XSLT example config
to use XSLTCache setting.
+New FAQ section on why perl variables are sticky globals,
suggested by Mark Seger.
-push Global directory onto @INC during ASP script execution
Protect contents of original @INC with local. This makes
things compatible with .09 Apache::ASP where we always had
Global in @INC. Fixed needed by Henrik Tougaard
- ; is a valid separator like & for QueryString Parameters
Fixed wanted by Anders
+Documented ';' may separate many directories in the IncludesDir
setting for creating a more flexible includes search path.
=item $VERSION = 2.17; $DATE="6/17/2001";
+Added ASP perl mmm-mode subclass and configuration
in editors/mmm-asp-perl.el file for better emacs support.
Updated SYNTAX/Editors documentation.
+Better debugging error message for Debug 2 or 3 settings
for global.asa errors. Limit debug output for lines
preceding rendered script.
-In old inline include mode, there should no longer
be the error "need id for includes" when using
$Response->Include() ... if DynamicIncludes were
enabled, this problem would not have likely occured
anyway. DynamicIncludes are preferrable to use so
that compiled includes can be shared between scripts.
This bug was likely introduced in version 2.11.
-Now file upload forms, forms with ENCTYPE="multipart/form-data"
can have multiple check boxes and select items marked for
@params = $Request->Form('param_name') functionality. This
will be demonstrated via the ./site/eg/file_upload.asp example.
=item $VERSION = 2.11; $DATE="05/29/2001";
+Parser optimization from Dariusz Pietrzak
-work around for global destruction error message for perl 5.6
during install
+$Response->{IsClientConnected} now will be set
correctly with ! $r->connection->aborted after each
$Response->Flush()
+New XSLTParser config which can be set to XML::XSLT or
XML::Sablotron. XML::Sablotron renders 10 times faster,
but differently. XML::XSLT is pure perl, so has wider
platform support than XML::Sablotron. This config affects
interface implemented for CollectionItem config.
Also $Request->QueryString('multiple args')->Item(1) method.
Note ASP collections start counting at 1.
--fixed race condition, where multiple processes might
try creating the same state directory at the same time, with
one winning, and one generating an error. Now, web process
will recheck for directory existence and error if
it doesn't.
-global.asa compilation will be cached correctly, not
sure when this broke. It was getting reloaded every request.
-StateAllWrite config, when set creates state files
with a+rw or 0666 permissions, and state directories
with a+rwx or 0777 permissions. This allows web servers
running as different users on the same machine to share a
common StateDir config. Also StateGroupWrite config
with perms 0770 and 0660 respectively.
-Apache::ASP->Loader() now won't follow links to
just one step away now from implementing XSP logic.
+$Server->Execute and $Server->Transfer API extensions
implemented. Execute is the same as $Request->Include()
and $Server->Transfer is like an apache internal redirect
but keeps the current ASP objects for the next script.
Added examples, transfer.htm, and modified dynamic_includes.htm.
+Better compile time error debugging with Debug 2 or -2.
Will hilite/link the buggy line for global.asa errors,
include errors, and XML/XSLT errors just like with
ASP scripts before.
+Nice source hiliting when viewing source for the example
scripts.
+Runtime string writing optimization for static HTML going
through $Response.
+New version numbering just like everyone else. Starting at 1.91
incoming session id that does not match one already seen. This will
help for those with Search engines that have bookmarked
pages with the session ids in the query strings. This breaks away
from standard ASP session id implementation which will automatically
use the session id presented by the browser, now a new session id will
be returned if the presented one is invalid or expired.
-$Application->GetSession will only return a session if
one already existed. It would create one before by default.
+Script_OnFlush global.asa event handler, and $Response->{BinaryRef}
member which is a scalar reference to the content about to be flushed.
See ./site/eg/global.asa for example usage, used in this case to
insert font tags on the fly into the output.
+Highlighting and linking of line error when Debug is set to 2 or -2.
--removed fork() call from flock() backup routine? How did
that get in there? Oh right, testing on Win32. :(
Very painful lesson this one, sorry to whom it may concern.
+$Application->SessionCount support turned off by default
must enable with SessionCount config option. This feature
+Documented SessionQuery* & $Server->URL() and
cleaned up formatting some, as well as redoing
some of the sections ordering for better readability.
Document the cookieless session functionality more
in a new SESSIONS section. Also documented new
FileUpload configs and $Request->FileUpload collection.
Documented StatScripts.
+StatScripts setting which if set to 0 will not reload
includes, global.asa, or scripts when changed.
+FileUpload file handles cleanup at garbage collection
time so developer does not have to worry about lazy coding
and undeffing filehandles used in code. Also set
uploaded filehandles to binmode automatically on Win32
platforms, saving the developer yet more typing.
+FileUploadTemp setting, default 0, if set will leave
a temp file on disk during the request, which may be
helpful for processing by other programs, but is also
it, and run it through ab, or Socrates, with SessionQuery
turned on, and then with SessionQueryParse set to see
the difference. SessionQuery just enables of session id
setting from the query string but will not auto parse urls.
-If buffering, Content-Length will again be set.
It broke, probably while I was tuning in the past
couple versions.
+UseStrict setting compiles all scripts including
global.asa with "use strict" turned on for catching
more coding errors. With this setting enabled,
use strict errors die during compilation forcing
Apache::ASP to try to recompile the script until
successful.
-Object use in includes like $Response->Write()
no longer error with "use strict" programming.
+SessionQuery config setting with $Server->URL($url, { %params } )
alpha API extensions to enable cookieless sessions.
Apache::ASP also went from 75 to 102 hits per second
on Solaris.
+PerlTaintCheck On friendly. This is mod_perl's way
of providing -T taint checking. When Apache::ASP
is used with state objects like $Session or $Application,
MLDBM must also be made taint friendly with:
$MLDBM::RemoveTaint = 1;
which could be put in the global.asa. Documented.
+Added $Response->ErrorDocument($error_code, $uri_or_string)
API extension which allows for setting of Apache's error
document at runtime. This is really just a wrapper
for Apache->custom_response() renamed so it syncs with
the Apache ErrorDocument config setting. Updated
documentation, and added error_document.htm example.
=OrderCollections setting was added, but then REMOVED
because it was not going to be used. It bound
$Request->* collections/hashes to Tie::IxHash, so that data
in those collections would be read in the order the
browser sent it, when eaching through or with keys.
-global.asa will be reloaded when changed. This broke
when I optimized the modification times with (stat($file))[9]
rather than "use File::stat; stat($file)->mtime"
-Make Apache::ASP->Loader() PerlRestartHandler safe,
had some unstrict code that was doing the wrong thing.
-IncludesDir config now works with DynamicIncludes.
+DebugBufferLength feature added, giving control to
how much buffered output gets shown when debugging errors.
so I've commented out this parsing trick for now. If you
need me to bring back this functionality, it will be in the
form of a config setting.
For information on PerlScript compatibility, see the PerlScript
section in the ASP docs.
-Added UniquePackages config option, that if set brings back
the old method of compiling each ASP script into its own
separate package. As of v.10, scripts are compiled by default
into the same package, so that scripts, dynamic includes & global.asa
can share globals. This BROKE scripts in the same ASP Application
that defined the same sub routines, as their subs would redefine
each other.
UniquePackages has scripts compiled into separate perl packages,
so they may define subs with the same name, w/o fear of overlap.
Under this settings, scripts will not be able to share globals.
-Secure field for cookies in $Response->Cookies() must be TRUE to
force cookie to be secure. Before, it just had to be defined,
which gave wrong behavior for Secure => 0.
+$Response->{IsClientConnected} set to one by default. Will
work out a real value when I upgrade to apache 1.3.6. This
value has no meaning before, as apache aborts the perl code
when a client drops its connection in earlier versions.
-StatINCMatch / StatINC can be used in production and work
even after a server graceful restart, which is essential for
a production server.
-Content-Length header is set again, if BufferingOn is set, and
haven't $Response->Flush()'d. This broke when I introduce
the Script_OnEnd event handler.
+Optimized reloading of the GlobalPackage perl module upon changes,
so that scripts and dynamic includes don't have to be recompiled.
The global.asa will still have to be though. Since we started
compiling all routines into a package that can be named with
GlobalPackage, we've been undeffing compiled scripts and includes
when the real GlobalPackage changed on disk, as we do a full sweep
through the namespace. Now, we skip those subs that we know to
be includes or scripts.
-Using Apache::Symbol::undef() to undefine precompiled scripts
and includes when reloading those scripts. Doing just an undef()
would sometimes result in an "active subroutine undef" error.
This bug came out when I started thrashing the StatINC system
error for Debug 2 setting. This makes changing libs with StatINC
on a little more friendly when there are errors.
-$Request->QueryString() now stores multiple values for the
same key, just as $Request->Form() has since v.07. In
wantarray() context like @vals = $Request->QueryString('dupkey'),
@vals will store whatever values where associated with dupkey
in the query string like (1,2) from: ?dupkey=1&dupkey=2
+The GlobalPackage config directive may be defined
to explicitly set the perl module that all scripts and global.asa
are compiled into.
-Dynamic includes may be in the Global directory, just like
normal includes.
+Perl script generated from asp scripts should match line
for line, seen in errors, except when using inline (default)
includes, pod comments, or <% #comment %> perl comments, which
will throw off the line counts by adding text, removing
text, or having an extra newline added, respectively.
-Script_OnEnd may now send output to the browser. Before
$main::Response->End() was being called at the end of the
main script preventing further output.
++All scripts are compiled as routines in a namespace uniquely
defined by the global.asa of the ASP application. Thus,
scripts, includes, and global.asa routines will share
all globals defined in the global.asa namespace. This means
that globals between scripts will be shared, and globals
defined in a global.asa will be available to scripts.
Scripts used to have their own namespace, thus globals
were not shared between them.
+a -o $output_dir switch on the ./cgi/asp script allows
it to execute scripts and write their output to an output
directory. Useful for building static html sites, based on
asp scripts. An example use would be:
asp -b -o out *.asp
Without an output directory, script output is written to STDOUT
+Improved docs on $Response->Cookies() and $Request->Cookies()
+Added PERFORMANCE doc to main README, and added sub section
on precompiling scripts with Apache::ASP->Loader()
+Naming of CompileIncludes switched over to DynamicIncludes
for greater clarity.
+Dynamic includes can now reference ASP objects like $Session
w/o the $main::* syntax. These subs are no longer anonymous
subs, and are now compiled into the namespace of the global.asa package.
+Apache::ASP->Loader() precompiles dynamic includes too. Making this work
required fixing some subtle bugs / dependencies in the compiling process.
+Added Apache::ASP->Loader() similar to Apache::RegistryLoader for
precompiling ASP scripts. Precompile a whole site at server
startup with one function call.
+Prettied the error messaging with Debug 2.
+Implemented $Response->BinaryWrite(), documented, and created
and example in ./eg/binary_write.htm
+Implemented $Server->MapPath() and created example of its use
in ./eg/server.htm
-$Request->Form() now reads file uploads correctly with
the latest CGI.pm, where $Request->Form('file_field') returns
the actual file name uploaded, which can be used as a file handle
to read in the data. Before, $Request->Form('file_field') would
return a glob that looks like *Fh::filename, so to get the file
name, you would have to parse it like =~ s/^\*Fh\:\://,
which you no longer have to do. As long as parsing was done as
mentioned, the change should be backwards compatible.
+Updated +enhanced documentation on file uploads. Created extra
comments about it as an FAQ, and under $Response->Form(), the latter
being an obvious place for a developer to look for it.
+Updated ./eg/file_upload.asp to show use of non file form data,
with which we had a bug before.
-Compatible with CGI.pm 2.46 headers()
-Compatible with CGI.pm $q = new CGI({}), caveat: does not set params
+use strict; followed by use of objects like $Session is fine.
-Multiple cookies may be set per script execution.
+file upload implemented via CGI.pm
++global.asa implemented with events Session_OnStart and Session_OnEnd
working appropriately.
+StateDir configuration directive implemented.
StateDir allows the session state directory to be specified separately
from the Global directory, useful for operating systems with caching file
systems.
+StateManager config directive. StateManager specifies how frequently
Sessions are cleaned up, with 10 (default) meaning that old Sessions
will be cleaned up 10 times per SessionTimeout period (default 20 minutes).
asp-perl
build/asp.conf
build/build.sh
build/build_ads.sh
build/cgi.html
build/changes.html
build/config.html
build/eg/index.html
build/events.html
build/faq.html
build/global/SiteTags.pm
build/global/ad.inc
build/global/box.inc
build/global/global.asa
build/global/index_extra.inc
build/global/testimonial.inc
build/global/testimonials.inc
build/global/top.inc
build/index.html
build/install.html
build/kudos.html
build/license.html
build/objects.html
build/perlscript.html
build/resources.html
build/sessions.html
build/sites.html
build/ssi.html
lib/Apache/ASP/StateManager.pm
lib/Bundle/Apache/ASP.pm
lib/Bundle/Apache/ASP/Extra.pm
make_httpd/build_httpds.sh
site/apache_asp.gif
site/apache_asp_small_trans.GIF
site/apps/bookmarks/.htaccess
site/apps/bookmarks/bookmarks.asp
site/apps/bookmarks/dummy.asp
site/apps/bookmarks/footer.inc
site/apps/bookmarks/global.asa
site/apps/bookmarks/header.inc
site/apps/bookmarks/index.asp
site/apps/search/.htaccess
site/apps/search/global.asa
site/apps/search/index.asp
site/apps/search/source.asp
site/articles/flow.gif
site/articles/perlmonth1_intro.html
site/articles/perlmonth2_build.html
site/articles/perlmonth3_tune.html
site/asptitlelogo.gif
site/cgi.html
site/changes.html
site/cine.gr.gif
site/eg/cookieless_session.asp
site/eg/counting.htm
site/eg/default.htm
site/eg/dynamic_includes.htm
site/eg/error_document.htm
site/eg/file_upload.asp
site/eg/filter.filter
site/eg/footer.inc
site/eg/form.asp
site/eg/formfill.asp
site/eg/global.asa
site/eg/global_asa_demo.asp
site/eg/header.inc
site/eg/include.htm
site/eg/index.htm
site/eg/index.html
site/eg/register_cleanup.asp
site/eg/response.asp
site/eg/row.inc
site/eg/server.htm
site/eg/server_variables.htm
site/eg/session.asp
site/syntax.html
site/testimonials.html
site/todo.html
site/top.inc
site/tuning.html
site/webtimelogo.jpg
site/xml.html
t/T.pm
t/application.t
t/asp-perl/asp.conf
t/asp-perl/global.asa
t/asp-perl/ok.inc
t/asp-perl1.t
t/asp-perl2.t
t/asp_object.t
t/cache.t
t/cache_test.inc
t/cgi_headers.t
t/closure.inc
t/closure.t
t/collection.t
t/cookies.t
t/dynamic_include_change.inc
t/end.t
t/end_basic.inc
t/end_clear.inc
t/end_redirect_basic.inc
t/end_redirect_soft.inc
t/end_xmlsubs_basic.inc
t/end_xmlsubs_redirect.inc
t/general.t
t/global.asa
t/global_event_end.t
t/global_event_end/global.asa
t/include.inc
t/include.t
t/include_asp.inc
t/include_change.inc
t/include_change.t
t/include_change_piece.inc_temp
t/include_code.inc
t/include_code2.inc
t/include_dir_error.t
t/include_return.inc
t/inline_include_change.inc
t/inode_names.t
t/load.inc
t/load.t
t/load_error.inc
t/long_names.t
t/loops.t
t/mail_error.t
t/no_cache.inc
t/no_cache.t
t/null/global.asa
t/null/ok.inc
t/raw.t
t/raw_include.inc
t/raw_include.t
t/reload_global_asa.t
t/req_params_none.t
t/request.t
t/response.t
t/response_end.t
t/same_name.t
t/same_name/test1/test.asp
t/same_name/test2/test.asp
t/server.t
t/server_mail.t
t/server_transfer.inc
t/server_transfer.t
t/session.inc
t/session.t
t/session_events.t
t/session_events/global.asa
t/session_query_parse.t
t/session_serialize.t
t/share.t
t/stat_inc.t
t/strict_error.inc
t/strict_error.t
t/taint_check.t
t/transfer.inc
t/transfer2.inc
t/unique_packages.inc
</Perl>
PerlModule Apache::ASP
Please be sure to add this configuration before Apache::ASP is loaded via
PerlModule, or a PerlRequire statement.
CONFIG
You may use a <Files ...> directive in your httpd.conf Apache configuration
file to make Apache::ASP start ticking. Configure the optional settings if
you want, the defaults are fine to get started. The settings are documented
below. Make sure Global is set to where your web applications global.asa is
if you have one!
PerlModule Apache::ASP
<Files ~ (\.asp)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global .
PerlSetVar StateDir /tmp/asp
</Files>
You may use other Apache configuration tags like <Directory>, <Location>,
and <VirtualHost>, to separately define ASP configurations, but using the
<Files> tag is natural for ASP application building because it lends itself
naturally to mixed media per directory. For building many separate ASP
sites, you might want to use separate .htaccess files, or <Files> tags in
<VirtualHost> sections, the latter being better for performance.
Core
Global
Global is the nerve center of an Apache::ASP application, in which the
global.asa may reside defining the web application's event handlers.
This directory is pushed onto @INC, so you will be able to "use" and
"require" files in this directory, and perl modules developed for this
application may be dropped into this directory, for easy use.
Unless StateDir is configured, this directory must be some writeable
directory by the web server. $Session and $Application object state
files will be stored in this directory. If StateDir is configured, then
ignore this paragraph, as it overrides the Global directory for this
purpose.
Includes, specified with <!--#include file=somefile.inc--> or
$Response->Include() syntax, may also be in this directory, please see
section on includes for more information.
PerlSetVar Global /tmp
GlobalPackage
Perl package namespace that all scripts, includes, & global.asa events
are compiled into. By default, GlobalPackage is some obscure name that
is uniquely generated from the file path of the Global directory, and
global.asa file. The use of explicitly naming the GlobalPackage is to
allow scripts access to globals and subs defined in a perl module that
is included with commands like:
in perl script: use Some::Package;
in apache conf: PerlModule Some::Package
PerlSetVar GlobalPackage Some::Package
UniquePackages
default 0. Set to 1 to compile each script into its own perl package, so
that subroutines defined in one script will not collide with another.
By default, ASP scripts in a web application are compiled into the
*same* perl package, so these scripts, their includes, and the
global.asa events all share common globals & subroutines defined by each
other. The problem for some developers was that they would at times
define a subroutine of the same name in 2+ scripts, and one subroutine
definition would redefine the other one because of the namespace
collision.
PerlSetVar UniquePackages 0
DynamicIncludes
default 0. SSI file includes are normally inlined in the calling script,
and the text gets compiled with the script as a whole. With this option
PerlSetVar IncludesDir .
Also, multiple includes directories may be set by creating a directory
list separated by a semicolon ';' as in
PerlSetVar IncludesDir ../shared;/usr/local/asp/shared
Using IncludesDir in this way creates an includes search path that would
look like ., Global, ../shared, /usr/local/asp/shared The current
directory of the executing script is checked first whenever an include
is specified, then the Global directory in which the global.asa resides,
and finally the IncludesDir setting.
NoCache
Default 0, if set to 1 will make it so that neither script nor include
compilations are cached by the server. Using this configuration will
save on memory but will slow down script execution. Please see the
TUNING section for other strategies on improving site performance.
PerlSetVar NoCache 0
separately from the Global directory, which contains more permanent
files. This way one may point StateDir to /tmp/myaspapp, and make one's
ASP application scream with speed.
PerlSetVar StateDir ./.state
StateManager
default 10, this number specifies the numbers of times per
SessionTimeout that timed out sessions are garbage collected. The bigger
the number, the slower your system, but the more precise Session_OnEnd's
will be run from global.asa, which occur when a timed out session is
cleaned up, and the better able to withstand Session guessing hacking
attempts. The lower the number, the faster a normal system will run.
The defaults of 20 minutes for SessionTimeout and 10 times for
StateManager, has dead Sessions being cleaned up every 2 minutes.
PerlSetVar StateManager 10
StateDB
default SDBM_File, this is the internal database used for state objects
Default 0, this NON-PORTABLE configuration will allow sessions to span
multiple web sites that match the same domain root. This is useful if
your web sites are hosted on the same machine and can share the same
StateDir configuration, and you want to shared the $Session data across
web sites. Whatever this is set to, that will add a
; domain=$CookieDomain
part to the Set-Cookie: header set for the session-id cookie.
PerlSetVar CookieDomain .your.global.domain
SessionTimeout
Default 20 minutes, when a user's session has been inactive for this
period of time, the Session_OnEnd event is run, if defined, for that
session, and the contents of that session are destroyed.
PerlSetVar SessionTimeout 20
SecureSession
default 0. Sets the secure tag for the session cookie, so that the
SessionQueryForce
default 0, set to 1 if you want to disallow the use of cookies for
session id passing, and only allow session ids to be passed on the query
string via SessionQuery and SessionQueryParse settings.
PerlSetVar SessionQueryForce 1
Developer Environment
UseStrict
default 0, if set to 1, will compile all scripts, global.asa and
includes with "use strict;" inserted at the head of the file, saving you
from the painful process of strictifying code that was not strict to
begin with.
Because of how essential "use strict" programming is in a mod_perl
environment, this default might be set to 1 one day, but this will be up
for discussion before that decision is made.
Note too that errors triggered by "use strict" are now captured as part
of the normal Apache::ASP error handling when this configuration is set,
The StatINCMatch setting should be a regular expression like: Struct|LWP
which would match on reloading Class/Struct.pm, and all the LWP/.*
libraries.
If you define StatINCMatch, you do not need to define StatINC.
PerlSetVar StatINCMatch .*
StatScripts
default 1, if set to 0, changed scripts, global.asa, and includes will
not be reloaded. Coupled with Apache mod_perl startup and restart
handlers executing Apache::ASP->Loader() for your application this
allows your application to be frozen, and only reloaded on the next
server restart or stop/start.
There are a few advantages for not reloading scripts and modules in
production. First there is a slight performance improvement by not
having to stat() the script, its includes and the global.asa every
request.
From an application deployment standpoint, you also gain the ability to
deploy your application as a snapshot taken when the server starts and
restarts. This provides you with the reassurance that during a
production server update from development sources, you do not have to
worry with sources being used for the wrong libraries and such, while
they are all being copied over.
Finally, though you really should not do this, you can work on a live
good macros and a configurable wordlist (so one can have syntax
highlighting both for Perl and HTML).
Please feel free to suggest your favorite development environment for this
list.
EVENTS
Overview
The ASP platform allows developers to create Web Applications. In
fulfillment of real software requirements, ASP allows event-triggered
actions to be taken, which are defined in a global.asa file. The global.asa
file resides in the Global directory, defined as a config option, and may
define the following actions:
Action Event
------ ------
Script_OnStart * Beginning of Script execution
Script_OnEnd * End of Script execution
Script_OnFlush * Before $Response being flushed to client.
Script_OnParse * Before script compilation
Application_OnStart Beginning of Application
Application_OnEnd End of Application
Session_OnStart Beginning of user Session.
Session_OnEnd End of user Session.
* These are API extensions that are not portable, but were
added because they are incredibly useful
These actions must be defined in the $Global/global.asa file as subroutines,
for example:
sub Session_OnStart {
$Application->{$Session->SessionID()} = started;
}
Sessions are easy to understand. When visiting a page in a web application,
each user has one unique $Session. This session expires, after which the
user will have a new $Session upon revisiting.
A web application starts when the user visits a page in that application,
and has a new $Session created. Right before the first $Session is created,
the $Application is created. When the last user $Session expires, that
$Application expires also. For some web applications that are always busy,
the Application_OnEnd event may never occur.
Script_OnStart & Script_OnEnd
The script events are used to run any code for all scripts in an application
defined by a global.asa. Often, you would like to run the same code for
every script, which you would otherwise have to add by hand, or add with a
file include, but with these events, just add your code to the global.asa,
and it will be run.
There is one caveat. Code in Script_OnEnd is not guaranteed to be run when
$Response->End() is called, since the program execution ends immediately at
this event. To always run critical code, use the API extension:
$Server->RegisterCleanup()
Session_OnStart
Triggered by the beginning of a user's session, Session_OnStart gets run
visit occurs, and theoretically the last session of an application ever run
will never have its Session_OnEnd run.
Thus I would not put anything mission-critical in the Session_OnEnd, just
stuff that would be nice to run whenever it gets run.
Script_OnFlush
API extension. This event will be called prior to flushing the $Response
buffer to the web client. At this time, the $Response->{BinaryRef} buffer
reference may be used to modify the buffered output at runtime to apply
global changes to scripts output without having to modify all the scripts.
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
Check out the ./site/eg/global.asa for an example of its use.
Script_OnParse
This event allows one to set up a source filter on the script text, allowing
one to change the script on the fly before the compilation stage occurs. The
script text is available in the $Server->{ScriptRef} scalar reference, and
can be accessed like so:
sub Script_OnParse {
my $code = $Server->{ScriptRef}
$$code .= " ADDED SOMETHING ";
PerlTransHandler
PerlFixupHandler
PerlHandler
PerlLogHandler
PerlCleanupHandler
For straight Apache::ASP programming, there are some equivalents, say
Script_OnStart event instead of Init/Fixup stages, or
$Server->RegisterCleanup() for Log/Cleanup stages, but you can do things in
the mod_perl handlers that you cannot do in Apache::ASP, especially if you
want to handle all files globally, and not just ASP scripts.
For many Apache::* modules for use with mod_perl, of which Apache::ASP is
just one, check out http://perl.apache.org/src/apache-modlist.html
To gain access to the ASP objects like $Session outside in a non-PerlHandler
mod_perl handler, you may use this API:
my $ASP = Apache::ASP->new($r); # $r is Apache->request object
as in this possible Authen handler:
DECLINED;
}
1;
OBJECTS
The beauty of the ASP Object Model is that it takes the burden of CGI and
Session Management off the developer, and puts them in objects accessible
from any ASP script & include. For the perl programmer, treat these objects
as globals accessible from anywhere in your ASP application.
The Apache::ASP object model supports the following:
Object Function
------ --------
$Session - user session state
$Response - output to browser
$Request - input from browser
$Application - application state
$Server - general methods
These objects, and their methods are further defined in the following
sections.
If you would like to define your own global objects for use in your scripts
and includes, you can initialize them in the global.asa Script_OnStart like:
use vars qw( $Form $Site ); # declare globals
sub Script_OnStart {
$Site = My::Site->new; # init $Site object
$Form = $Request->Form; # alias form data
$Server->RegisterCleanup(sub { # garbage collection
$Site->DESTROY;
$Site = $Form = undef;
});
}
In this way you can create site wide application objects and simple aliases
API Extension. Unlocks the $Session explicitly. If you do not call this,
$Session will be unlocked automatically at the end of the script.
$Response Object
This object manages the output from the ASP Application and the client web
browser. It does not store state information like the $Session object but
does have a wide array of methods to call.
$Response->{BinaryRef}
API extension. This is a perl reference to the buffered output of the
$Response object, and can be used in the Script_OnFlush global.asa event
to modify the buffered output at runtime to apply global changes to
scripts output without having to modify all the scripts. These changes
take place before content is flushed to the client web browser.
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
Check out the ./site/eg/global.asa for an example of its use.
$Response->{Buffer}
Default 1, when TRUE sends output from script to client only at the end
of processing the script. When 0, response is not buffered, and client
is sent output as output is generated by the script.
$Response->{CacheControl}
Default "private", when set to public allows proxy servers to cache the
content. This setting controls the value set in the HTTP header
Cache-Control
This setting overrides the FormFill config at runtime for the script
execution only.
$Response->{IsClientConnected}
1 if web client is connected, 0 if not. This value starts set to 1, and
will be updated whenever a $Response->Flush() is called. If BufferingOn
is set, by default $Response->Flush() will only be called at the end of
the HTML output.
As of version 2.23 this value is updated correctly before global.asa
Script_OnStart is called, so global script termination may be correctly
handled during that event, which one might want to do with excessive
user STOP/RELOADS when the web server is very busy.
An API extension $Response->IsClientConnected may be called for
refreshed connection status without calling first a $Response->Flush
$Response->{PICS}
If this property has been set, a PICS-Label HTTP header will be sent
with its value. For those that do not know, PICS is a header that is
useful in rating the internet. It stands for Platform for Internet
$fileup->{FileHandle};
$fileup->{Mime-Header};
$fileup->{TempFile};
$Request->Form($name)
Returns the value of the input of name $name used in a form with POST
method. If $name is not specified, returns a ref to a hash of all the
form data. One can use this hash to create a nice alias to the form data
like:
# in global.asa
use vars qw( $Form );
sub Script_OnStart {
$Form = $Request->Form;
}
# then in ASP scripts
<%= $Form->{var} %>
File upload data will be loaded into $Request->Form('file_field'), where
the value is the actual file name of the file uploaded, and the contents
of the file can be found by reading from the file name as a file handle
uploads are implemented via the CGI.pm module. An example can be found
in the installation samples ./site/eg/file_upload.asp
$Request->Params($name)
API extension. If RequestParams CONFIG is set, the $Request->Params
object is created with combined contents of $Request->QueryString and
$Request->Form. This is for developer convenience simlar to CGI.pm's
param() method. Just like for $Response->Form, one could create a nice
alias like:
# in global.asa
use vars qw( $Params );
sub Script_OnStart {
$Params = $Request->Params;
}
$Request->QueryString($name)
Returns the value of the input of name $name used in a form with GET
method, or passed by appending a query string to the end of a url as in
http://localhost/?data=value. If $name is not specified, returns a ref
to a hash of all the query string data.
id. This allows one to easily write a session manager if session ids are
stored in $Application during Session_OnStart, with full access to these
sessions for administrative purposes.
Be careful not to expose full session ids over the net, as they could be
used by a hacker to impersonate another user. So when creating a session
manager, for example, you could create some other id to reference the
SessionID internally, which would allow you to control the sessions.
This kind of application would best be served under a secure web server.
The ./site/eg/global_asa_demo.asp script makes use of this routine to
display all the data in current user sessions.
$Application->SessionCount()
This NON-PORTABLE method returns the current number of active sessions
in the application, and is enabled by the SessionCount configuration
setting. This method is not implemented as part of the original ASP
object model, but is implemented here because it is useful. In
particular, when accessing databases with license requirements, one can
monitor usage effectively through accessing this value.
<!--#include file=filename.inc-->
,the .inc being merely a convention, text from the included file will be
inserted directly into the script being executed and the script will be
compiled as a whole. Whenever the script or any of its includes change, the
script will be recompiled.
Includes go a great length to promote good decomposition and code sharing in
ASP scripts, but they are still fairly static. As of version .09, includes
may have dynamic runtime execution, as subroutines compiled into the
global.asa namespace. The first way to invoke includes dynamically is
<!--#include file=filename.inc args=@args-->
If @args is specified, Apache::ASP knows to execute the include at runtime
instead of inlining it directly into the compiled code of the script. It
does this by compiling the script at runtime as a subroutine, and caching it
for future invocations. Then the compiled subroutine is executed and has
@args passed into its as arguments.
This is still might be too static for some, as @args is still hardcoded into
> VBScript dates may not be used for Expires property of cookies.
> Win32::OLE::in may not be used. Use keys() to iterate over.
> The ->{Item} property does not work, use the ->Item() method.
STYLE GUIDE
Here are some general style guidelines. Treat these as tips for best
practices on Apache::ASP development if you will.
UseStrict
One of perl's blessings is also its bane, variables do not need to be
declared, and are by default globally scoped. The problem with this in
mod_perl is that global variables persist from one request to another even
if a different web browser is viewing a page.
To avoid this problem, perl programmers have often been advised to add to
the top of their perl scripts:
use strict;
In Apache::ASP, you can do this better by setting:
PerlSetVar UseStrict 1
which will cover both script & global.asa compilation and will catch "use
strict" errors correctly. For perl modules, please continue to add "use
strict" to the top of them.
Because its so essential in catching hard to find errors, this configuration
will likely become the default in some future release. For now, keep setting
it.
Do not define subroutines in scripts.
DO NOT add subroutine declarations in scripts. Apache::ASP is optimized by
compiling a script into a subroutine for faster future invocation. Adding a
}
The biggest problem with subroutines defined in subroutines is the side
effect of creating closures, which will not behave as usually desired in a
mod_perl environment. To understand more about closures, please read up on
them & "Nested Subroutines" at:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html
Instead of defining subroutines in scripts, you may add them to your sites
global.asa, or you may create a perl package or module to share with your
scripts. For more on perl objects & modules, please see:
http://perldoc.perl.org/perlobj.html
Use global.asa's Script_On* Events
Chances are that you will find yourself doing the same thing repeatedly in
each of your web application's scripts. You can use Script_OnStart and
Script_OnEnd to automate these routine tasks. These events are called before
and after each script request.
For example, let's say you have a header & footer you would like to include
in the output of every page, then you might:
# global.asa
sub Script_OnStart {
$Response->Include('header.inc');
}
sub Script_OnEnd {
$Response->Include('footer.inc');
}
Or let's say you want to initialize a global database connection for use in
your scripts:
# global.asa
use Apache::DBI; # automatic persistent database connections
use DBI;
use vars qw($dbh); # declare global $dbh
sub Script_OnStart {
# initialize $dbh
$dbh = DBI->connect(...);
# force you to explicitly commit when you want to save data
$Server->RegisterCleanup(sub { $dbh->rollback; });
}
sub Script_OnEnd {
--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:
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
file system. On WinNT, all files may be cached, and you have no control of
this. On Solaris, /tmp is a RAM disk and would be a good place to set the
"StateDir" config setting to. When cached file systems are used there is
little performance penalty for using state files. Linux tends to do a good
job caching its file systems, so pick a StateDir for ease of system
administration.
On Win32 systems, where mod_perl requests are serialized, you can freely use
SessionSerialize to make your $Session requests faster, and you can achieve
similar performance benefits for $Application if you call
$Application->Lock() in your global.asa's Script_OnStart.
Low MaxClients
Set your MaxClients low, such that if you have that many httpd servers
running, which will happen on busy site, your system will not start swapping
to disk because of excessive RAM usage. Typical settings are less than 100
even with 1 gig RAM! To handle more client connections, look into a dual
server, mod_proxy front end.
High MaxRequestsPerChild
Set your max requests per child thread or process (in httpd.conf) high, so
(d) Updated documention for the $Application->SessionCount API
+ Scripts with named subroutines, which is warned against in the style guide,
will not be cached to help prevent my closure problems that often
hurt new developers working in mod_perl environments. The downside
is that these script will have a performance penalty having to be
recompiled each invocation, but this will kill many closure caching
bugs that are hard to detect.
- $Request->FileUpload('upload_file', 'BrowserFile') would return
a glob before that would be the file name in scalar form. However
this would be interpreted as a reference incorrectly. The fix
is to make sure this is always a scalar by stringifying
this data internally. Thanks to Richard Curtis for pointing
out this bug.
$VERSION = 2.51; $DATE="02/10/2003"
+ added t/session_query_parse.t test to cover use of SessionQueryParse
and $Server->URL APIs
- Fixed duplicate "&" bug associated with using $Server->URL
in case this was set to something else before the error occured.
Thanks to Philip Mak for reporting.
- Couple of minor bug fixes under PerlWarn use, thanks Peter Galbavy
for reporting.
+ Added automatic load of "use Apache2" for compat with mod_perl2
request objects when Apache::ASP is loaded via "PerlModule Apache::ASP"
Thanks to Richard Curtis for reporting bug & subsequent testing.
- When GlobalPackage config changes, but global.asa has not, global.asa
will be recompiled anyway to update the GlobalPackage correctly.
Changing GlobalPackage before would cause errors if global.asa was
already compiled.
++ For ANY PerlSetVar type config, OFF/Off/off will be assumed
to have value of 0 for that setting. Before, only a couple settings
had this semantics, but they all do now for consistency.
- Fix for InodeNames config on OpenBSD, or any OS that might have
a device # of 0 for the file being stat()'d, thanks to Peter Galbavy
for bug report.
+ removed useless Apache::ASP::Collection::DESTROY
+ removed useless Apache::ASP::Server::DESTROY
+ removed useless Apache::ASP::GlobalASA::DESTROY
+ removed useless Apache::ASP::Response::DESTROY
- Default path for $Response->{Cookies} was from CookiePath
config, but this was incorrect as CookiePath config is only
for $Session cookie, so now path for $Response->{Cookies}
defaults to /
- Fixed bug where global.asa events would get undefined with
StatINC and GlobalPackage set when the GlobalPackage library
changed & get reloaded.
(d) Documented long time config NoCache.
-- Fixed use with Apache::Filter, capable as both source
and destination filter. Added ./site/eg/filter.filter example
to demonstrate these abilities.
+ Use $r->err_headers_out->add Apache::Table API for cookies
+ made deprecated warnings for use of certain $Response->Member
calls more loudly write to error_log, so I can remove the AUTOLOAD
for Response one day
- Probably fixed behavior in CgiHeaders, at least under perl 5.8.0, and
added t/cgi_headers.t to cover this config.
+ removed $Apache::ASP::CompressGzip setting ability, used to possibly
set CompressGzip in the module before, not documented anyway
+ removed $Apache::ASP::Filter setting ability to set Filter globally,
not documented anyway
+ removed old work around for setting ServerStarting to 0
at runtime, which was bad for Apache::DBI on win32 a long
time ago:
$Apache::ServerStarting and $Apache::ServerStarting = 0;
If this code is still needed in Apache::ASP->handler() let
me know.
++Optimization for static HTML/XML files that are served up
via Apache::ASP so that they are not compiled into perl subroutines
first. This makes especially native XSLT both faster & take
less memory to serve, before XSL & XML files being transformed
by XSLT would both be compiled as normal ASP script first, so
now this will happen if they really are ASP scripts with embedded
<% %> code blocks & XMLSubs being executed.
+Consolidate some config data for Apache::ASP->Loader to use
globals in @Apache::ASP::CompileChecksumKeys to know which
config data is important for precompiling ASP scripts.
+Further streamlined code compilation. Now both base
scripts and includes use the internal CompileInclude() API
to generate code.
-Fixed runtime HTML error output when Debug is set to -2/2,
so that script correctly again gets rendered in final perl form.
Added compile time error output to ./site/eg/syntax_error.asp
when a special link is clicked for a quick visual test.
-Cleaned up some bad coding practices in ./site/eg/global.asa
associated changes in other example files. Comment example
global.asa some for the first time reader
-DemoASP.pm examples module needed "use strict" fix, thanks
to Allan Vest for bug report
--$rv = $Response->Include({ File => ..., Cache => 1});
now works to get the first returned value fetched from
the cache. Before, because a list was always returned,
$rv would have been equal to the number of items returned,
even if the return value list has just one element.
$VERSION = 2.41; $DATE="09/29/2002"
-Removed CVS Revision tag from Apache::ASP::Date, which
was causing bad revision numbers in CPAN after CVS integration
of Apache::ASP
+removed cgi/asp link to ../asp-perl from distribution. This
link was for the deprecated asp script which is now asp-perl
$VERSION = 2.39; $DATE="09/10/2002"
-Turn off $^W explicitly before reloading global.asa. Reloading
global.asa when $^W is set will trigger subroutine redefinition
warnings. Reloading global.asa should occur without any problems
under normal usage of the system, thus this work around.
This fix is important to UseStrict functionality because warnings
automatically become thrown as die() errors with UseStrict enabled,
so we have to disable normal soft warnings here.
-$Response->Include() runtime errors now throw a die() that
can be trapped. This was old functionality that has been restored.
Other compile time errors should still trigger a hard error
like script compilation, global.asa, or $Response->Include()
without an eval()
+Some better error handling with Debug 3 or -3 set, cleaned
up developer errors messages somewhat.
$VERSION = 2.37; $DATE="07/03/2002"
-Fixed the testing directory structures for t/long_names.t
so that tar software like Archive::Tar & Solaris tar that
have problems with long file names will still be able
to untar distribution successfully. Now t/long_names.t
- Fixed bug where XMLSubs where removing <?xml version ... ?> tag
when it was needed in XSLT mode.
+ $Server->Mail({ CC => '...', BCC => '...' }), now works to send
CC & BCC headers/recipients.
+ Removed $Apache::ASP::Register definition which defined the current
executing Apache::ASP object. Only one part of the application was
using it, and this has been fixed. This would have been an unsafe
use of globals for a threaded environment.
+ Decreased latency when doing Application_OnStart, used to sleep(1)
for CleanupMaster sync, but this is not necessary for Application_OnStart
scenario
+ Restructure code / core templates for MailErrorsTo funcationality.
Wrote test mail_error.t to cover this. $ENV{REMOTE_USER} will now
be displayed in the MailErrorsTo message when defined from 401 basic auth.
+ $Server->RegisterCleanup should be thread safe now, as it no longer relies
for runtime configuration via %Config defined there. Update docs
for running in standalone CGI mode
+ Make use of MANFEST.SKIP to not publish the dev/* files anymore.
- Script_OnEnd guaranteed to run after $Response->End, but
it will not run if there was an error earlier in the request.
+ lots of new test cases covering behaviour of $Response->End
and $Response->Redirect under various conditions like XMLSubs
and SoftRedirect and global.asa Script_OnStart
+ asp-perl will be installed into the bin executables when
Apache::ASP is installed. asp-perl is the command line version
of Apache::ASP that can also be used to run script in CGI mode.
Test case covering asp-perl functionality.
+ asp CGI/command line script now called asp-perl. I picked this
name because Apache::ASP often has the name asp-perl in distributions
of the module.
-Make Apache::ASP script run under perl taint checking -T for perl 5.6.1...
$code =~ tr///; does not work to untaint here, so much use the slower:
$code =~ /^(.*)$/s; $code = $1; method to untaint.
-Check for inline includes changing, included in a dynamic included
loaded at runtime via $Response->Include(). Added test case for
this at t/include_change.t. If an inline include of a dynamic include
changes, the dynamic include should get recompiled now.
-Make OK to use again with PerlTaintCheck On, with MLDBM::Sync 2.25.
Fixed in ASP.pm, t/global.asa, and created new t/taint_check.t test script
+Load more modules when Apache::ASP is loaded so parent will share more
with children httpd:
Apache::Symbol
Devel::Symdump
Config
lib
MLDBM::Sync::SDBM_File
+When FileUploadMax bytes is exceeded for a file upload, there will not
CacheDB where output is larger and there are not many
versions to cache, like for XSLTCache, where the site is
mostly static.
+ Better RESOURCES section to web site, especially with adding
some links to past Apache::ASP articles & presentations.
$VERSION = 2.25; $DATE="10/11/2001";
+ Improved ./site/apps/search application, for better
search results at Apache::ASP site. Also, reengineered
application better, with more perl code moved to global.asa.
Make use of MLDBM::Sync::SDBM_File, where search database
before was engineering around SDBM_File's shortcomings.
- Fix for SessionSerialize config, which broke in 2.23
Also, added t/session_serialize.t to test suite to catch
this problem in the future.
$VERSION = 2.23; $DATE="10/11/2001";
+Make sure a couple other small standard modules get loaded
upon "PerlModule Apache::ASP", like Time::HiRes, Class::Struct,
and MLDBM::Serializer::Data::Dumper. If not available
these modules won't cause errors, but will promote child httpd
RAM sharing if they are.
-XMLSubs args parsing fix so an arg like z-index
does not error under UseStrict. This is OK now:
<my:layer z-index=3 top=0 left=0> HTML </my:layer>
-Only remove outermost <SCRIPT> tags from global.asa
for IIS/PerlScript compatibility. Used to remove
all <SCRIPT> tags, which hurt when some subs in globa.asa
would be printing some JavaScript.
+$Response->{IsClientConnected} now updated correctly
before global.asa Script_OnStart. $Response->IsClientConnect()
can be used for accurate accounting, while
$Response->{IsClientConnected} only gets updated
after $Response->Flush(). Added test cases to response.t
+$Server->HTMLEncode(\$data) API extension, now can take
scalar ref, which can give a 5% improvement in benchmarks
for data 100K in size.
-Access to $Application is locked when Application_OnEnd &
Application_OnStart is called, creating a critical section
sub My::Auth::handler {
my $r = shift;
my $ASP = Apache::ASP->new($r)
my $Session = $ASP->Session;
}
In the above example, $Session would be the same $Session
object created later while running the ASP script for this
same request.
Added t/asp_object.t test for this. Fixed global.asa to only
init StateDir when application.asp starts which is the first
test script to run.
-Fixed on Win32 to make Apache::ASP->new($r) able to create
multiple master ASP objects per request. Was not reentrant
safe before, particularly with state locking for dbms like
$Application & $Session.
++Output caching for includes, built on same layer ( extended )
as XSLTCache, test suite at t/cache.t. Enabled with special
<% return(1,2); %>
$VERSION = 2.21; $DATE="8/5/2001";
+Documented RequestParams config in CONFIG misc section.
+Documented new XSLT caching directives.
+Updated ./site/eg/.htaccess XSLT example config
to use XSLTCache setting.
+New FAQ section on why perl variables are sticky globals,
suggested by Mark Seger.
-push Global directory onto @INC during ASP script execution
Protect contents of original @INC with local. This makes
things compatible with .09 Apache::ASP where we always had
Global in @INC. Fixed needed by Henrik Tougaard
- ; is a valid separator like & for QueryString Parameters
Fixed wanted by Anders
+Documented ';' may separate many directories in the IncludesDir
setting for creating a more flexible includes search path.
$VERSION = 2.17; $DATE="6/17/2001";
+Added ASP perl mmm-mode subclass and configuration
in editors/mmm-asp-perl.el file for better emacs support.
Updated SYNTAX/Editors documentation.
+Better debugging error message for Debug 2 or 3 settings
for global.asa errors. Limit debug output for lines
preceding rendered script.
-In old inline include mode, there should no longer
be the error "need id for includes" when using
$Response->Include() ... if DynamicIncludes were
enabled, this problem would not have likely occured
anyway. DynamicIncludes are preferrable to use so
that compiled includes can be shared between scripts.
This bug was likely introduced in version 2.11.
introduced in 2.11.
-Now file upload forms, forms with ENCTYPE="multipart/form-data"
can have multiple check boxes and select items marked for
@params = $Request->Form('param_name') functionality. This
will be demonstrated via the ./site/eg/file_upload.asp example.
$VERSION = 2.11; $DATE="05/29/2001";
+Parser optimization from Dariusz Pietrzak
-work around for global destruction error message for perl 5.6
during install
+$Response->{IsClientConnected} now will be set
correctly with ! $r->connection->aborted after each
$Response->Flush()
+New XSLTParser config which can be set to XML::XSLT or
XML::Sablotron. XML::Sablotron renders 10 times faster,
but differently. XML::XSLT is pure perl, so has wider
platform support than XML::Sablotron. This config affects
interface implemented for CollectionItem config.
Also $Request->QueryString('multiple args')->Item(1) method.
Note ASP collections start counting at 1.
--fixed race condition, where multiple processes might
try creating the same state directory at the same time, with
one winning, and one generating an error. Now, web process
will recheck for directory existence and error if
it doesn't.
-global.asa compilation will be cached correctly, not
sure when this broke. It was getting reloaded every request.
-StateAllWrite config, when set creates state files
with a+rw or 0666 permissions, and state directories
with a+rwx or 0777 permissions. This allows web servers
running as different users on the same machine to share a
common StateDir config. Also StateGroupWrite config
with perms 0770 and 0660 respectively.
-Apache::ASP->Loader() now won't follow links to
just one step away now from implementing XSP logic.
+$Server->Execute and $Server->Transfer API extensions
implemented. Execute is the same as $Request->Include()
and $Server->Transfer is like an apache internal redirect
but keeps the current ASP objects for the next script.
Added examples, transfer.htm, and modified dynamic_includes.htm.
+Better compile time error debugging with Debug 2 or -2.
Will hilite/link the buggy line for global.asa errors,
include errors, and XML/XSLT errors just like with
ASP scripts before.
+Nice source hiliting when viewing source for the example
scripts.
+Runtime string writing optimization for static HTML going
through $Response.
+New version numbering just like everyone else. Starting at 1.91
incoming session id that does not match one already seen. This will
help for those with Search engines that have bookmarked
pages with the session ids in the query strings. This breaks away
from standard ASP session id implementation which will automatically
use the session id presented by the browser, now a new session id will
be returned if the presented one is invalid or expired.
-$Application->GetSession will only return a session if
one already existed. It would create one before by default.
+Script_OnFlush global.asa event handler, and $Response->{BinaryRef}
member which is a scalar reference to the content about to be flushed.
See ./site/eg/global.asa for example usage, used in this case to
insert font tags on the fly into the output.
+Highlighting and linking of line error when Debug is set to 2 or -2.
--removed fork() call from flock() backup routine? How did
that get in there? Oh right, testing on Win32. :(
Very painful lesson this one, sorry to whom it may concern.
+$Application->SessionCount support turned off by default
must enable with SessionCount config option. This feature
$VERSION = 0.18; $DATE="02/03/2000";
+Documented SessionQuery* & $Server->URL() and
cleaned up formatting some, as well as redoing
some of the sections ordering for better readability.
Document the cookieless session functionality more
in a new SESSIONS section. Also documented new
FileUpload configs and $Request->FileUpload collection.
Documented StatScripts.
+StatScripts setting which if set to 0 will not reload
includes, global.asa, or scripts when changed.
+FileUpload file handles cleanup at garbage collection
time so developer does not have to worry about lazy coding
and undeffing filehandles used in code. Also set
uploaded filehandles to binmode automatically on Win32
platforms, saving the developer yet more typing.
+FileUploadTemp setting, default 0, if set will leave
a temp file on disk during the request, which may be
helpful for processing by other programs, but is also
it, and run it through ab, or Socrates, with SessionQuery
turned on, and then with SessionQueryParse set to see
the difference. SessionQuery just enables of session id
setting from the query string but will not auto parse urls.
-If buffering, Content-Length will again be set.
It broke, probably while I was tuning in the past
couple versions.
+UseStrict setting compiles all scripts including
global.asa with "use strict" turned on for catching
more coding errors. With this setting enabled,
use strict errors die during compilation forcing
Apache::ASP to try to recompile the script until
successful.
-Object use in includes like $Response->Write()
no longer error with "use strict" programming.
+SessionQuery config setting with $Server->URL($url, { %params } )
alpha API extensions to enable cookieless sessions.
Apache::ASP also went from 75 to 102 hits per second
on Solaris.
+PerlTaintCheck On friendly. This is mod_perl's way
of providing -T taint checking. When Apache::ASP
is used with state objects like $Session or $Application,
MLDBM must also be made taint friendly with:
$MLDBM::RemoveTaint = 1;
which could be put in the global.asa. Documented.
+Added $Response->ErrorDocument($error_code, $uri_or_string)
API extension which allows for setting of Apache's error
document at runtime. This is really just a wrapper
for Apache->custom_response() renamed so it syncs with
the Apache ErrorDocument config setting. Updated
documentation, and added error_document.htm example.
=OrderCollections setting was added, but then REMOVED
because it was not going to be used. It bound
$Request->* collections/hashes to Tie::IxHash, so that data
in those collections would be read in the order the
browser sent it, when eaching through or with keys.
-global.asa will be reloaded when changed. This broke
when I optimized the modification times with (stat($file))[9]
rather than "use File::stat; stat($file)->mtime"
-Make Apache::ASP->Loader() PerlRestartHandler safe,
had some unstrict code that was doing the wrong thing.
-IncludesDir config now works with DynamicIncludes.
+DebugBufferLength feature added, giving control to
how much buffered output gets shown when debugging errors.
so I've commented out this parsing trick for now. If you
need me to bring back this functionality, it will be in the
form of a config setting.
For information on PerlScript compatibility, see the PerlScript
section in the ASP docs.
-Added UniquePackages config option, that if set brings back
the old method of compiling each ASP script into its own
separate package. As of v.10, scripts are compiled by default
into the same package, so that scripts, dynamic includes & global.asa
can share globals. This BROKE scripts in the same ASP Application
that defined the same sub routines, as their subs would redefine
each other.
UniquePackages has scripts compiled into separate perl packages,
so they may define subs with the same name, w/o fear of overlap.
Under this settings, scripts will not be able to share globals.
-Secure field for cookies in $Response->Cookies() must be TRUE to
force cookie to be secure. Before, it just had to be defined,
which gave wrong behavior for Secure => 0.
+$Response->{IsClientConnected} set to one by default. Will
work out a real value when I upgrade to apache 1.3.6. This
value has no meaning before, as apache aborts the perl code
when a client drops its connection in earlier versions.
-StatINCMatch / StatINC can be used in production and work
even after a server graceful restart, which is essential for
a production server.
-Content-Length header is set again, if BufferingOn is set, and
haven't $Response->Flush()'d. This broke when I introduce
the Script_OnEnd event handler.
+Optimized reloading of the GlobalPackage perl module upon changes,
so that scripts and dynamic includes don't have to be recompiled.
The global.asa will still have to be though. Since we started
compiling all routines into a package that can be named with
GlobalPackage, we've been undeffing compiled scripts and includes
when the real GlobalPackage changed on disk, as we do a full sweep
through the namespace. Now, we skip those subs that we know to
be includes or scripts.
-Using Apache::Symbol::undef() to undefine precompiled scripts
and includes when reloading those scripts. Doing just an undef()
would sometimes result in an "active subroutine undef" error.
This bug came out when I started thrashing the StatINC system
error for Debug 2 setting. This makes changing libs with StatINC
on a little more friendly when there are errors.
-$Request->QueryString() now stores multiple values for the
same key, just as $Request->Form() has since v.07. In
wantarray() context like @vals = $Request->QueryString('dupkey'),
@vals will store whatever values where associated with dupkey
in the query string like (1,2) from: ?dupkey=1&dupkey=2
+The GlobalPackage config directive may be defined
to explicitly set the perl module that all scripts and global.asa
are compiled into.
-Dynamic includes may be in the Global directory, just like
normal includes.
+Perl script generated from asp scripts should match line
for line, seen in errors, except when using inline (default)
includes, pod comments, or <% #comment %> perl comments, which
will throw off the line counts by adding text, removing
text, or having an extra newline added, respectively.
-Script_OnEnd may now send output to the browser. Before
$main::Response->End() was being called at the end of the
main script preventing further output.
++All scripts are compiled as routines in a namespace uniquely defined
by the global.asa of the ASP application. Thus, scripts, includes, and
global.asa routines will share all globals defined in the global.asa
namespace. This means that globals between scripts will be shared, and
globals defined in a global.asa will be available to scripts.
Scripts used to have their own namespace, thus globals
were not shared between them.
+a -o $output_dir switch on the ./cgi/asp script allows
it to execute scripts and write their output to an output
directory. Useful for building static html sites, based on
asp scripts. An example use would be:
asp -b -o out *.asp
Without an output directory, script output is written to STDOUT
+Improved docs on $Response->Cookies() and $Request->Cookies()
+Added PERFORMANCE doc to main README, and added sub section
on precompiling scripts with Apache::ASP->Loader()
+Naming of CompileIncludes switched over to DynamicIncludes
for greater clarity.
+Dynamic includes can now reference ASP objects like $Session
w/o the $main::* syntax. These subs are no longer anonymous
subs, and are now compiled into the namespace of the global.asa package.
+Apache::ASP->Loader() precompiles dynamic includes too. Making this work
required fixing some subtle bugs / dependencies in the compiling process.
+Added Apache::ASP->Loader() similar to Apache::RegistryLoader for
precompiling ASP scripts. Precompile a whole site at server
startup with one function call.
+Prettied the error messaging with Debug 2.
+Implemented $Response->BinaryWrite(), documented, and created
and example in ./eg/binary_write.htm
+Implemented $Server->MapPath() and created example of its use
in ./eg/server.htm
-$Request->Form() now reads file uploads correctly with
the latest CGI.pm, where $Request->Form('file_field') returns
the actual file name uploaded, which can be used as a file handle
to read in the data. Before, $Request->Form('file_field') would
return a glob that looks like *Fh::filename, so to get the file
name, you would have to parse it like =~ s/^\*Fh\:\://,
which you no longer have to do. As long as parsing was done as
mentioned, the change should be backwards compatible.
+Updated +enhanced documentation on file uploads. Created extra
comments about it as an FAQ, and under $Response->Form(), the latter
being an obvious place for a developer to look for it.
+Updated ./eg/file_upload.asp to show use of non file form data,
with which we had a bug before.
-Compatible with CGI.pm 2.46 headers()
-Compatible with CGI.pm $q = new CGI({}), caveat: does not set params
+use strict; followed by use of objects like $Session is fine.
-Multiple cookies may be set per script execution.
+file upload implemented via CGI.pm
++global.asa implemented with events Session_OnStart and Session_OnEnd
working appropriately.
+StateDir configuration directive implemented.
StateDir allows the session state directory to be specified separately
from the Global directory, useful for operating systems with caching file
systems.
+StateManager config directive. StateManager specifies how frequently
Sessions are cleaned up, with 10 (default) meaning that old Sessions
will be cleaned up 10 times per SessionTimeout period (default 20 minutes).
build/asp.conf view on Meta::CPAN
# config loaded by asp script
%Config = (
XMLSubsMatch => 'site:\w+',
Debug => 3,
UseStrict => 1,
Global => './global',
);
editors/mmm-asp-perl.el view on Meta::CPAN
;;; Apache::ASP mmm-mode config, by Joshua Chamas, 6/17/2001
(require 'mmm-auto)
(require 'mmm-compat)
(require 'mmm-vars)
(setq mmm-global-mode 'maybe)
; sets meta-p to reparse buffer in case the buffer does
; no update automatically while typing
(global-set-key "\M-p" 'mmm-parse-buffer)
;; create asp-perl mmm-mode subclass
(mmm-add-group 'asp-perl '((asp-perl-blocks
:submode perl-mode
:match-face (("<%" . mmm-code-submode-face)
("<%=" . mmm-output-submode_face))
:front "<%=?"
:back "%>"
)))
; .asp, .htm, .inc files will be parsed with mmm-mode
(add-to-list 'mmm-mode-ext-classes-alist '(nil "\\.\\(asp\\|htm\\|inc\\)" asp-perl))
(add-hook 'mmm-major-mode-hook 'turn-on-auto-fill)
; turn off background color for code blocks, may set it if you like
(set-face-background 'mmm-default-submode-face nil)
;(set-face-background 'mmm-default-submode-face "gray")
; set major mode for these files to HTML mode, except global.asa which you
; want to treat as a pure perl file
(setq auto-mode-alist (append '(
("\\.pm$" . cperl-mode)
("\\.asa$" . cperl-mode)
("\\.inc$" . html-mode)
("\\.htm" . html-mode)
("\\.asp$" . html-mode)
) auto-mode-alist))
lib/Apache/ASP/Error.pm view on Meta::CPAN
<b><u>Debug Output</u></b>
<ol>
@{[join("\n<li> ", '', map { $_ } @{$self->{debugs_output}}) ]}
</ol>
</tt>
<pre>
OUT
;
# could be looking at a compilation error, then set the script to what
# we were compiling (maybe global.asa), else its our real script
# with probably a runtime error
my $script;
if($self->{compile_error}) {
$script = ${$self->{compile_eval}};
}
if($$response_buffer) {
my $length = &config($self, 'DebugBufferLength') || 100;
$out .= "<b><u>Last $length Bytes of Buffered Output</u></b>\n\n";
$out .= $self->Escape(substr($$response_buffer, -1 * $length));
lib/Apache/ASP/Error.pm view on Meta::CPAN
$self->{Server}->RegisterCleanup
(
sub {
for(1..3) {
my $success =
$self->SendMail({
To => $self->{mail_alert_to},
From => &config($self, 'MailFrom', undef, $self->{mail_alert_to}),
Subject => join('-', 'ASP-ALERT', $host),
Body => "$self->{global}-$ENV{SCRIPT_NAME}",
});
if($success) {
last;
} else {
$self->Error("can't send alert mail to $self->{mail_alert_to}");
}
}
});
}
lib/Apache/ASP/GlobalASA.pm view on Meta::CPAN
package Apache::ASP::GlobalASA;
# GlobalASA Object
# global.asa processes, whether or not there is a global.asa file.
# if there is not one, the code is left blank, and empty routines
# are filled in
use strict;
no strict qw(refs);
use vars qw(%stash *stash @ISA @Routines);
# these define the default routines that get parsed out of the
# GLOBAL.ASA file
@Routines =
lib/Apache/ASP/GlobalASA.pm view on Meta::CPAN
"Script_OnStart",
"Script_OnEnd",
"Script_OnParse",
"Script_OnFlush"
);
my $match_events = join('|', @Routines);
sub new {
my $asp = shift || die("no asp passed to GlobalASA");
my $filename = $asp->{global}.'/global.asa';
my $id = &Apache::ASP::FileId($asp, $asp->{global}, undef, 1);
my $package = $asp->{global_package} ? $asp->{global_package} : "Apache::ASP::Compiles::".$id;
$id .= 'x'.$package; # need to recompile when either file or namespace changes
# make sure that when either the file or package changes, that we
# update the global.asa compilation
my $self = bless {
asp => $asp,
'package' => $package,
# filename => $filename,
# id => $id,
};
# assign early, since something like compiling reference the global asa,
# and we need to do that in here
$asp->{GlobalASA} = $self;
$asp->{dbg} && $asp->Debug("GlobalASA package $self->{'package'}");
my $compiled = $Apache::ASP::Compiled{$id};
if($compiled && ! $asp->{stat_scripts}) {
# $asp->{dbg} && $asp->Debug("no stat: GlobalASA already compiled");
$self->{'exists'} = $compiled->{'exists'};
$self->{'compiled'} = $compiled; # for event lookups
return $self;
}
if($compiled) {
# $asp->{dbg} && $asp->Debug("global.asa was cached for $id");
} else {
$asp->{dbg} && $asp->Debug("global.asa was not cached for $id");
$compiled = $Apache::ASP::Compiled{$id} = { mtime => 0, 'exists' => 0 };
}
$self->{compiled} = $compiled;
my $exists = $self->{'exists'} = -e $filename;
my $changed = 0;
if(! $exists && ! $compiled->{'exists'}) {
# fastest exit for simple case of no global.asa
return $self;
} elsif(! $exists && $compiled->{'exists'}) {
# if the global.asa disappeared
$changed = 1;
} elsif($exists && ! $compiled->{'exists'}) {
# if global.asa reappeared
$changed = 1;
} else {
$self->{mtime} = $exists ? (stat(_))[9] : 0;
if($self->{mtime} > $compiled->{mtime}) {
# if the modification time is greater than the compile time
$changed = 1;
}
}
$changed || return($self);
lib/Apache/ASP/GlobalASA.pm view on Meta::CPAN
if($code =~ s/\<script[^>]*\>((.*)\s+sub\s+($match_events).*)\<\/script\>/$1/isg) {
$asp->Debug("script tags removed from $filename for IIS PerlScript compatibility");
}
$code = (
"\n#line 1 $filename\n".
join(" ;; ",
"package $self->{'package'};",
$strict,
"use vars qw(\$".join(" \$",@Apache::ASP::Objects).');',
"use lib qw($self->{asp}->{global});",
$code,
'sub exit { $main::Response->End(); } ',
"no lib qw($self->{asp}->{global});",
'1;',
)
);
$asp->{dbg} && $asp->Debug("compiling global.asa $self->{'package'} $id exists $exists", $self, '---', $compiled);
$code =~ /^(.*)$/s;
$code = $1;
# turn off $^W to suppress warnings about reloading subroutines
# which is a valid use of global.asa. We cannot just undef
# all the events possible in global.asa, as global.asa can be
# used as a general package library for the web application
# --jc, 9/6/2002
local $^W = 0;
# only way to catch strict errors here
if($asp->{use_strict}) {
local $SIG{__WARN__} = sub { die("maybe use strict error: ", @_) };
eval $code;
} else {
eval $code;
lib/Apache/ASP/GlobalASA.pm view on Meta::CPAN
# we cache whether the code was compiled so we can do quick
# lookups before executing it
my $routines = {};
local *stash = *{"$self->{'package'}::"};
for(@Routines) {
if($stash{$_}) {
$routines->{$_} = 1;
}
}
$compiled->{'routines'} = $routines;
$asp->Debug('global.asa routines', $routines);
$self->{'compiled'} = $compiled;
} else {
$asp->CompileErrorThrow($code, "errors compiling global.asa: $@");
}
$self;
}
sub IsCompiled {
my($self, $routine) = @_;
$self->{'compiled'}{routines}{$routine};
}
lib/Apache/ASP/Session.pm view on Meta::CPAN
sub TIEHASH {
my($package, $self) = @_;
bless $self;
}
# stub so we don't have to test for it in autoload
sub DESTROY {
my $self = shift;
# wrapped in eval to suppress odd global destruction error messages
# in perl 5.6.0, --jc 5/28/2001
return unless eval { $self->{state} };
$self->{state}->DESTROY;
undef $self->{state};
%$self = ();
}
# don't need to skip DESTROY since we have it here
# return if ($AUTOLOAD =~ /DESTROY/);
lib/Apache/ASP/StatINC.pm view on Meta::CPAN
$StatStartTime = time();
# Apache::StatINC didn't quite work right, so writing own
sub StatINCRun {
my $self = shift;
my $stats = 0;
# include necessary libs, without nice error message...
# we only do this once if successful, to speed up code a bit,
# and load success bool into global. otherwise keep trying
# to generate consistent error messages
unless($StatINCReady) {
my $ready = 1;
for('Devel::Symdump') {
eval "use $_";
if($@) {
$ready = 0;
$self->Error("You need $_ to use StatINC: $@ ... ".
"Please download it from your nearest CPAN");
}
lib/Apache/ASP/StatINC.pm view on Meta::CPAN
# we need to explicitly re-register a namespace that
# we are about to undef, in case any imports happened there
# since last we checked, so we don't delete duplicate symbols
$self->StatRegister($key, $file, $mtime);
my $class = &File2Class($key);
my $sym = Devel::Symdump->new($class);
my $function;
my $is_global_package = $class eq $self->{GlobalASA}{'package'} ? 1 : 0;
my @global_events_list = $self->{GlobalASA}->EventsList;
for $function ($sym->functions()) {
my $code = \&{$function};
if($function =~ /::O_[^:]+$/) {
$self->Debug("skipping undef of troublesome $function");
next;
}
if($Apache::ASP::Codes{$code}{count} > 1) {
$self->Debug("skipping undef of multiply defined $function: $code");
next;
}
if($is_global_package) {
# skip undef if id is an include or script
if($function =~ /::__ASP_/) {
$self->Debug("skipping undef compiled ASP sub $function");
next;
}
if(grep($function eq $class."::".$_, @global_events_list)) {
$self->Debug("skipping undef global event $function");
next;
}
if($Apache::ASP::ScriptSubs{$function}) {
$self->Debug("skipping undef script subroutine $function");
next;
}
}
lib/Apache/ASP/StatINC.pm view on Meta::CPAN
# don't use "use", since we don't want symbols imported into ASP
delete $INC{$key};
$self->Debug("loading $key with require");
eval { require($key); };
if($@) {
$INC{$key} = $file; # make sure we keep trying to reload it
$self->Error("can't require/reload $key: $@");
next;
}
# if this was the same module as the global.asa package,
# then we need to reload the global.asa, since we just
# undef'd the subs
if($is_global_package) {
# we just undef'd the global.asa routines, so these too
# must be recompiled
$self->Debug("reloading global.asa file after clearing package namespace");
delete $Apache::ASP::Compiled{$self->{GlobalASA}{'id'}};
&Apache::ASP::GlobalASA::new($self);
}
$self->StatRegister($key, $file, $mtime);
# we want to register INC now in case any new libs were
# added when this module was reloaded
$self->StatRegisterAll();
}
lib/Apache/ASP/StateManager.pm view on Meta::CPAN
# Some OS's have hashed directory lookups up to 16 bytes, so we leave room
# for .lock extension ... nevermind, security is more important, back to 32
# $SessionIDLength = 11;
$SessionIDLength = 32;
$DefaultStateDB = 'SDBM_File';
$DefaultStateSerializer = 'Data::Dumper';
sub InitState {
my $self = shift;
my $r = $self->{r};
my $global_asa = $self->{GlobalASA};
## STATE INITS
# what percent of the session_timeout's time do we garbage collect
# state files and run programs like Session_OnEnd and Application_OnEnd
$self->{state_manager} = &config($self, 'StateManager', undef, $Apache::ASP::StateManager);
# state is the path where state files are stored, like $Session, $Application, etc.
$self->{state_dir} = &config($self, 'StateDir', undef, $self->{global}.'/.state');
$self->{state_dir} =~ tr///; # untaint
$self->{session_state} = &config($self, 'AllowSessionState', undef, 1);
$self->{state_serialize} = &config($self, 'ApplicationSerialize');
if($self->{state_db} = &config($self, 'StateDB')) {
# StateDB - Check StateDB module support
$Apache::ASP::State::DB{$self->{state_db}} ||
$self->Error("$self->{state_db} is not supported for StateDB, try: " .
join(", ", keys %Apache::ASP::State::DB));
$self->{state_db} =~ /^(.*)$/; # untaint
lib/Apache/ASP/StateManager.pm view on Meta::CPAN
if($session->Started()) {
# we only want one process purging at a time
if($self->{app_state}) {
$internal->LOCK();
if(($last_session_timeout = $internal->{LastSessionTimeout} || 0) < time()) {
$internal->{'LastSessionTimeout'} = $self->{session_timeout} + time;
$internal->UNLOCK();
$self->{Application}->Lock;
my $obj = tied(%{$self->{Application}});
if($self->CleanupGroups('PURGE')) {
$last_session_timeout && $global_asa->ApplicationOnEnd();
$global_asa->ApplicationOnStart();
}
$self->{Application}->UnLock;
}
$internal->UNLOCK();
}
$global_asa->SessionOnStart();
}
if($self->{app_state}) {
# The last session timeout should only be updated every group_refresh period
# another optimization, rand() so not all at once either
$internal->LOCK();
$last_session_timeout ||= $internal->{'LastSessionTimeout'};
if($last_session_timeout < $self->{session_timeout} + time +
(rand() * $self->{group_refresh} / 2))
{
lib/Apache/ASP/StateManager.pm view on Meta::CPAN
}
$id;
}
sub Secret {
my $self = shift;
# have enough data in here that even if srand() is seeded for the purpose
# of debugging an external program, should have decent behavior.
my $data = $self . $self->{remote_ip} . rand() . time() .
$self->{global} . $self->{'r'} . $self->{'filename'}.
$$ . $ServerID;
my $secret = substr(md5_hex($data), 0, $SessionIDLength);
# by having [0-1][0-f] as the first 2 chars, only 32 groups now, which remains
# efficient for inactive sites, even with empty groups
$secret =~ s/^(.)/0/;
$secret;
}
sub RefreshSessionId {
my($self, $id, $reset) = @_;
site/articles/perlmonth1_intro.html view on Meta::CPAN
</pre>
You might be looking at the $Application object as saying "huh, what's that?".
Simply, $Application allows you to share data between various ASP scripts
and users. Metaphorically it represents your web site as an application,
and $Application is initialized when the first user $Session is created,
and destroyed when the last user $Session is destroyed.
<p>
Events are triggered when these objects are created and destroyed.
In addition to data initialization and destruction, these events allow
the developer to define, in the global.asa, subroutines to be executed
at these event times, providing hooks enabling the web site
to function easily as a dynamic software application. The
<a href=http://www.apache-asp.org/events.html>events</a>
are as follows:
<pre>
Action Event
------ ------
Script_OnStart * Beginning of Script execution
Script_OnEnd * End of Script execution
Application_OnStart Beginning of Application
site/articles/perlmonth2_build.html view on Meta::CPAN
<p>
If the index.asp works on your server, and just prints
<tt>INTRO Apache::ASP::Session=HASH(0x??????)</tt>,
then we know Apache::ASP is working and $Sessions are
enabled.
<hr size=1>
Next, we set up the <tt>global.asa</tt> with globals and
libraries that need to be initialized for the web
application, and define the relevant event handlers.
We also set up per request globals, like the document's
title, which is something that we can do in
<tt>Script_OnStart</tt>. Finally, we use
the <tt>Script_OnStart</tt> and <tt>Script_OnEnd</tt>
events to automatically include the header and footer
for each script in our web application, and initialize
relevant globals used by the scripts.
<p>
Notice that each script can process its own <tt>Logout</tt>
request, which was a decision made after the design
because it seemed good to make the first script, <tt>index.asp</tt>,
<tt>$Session</tt> aware.
<p>
<center>
<table border=0 cellspacing=0 width=90% >
<tr bgcolor=gray><td><font color=white><b># global.asa</b></td></tr>
<tr bgcolor=#c0c0c0><td><pre>
<tt>use File::Basename;
use DBI;
use DBD::CSV;
use vars qw( $DarkColor $Name %Titles $FontBase $Db $Title $Basename $Form $Query );
$DarkColor = '#0000aa';
$Name = "MyBookmarks";
%Titles = (
site/articles/perlmonth2_build.html view on Meta::CPAN
<p>
<hr size=1>
Next we set up the headers and footers for each page.
One problem with <tt>HTML</tt> is that it requires you to specify
the unique titles of the document before the standard
body style for your site, so we cheated this and
created the per page titles already in the <tt>Script_OnStart</tt>
of the <tt>global.asa</tt>.
<p>
<center>
<table border=0 cellspacing=0 width=90% >
<tr bgcolor=gray><td><font color=white><b># header.inc</b></td></tr>
<tr bgcolor=#c0c0c0><td><pre>
<tt><html>
<head><title><%=$Title%></title></head>
<body bgcolor=white link=purple alink=yellow vlink=gray>
site/changes.html view on Meta::CPAN
(d) Updated documention for the $Application->SessionCount API
+ Scripts with named subroutines, which is warned against in the style guide,
will not be cached to help prevent my closure problems that often
hurt new developers working in mod_perl environments. The downside
is that these script will have a performance penalty having to be
recompiled each invocation, but this will kill many closure caching
bugs that are hard to detect.
- $Request->FileUpload('upload_file', 'BrowserFile') would return
a glob before that would be the file name in scalar form. However
this would be interpreted as a reference incorrectly. The fix
is to make sure this is always a scalar by stringifying
this data internally. Thanks to Richard Curtis for pointing
out this bug.
</pre></font>
<p>
<a name=%24VERSION%20%3D%2025b84bf7e></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.51; $DATE="02/10/2003"</b></font>
<font face="courier new" size=3><pre>
site/changes.html view on Meta::CPAN
in case this was set to something else before the error occured.
Thanks to Philip Mak for reporting.
- Couple of minor bug fixes under PerlWarn use, thanks Peter Galbavy
for reporting.
+ Added automatic load of "use Apache2" for compat with mod_perl2
request objects when Apache::ASP is loaded via "PerlModule Apache::ASP"
Thanks to Richard Curtis for reporting bug & subsequent testing.
- When GlobalPackage config changes, but global.asa has not, global.asa
will be recompiled anyway to update the GlobalPackage correctly.
Changing GlobalPackage before would cause errors if global.asa was
already compiled.
++ For ANY PerlSetVar type config, OFF/Off/off will be assumed
to have value of 0 for that setting. Before, only a couple settings
had this semantics, but they all do now for consistency.
- Fix for InodeNames config on OpenBSD, or any OS that might have
a device # of 0 for the file being stat()'d, thanks to Peter Galbavy
for bug report.
site/changes.html view on Meta::CPAN
+ removed useless Apache::ASP::Collection::DESTROY
+ removed useless Apache::ASP::Server::DESTROY
+ removed useless Apache::ASP::GlobalASA::DESTROY
+ removed useless Apache::ASP::Response::DESTROY
- Default path for $Response->{Cookies} was from CookiePath
config, but this was incorrect as CookiePath config is only
for $Session cookie, so now path for $Response->{Cookies}
defaults to /
- Fixed bug where global.asa events would get undefined with
StatINC and GlobalPackage set when the GlobalPackage library
changed & get reloaded.
(d) Documented long time config NoCache.
-- Fixed use with Apache::Filter, capable as both source
and destination filter. Added <a href=eg/filter.filter>./site/eg/filter.filter</a> example
to demonstrate these abilities.
+ Use $r->err_headers_out->add Apache::Table API for cookies
site/changes.html view on Meta::CPAN
+ made deprecated warnings for use of certain $Response->Member
calls more loudly write to error_log, so I can remove the AUTOLOAD
for Response one day
- Probably fixed behavior in CgiHeaders, at least under perl 5.8.0, and
added t/cgi_headers.t to cover this config.
+ removed $Apache::ASP::CompressGzip setting ability, used to possibly
set CompressGzip in the module before, not documented anyway
+ removed $Apache::ASP::Filter setting ability to set Filter globally,
not documented anyway
+ removed old work around for setting ServerStarting to 0
at runtime, which was bad for Apache::DBI on win32 a long
time ago:
$Apache::ServerStarting and $Apache::ServerStarting = 0;
If this code is still needed in Apache::ASP->handler() let
me know.
site/changes.html view on Meta::CPAN
++Optimization for static HTML/XML files that are served up
via Apache::ASP so that they are not compiled into perl subroutines
first. This makes especially native XSLT both faster & take
less memory to serve, before XSL & XML files being transformed
by XSLT would both be compiled as normal ASP script first, so
now this will happen if they really are ASP scripts with embedded
<% %> code blocks & XMLSubs being executed.
+Consolidate some config data for Apache::ASP->Loader to use
globals in @Apache::ASP::CompileChecksumKeys to know which
config data is important for precompiling ASP scripts.
+Further streamlined code compilation. Now both base
scripts and includes use the internal CompileInclude() API
to generate code.
-Fixed runtime HTML error output when Debug is set to -2/2,
so that script correctly again gets rendered in final perl form.
Added compile time error output to <a href=eg/syntax_error.asp>./site/eg/syntax_error.asp</a>
when a special link is clicked for a quick visual test.
-Cleaned up some bad coding practices in <a href=eg/global.asa>./site/eg/global.asa</a>
associated changes in other example files. Comment example
global.asa some for the first time reader
-DemoASP.pm examples module needed "use strict" fix, thanks
to Allan Vest for bug report
--$rv = $Response->Include({ File => ..., Cache => 1});
now works to get the first returned value fetched from
the cache. Before, because a list was always returned,
$rv would have been equal to the number of items returned,
even if the return value list has just one element.
site/changes.html view on Meta::CPAN
of Apache::ASP
+removed cgi/asp link to ../asp-perl from distribution. This
link was for the deprecated asp script which is now asp-perl
</pre></font>
<p>
<a name=%24VERSION%20%3D%20252d85c29></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.39; $DATE="09/10/2002"</b></font>
<font face="courier new" size=3><pre>
-Turn off $^W explicitly before reloading global.asa. Reloading
global.asa when $^W is set will trigger subroutine redefinition
warnings. Reloading global.asa should occur without any problems
under normal usage of the system, thus this work around.
This fix is important to UseStrict functionality because warnings
automatically become thrown as die() errors with UseStrict enabled,
so we have to disable normal soft warnings here.
-$Response->Include() runtime errors now throw a die() that
can be trapped. This was old functionality that has been restored.
Other compile time errors should still trigger a hard error
like script compilation, global.asa, or $Response->Include()
without an eval()
+Some better error handling with Debug 3 or -3 set, cleaned
up developer errors messages somewhat.
</pre></font>
<p>
<a name=%24VERSION%20%3D%202c1fa6b38></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.37; $DATE="07/03/2002"</b></font>
<font face="courier new" size=3><pre>
site/changes.html view on Meta::CPAN
- Fixed bug where XMLSubs where removing <?xml version ... ?> tag
when it was needed in XSLT mode.
+ $Server->Mail({ CC => '...', BCC => '...' }), now works to send
CC & BCC headers/recipients.
+ Removed $Apache::ASP::Register definition which defined the current
executing Apache::ASP object. Only one part of the application was
using it, and this has been fixed. This would have been an unsafe
use of globals for a threaded environment.
+ Decreased latency when doing Application_OnStart, used to sleep(1)
for CleanupMaster sync, but this is not necessary for Application_OnStart
scenario
+ Restructure code / core templates for MailErrorsTo funcationality.
Wrote test mail_error.t to cover this. $ENV{REMOTE_USER} will now
be displayed in the MailErrorsTo message when defined from 401 basic auth.
+ $Server->RegisterCleanup should be thread safe now, as it no longer relies
site/changes.html view on Meta::CPAN
for runtime configuration via %Config defined there. Update docs
for running in standalone CGI mode
+ Make use of MANFEST.SKIP to not publish the dev/* files anymore.
- Script_OnEnd guaranteed to run after $Response->End, but
it will not run if there was an error earlier in the request.
+ lots of new test cases covering behaviour of $Response->End
and $Response->Redirect under various conditions like XMLSubs
and SoftRedirect and global.asa Script_OnStart
+ asp-perl will be installed into the bin executables when
Apache::ASP is installed. asp-perl is the command line version
of Apache::ASP that can also be used to run script in CGI mode.
Test case covering asp-perl functionality.
+ asp CGI/command line script now called asp-perl. I picked this
name because Apache::ASP often has the name asp-perl in distributions
of the module.
site/changes.html view on Meta::CPAN
-Make Apache::ASP script run under perl taint checking -T for perl 5.6.1...
$code =~ tr///; does not work to untaint here, so much use the slower:
$code =~ /^(.*)$/s; $code = $1; method to untaint.
-Check for inline includes changing, included in a dynamic included
loaded at runtime via $Response->Include(). Added test case for
this at t/include_change.t. If an inline include of a dynamic include
changes, the dynamic include should get recompiled now.
-Make OK to use again with PerlTaintCheck On, with MLDBM::Sync 2.25.
Fixed in ASP.pm, t/global.asa, and created new t/taint_check.t test script
+Load more modules when Apache::ASP is loaded so parent will share more
with children httpd:
Apache::Symbol
Devel::Symdump
Config
lib
MLDBM::Sync::SDBM_File
+When FileUploadMax bytes is exceeded for a file upload, there will not
site/changes.html view on Meta::CPAN
+ Better RESOURCES section to web site, especially with adding
some links to past Apache::ASP articles & presentations.
</pre></font>
<p>
<a name=%24VERSION%20%3D%20276d7fe30></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.25; $DATE="10/11/2001";</b></font>
<font face="courier new" size=3><pre>
+ Improved ./site/apps/search application, for better
search results at Apache::ASP site. Also, reengineered
application better, with more perl code moved to global.asa.
Make use of MLDBM::Sync::SDBM_File, where search database
before was engineering around SDBM_File's shortcomings.
- Fix for SessionSerialize config, which broke in 2.23
Also, added t/session_serialize.t to test suite to catch
this problem in the future.
</pre></font>
<p>
<a name=%24VERSION%20%3D%2024674da9c></a>
site/changes.html view on Meta::CPAN
upon "PerlModule Apache::ASP", like Time::HiRes, Class::Struct,
and MLDBM::Serializer::Data::Dumper. If not available
these modules won't cause errors, but will promote child httpd
RAM sharing if they are.
-XMLSubs args parsing fix so an arg like z-index
does not error under UseStrict. This is OK now:
<my:layer z-index=3 top=0 left=0> HTML </my:layer>
-Only remove outermost <SCRIPT> tags from global.asa
for IIS/PerlScript compatibility. Used to remove
all <SCRIPT> tags, which hurt when some subs in globa.asa
would be printing some JavaScript.
+$Response->{IsClientConnected} now updated correctly
before global.asa Script_OnStart. $Response->IsClientConnect()
can be used for accurate accounting, while
$Response->{IsClientConnected} only gets updated
after $Response->Flush(). Added test cases to response.t
+$Server->HTMLEncode(\$data) API extension, now can take
scalar ref, which can give a 5% improvement in benchmarks
for data 100K in size.
-Access to $Application is locked when Application_OnEnd &
Application_OnStart is called, creating a critical section
site/changes.html view on Meta::CPAN
sub My::Auth::handler {
my $r = shift;
my $ASP = Apache::ASP->new($r)
my $Session = $ASP->Session;
}
In the above example, $Session would be the same $Session
object created later while running the ASP script for this
same request.
Added t/asp_object.t test for this. Fixed global.asa to only
init StateDir when application.asp starts which is the first
test script to run.
-Fixed on Win32 to make Apache::ASP->new($r) able to create
multiple master ASP objects per request. Was not reentrant
safe before, particularly with state locking for dbms like
$Application & $Session.
++Output caching for includes, built on same layer ( extended )
as XSLTCache, test suite at t/cache.t. Enabled with special
site/changes.html view on Meta::CPAN
<a name=%24VERSION%20%3D%202c37caa32></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.21; $DATE="8/5/2001";</b></font>
<font face="courier new" size=3><pre>
+Documented RequestParams config in CONFIG misc section.
+Documented new XSLT caching directives.
+Updated <a href=eg/.htaccess>./site/eg/.htaccess</a> XSLT example config
to use XSLTCache setting.
+New FAQ section on why perl variables are sticky globals,
suggested by Mark Seger.
-push Global directory onto @INC during ASP script execution
Protect contents of original @INC with local. This makes
things compatible with .09 Apache::ASP where we always had
Global in @INC. Fixed needed by Henrik Tougaard
- ; is a valid separator like & for QueryString Parameters
Fixed wanted by Anders
site/changes.html view on Meta::CPAN
<p>
<a name=%24VERSION%20%3D%20282c9e25e></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.17; $DATE="6/17/2001";</b></font>
<font face="courier new" size=3><pre>
+Added ASP perl mmm-mode subclass and configuration
in editors/mmm-asp-perl.el file for better emacs support.
Updated SYNTAX/Editors documentation.
+Better debugging error message for Debug 2 or 3 settings
for global.asa errors. Limit debug output for lines
preceding rendered script.
-In old inline include mode, there should no longer
be the error "need id for includes" when using
$Response->Include() ... if DynamicIncludes were
enabled, this problem would not have likely occured
anyway. DynamicIncludes are preferrable to use so
that compiled includes can be shared between scripts.
This bug was likely introduced in version 2.11.
site/changes.html view on Meta::CPAN
@params = $Request->Form('param_name') functionality. This
will be demonstrated via the <a href=eg/file_upload.asp>./site/eg/file_upload.asp</a> example.
</pre></font>
<p>
<a name=%24VERSION%20%3D%2023614edca></a>
<font face=verdana><font class=title size=+0 color=#555555><b>$VERSION = 2.11; $DATE="05/29/2001";</b></font>
<font face="courier new" size=3><pre>
+Parser optimization from Dariusz Pietrzak
-work around for global destruction error message for perl 5.6
during install
+$Response->{IsClientConnected} now will be set
correctly with ! $r->connection->aborted after each
$Response->Flush()
+New XSLTParser config which can be set to XML::XSLT or
XML::Sablotron. XML::Sablotron renders 10 times faster,
but differently. XML::XSLT is pure perl, so has wider
platform support than XML::Sablotron. This config affects
site/changes.html view on Meta::CPAN
interface implemented for CollectionItem config.
Also $Request->QueryString('multiple args')->Item(1) method.
Note ASP collections start counting at 1.
--fixed race condition, where multiple processes might
try creating the same state directory at the same time, with
one winning, and one generating an error. Now, web process
will recheck for directory existence and error if
it doesn't.
-global.asa compilation will be cached correctly, not
sure when this broke. It was getting reloaded every request.
-StateAllWrite config, when set creates state files
with a+rw or 0666 permissions, and state directories
with a+rwx or 0777 permissions. This allows web servers
running as different users on the same machine to share a
common StateDir config. Also StateGroupWrite config
with perms 0770 and 0660 respectively.
-Apache::ASP->Loader() now won't follow links to
site/changes.html view on Meta::CPAN
just one step away now from implementing XSP logic.
+$Server->Execute and $Server->Transfer API extensions
implemented. Execute is the same as $Request->Include()
and $Server->Transfer is like an apache internal redirect
but keeps the current ASP objects for the next script.
Added examples, transfer.htm, and modified dynamic_includes.htm.
+Better compile time error debugging with Debug 2 or -2.
Will hilite/link the buggy line for global.asa errors,
include errors, and XML/XSLT errors just like with
ASP scripts before.
+Nice source hiliting when viewing source for the example
scripts.
+Runtime string writing optimization for static HTML going
through $Response.
+New version numbering just like everyone else. Starting at 1.91
site/changes.html view on Meta::CPAN
incoming session id that does not match one already seen. This will
help for those with Search engines that have bookmarked
pages with the session ids in the query strings. This breaks away
from standard ASP session id implementation which will automatically
use the session id presented by the browser, now a new session id will
be returned if the presented one is invalid or expired.
-$Application->GetSession will only return a session if
one already existed. It would create one before by default.
+Script_OnFlush global.asa event handler, and $Response->{BinaryRef}
member which is a scalar reference to the content about to be flushed.
See <a href=eg/global.asa>./site/eg/global.asa</a> for example usage, used in this case to
insert font tags on the fly into the output.
+Highlighting and linking of line error when Debug is set to 2 or -2.
--removed fork() call from flock() backup routine? How did
that get in there? Oh right, testing on Win32. :(
Very painful lesson this one, sorry to whom it may concern.
+$Application->SessionCount support turned off by default
must enable with SessionCount config option. This feature
site/changes.html view on Meta::CPAN
<font face="courier new" size=3><pre>
+Documented SessionQuery* & $Server->URL() and
cleaned up formatting some, as well as redoing
some of the sections ordering for better readability.
Document the cookieless session functionality more
in a new SESSIONS section. Also documented new
FileUpload configs and $Request->FileUpload collection.
Documented StatScripts.
+StatScripts setting which if set to 0 will not reload
includes, global.asa, or scripts when changed.
+FileUpload file handles cleanup at garbage collection
time so developer does not have to worry about lazy coding
and undeffing filehandles used in code. Also set
uploaded filehandles to binmode automatically on Win32
platforms, saving the developer yet more typing.
+FileUploadTemp setting, default 0, if set will leave
a temp file on disk during the request, which may be
helpful for processing by other programs, but is also
site/changes.html view on Meta::CPAN
it, and run it through ab, or Socrates, with SessionQuery
turned on, and then with SessionQueryParse set to see
the difference. SessionQuery just enables of session id
setting from the query string but will not auto parse urls.
-If buffering, Content-Length will again be set.
It broke, probably while I was tuning in the past
couple versions.
+UseStrict setting compiles all scripts including
global.asa with "use strict" turned on for catching
more coding errors. With this setting enabled,
use strict errors die during compilation forcing
Apache::ASP to try to recompile the script until
successful.
-Object use in includes like $Response->Write()
no longer error with "use strict" programming.
+SessionQuery config setting with $Server->URL($url, { %params } )
alpha API extensions to enable cookieless sessions.
site/changes.html view on Meta::CPAN
Apache::ASP also went from 75 to 102 hits per second
on Solaris.
+PerlTaintCheck On friendly. This is mod_perl's way
of providing -T taint checking. When Apache::ASP
is used with state objects like $Session or $Application,
MLDBM must also be made taint friendly with:
$MLDBM::RemoveTaint = 1;
which could be put in the global.asa. Documented.
+Added $Response->ErrorDocument($error_code, $uri_or_string)
API extension which allows for setting of Apache's error
document at runtime. This is really just a wrapper
for Apache->custom_response() renamed so it syncs with
the Apache ErrorDocument config setting. Updated
documentation, and added error_document.htm example.
=OrderCollections setting was added, but then REMOVED
because it was not going to be used. It bound
$Request->* collections/hashes to Tie::IxHash, so that data
in those collections would be read in the order the
browser sent it, when eaching through or with keys.
-global.asa will be reloaded when changed. This broke
when I optimized the modification times with (stat($file))[9]
rather than "use File::stat; stat($file)->mtime"
-Make Apache::ASP->Loader() PerlRestartHandler safe,
had some unstrict code that was doing the wrong thing.
-IncludesDir config now works with DynamicIncludes.
+DebugBufferLength feature added, giving control to
how much buffered output gets shown when debugging errors.
site/changes.html view on Meta::CPAN
so I've commented out this parsing trick for now. If you
need me to bring back this functionality, it will be in the
form of a config setting.
For information on PerlScript compatibility, see the PerlScript
section in the ASP docs.
-Added UniquePackages config option, that if set brings back
the old method of compiling each ASP script into its own
separate package. As of v.10, scripts are compiled by default
into the same package, so that scripts, dynamic includes & global.asa
can share globals. This BROKE scripts in the same ASP Application
that defined the same sub routines, as their subs would redefine
each other.
UniquePackages has scripts compiled into separate perl packages,
so they may define subs with the same name, w/o fear of overlap.
Under this settings, scripts will not be able to share globals.
-Secure field for cookies in $Response->Cookies() must be TRUE to
force cookie to be secure. Before, it just had to be defined,
which gave wrong behavior for Secure => 0.
+$Response->{IsClientConnected} set to one by default. Will
work out a real value when I upgrade to apache 1.3.6. This
value has no meaning before, as apache aborts the perl code
when a client drops its connection in earlier versions.
site/changes.html view on Meta::CPAN
-StatINCMatch / StatINC can be used in production and work
even after a server graceful restart, which is essential for
a production server.
-Content-Length header is set again, if BufferingOn is set, and
haven't $Response->Flush()'d. This broke when I introduce
the Script_OnEnd event handler.
+Optimized reloading of the GlobalPackage perl module upon changes,
so that scripts and dynamic includes don't have to be recompiled.
The global.asa will still have to be though. Since we started
compiling all routines into a package that can be named with
GlobalPackage, we've been undeffing compiled scripts and includes
when the real GlobalPackage changed on disk, as we do a full sweep
through the namespace. Now, we skip those subs that we know to
be includes or scripts.
-Using Apache::Symbol::undef() to undefine precompiled scripts
and includes when reloading those scripts. Doing just an undef()
would sometimes result in an "active subroutine undef" error.
This bug came out when I started thrashing the StatINC system
site/changes.html view on Meta::CPAN
error for Debug 2 setting. This makes changing libs with StatINC
on a little more friendly when there are errors.
-$Request->QueryString() now stores multiple values for the
same key, just as $Request->Form() has since v.07. In
wantarray() context like @vals = $Request->QueryString('dupkey'),
@vals will store whatever values where associated with dupkey
in the query string like (1,2) from: ?dupkey=1&dupkey=2
+The GlobalPackage config directive may be defined
to explicitly set the perl module that all scripts and global.asa
are compiled into.
-Dynamic includes may be in the Global directory, just like
normal includes.
+Perl script generated from asp scripts should match line
for line, seen in errors, except when using inline (default)
includes, pod comments, or <% #comment %> perl comments, which
will throw off the line counts by adding text, removing
text, or having an extra newline added, respectively.
-Script_OnEnd may now send output to the browser. Before
$main::Response->End() was being called at the end of the
main script preventing further output.
</pre></font>++All scripts are compiled as routines in a namespace uniquely
<font face="courier new" size=3><pre> defined by the global.asa of the ASP application. Thus,
scripts, includes, and global.asa routines will share
all globals defined in the global.asa namespace. This means
that globals between scripts will be shared, and globals
defined in a global.asa will be available to scripts.
Scripts used to have their own namespace, thus globals
were not shared between them.
+a -o $output_dir switch on the ./cgi/asp script allows
it to execute scripts and write their output to an output
directory. Useful for building static html sites, based on
asp scripts. An example use would be:
asp -b -o out *.asp
Without an output directory, script output is written to STDOUT
site/changes.html view on Meta::CPAN
+Improved docs on $Response->Cookies() and $Request->Cookies()
+Added PERFORMANCE doc to main README, and added sub section
on precompiling scripts with Apache::ASP->Loader()
+Naming of CompileIncludes switched over to DynamicIncludes
for greater clarity.
+Dynamic includes can now reference ASP objects like $Session
w/o the $main::* syntax. These subs are no longer anonymous
subs, and are now compiled into the namespace of the global.asa package.
+Apache::ASP->Loader() precompiles dynamic includes too. Making this work
required fixing some subtle bugs / dependencies in the compiling process.
+Added Apache::ASP->Loader() similar to Apache::RegistryLoader for
precompiling ASP scripts. Precompile a whole site at server
startup with one function call.
+Prettied the error messaging with Debug 2.
site/changes.html view on Meta::CPAN
+Implemented $Response->BinaryWrite(), documented, and created
and example in ./eg/binary_write.htm
+Implemented $Server->MapPath() and created example of its use
in ./eg/server.htm
-$Request->Form() now reads file uploads correctly with
the latest CGI.pm, where $Request->Form('file_field') returns
the actual file name uploaded, which can be used as a file handle
to read in the data. Before, $Request->Form('file_field') would
return a glob that looks like *Fh::filename, so to get the file
name, you would have to parse it like =~ s/^\*Fh\:\://,
which you no longer have to do. As long as parsing was done as
mentioned, the change should be backwards compatible.
+Updated +enhanced documentation on file uploads. Created extra
comments about it as an FAQ, and under $Response->Form(), the latter
being an obvious place for a developer to look for it.
+Updated ./eg/file_upload.asp to show use of non file form data,
with which we had a bug before.
site/changes.html view on Meta::CPAN
-Compatible with CGI.pm 2.46 headers()
-Compatible with CGI.pm $q = new CGI({}), caveat: does not set params
+use strict; followed by use of objects like $Session is fine.
-Multiple cookies may be set per script execution.
+file upload implemented via CGI.pm
++global.asa implemented with events Session_OnStart and Session_OnEnd
working appropriately.
+StateDir configuration directive implemented.
StateDir allows the session state directory to be specified separately
from the Global directory, useful for operating systems with caching file
systems.
+StateManager config directive. StateManager specifies how frequently
Sessions are cleaned up, with 10 (default) meaning that old Sessions
will be cleaned up 10 times per SessionTimeout period (default 20 minutes).
site/config.html view on Meta::CPAN
<td valign=top bgcolor=white>
<font size=+0 face=verdana,arial>
<font face=verdana><font class=title size=+1 color=#555555><b>CONFIG</b></font>
<font face="courier new" size=3><pre>
</pre></font>You may use a <Files ...> directive in your httpd.conf
Apache configuration file to make Apache::ASP start ticking. Configure the
optional settings if you want, the defaults are fine to get started.
The settings are documented below.
Make sure Global is set to where your web applications global.asa is
if you have one!
<font face="courier new" size=3><pre>
PerlModule Apache::ASP
<Files ~ (\.asp)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global .
PerlSetVar StateDir /tmp/asp
</Files>
</pre></font>NOTE: do not use this for the examples in ./site/eg. To get the
site/config.html view on Meta::CPAN
<p>
<a name=Core></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Core</b></font>
</font>
<p>
<a name=Global></a>
<font face=verdana><font class=title size=-1 color=#555555><b>Global</b></font>
<font face="courier new" size=3><pre>
</pre></font>Global is the nerve center of an Apache::ASP application, in which
the global.asa may reside defining the web application's
event handlers.
<font face="courier new" size=3><pre>
</pre></font>This directory is pushed onto @INC, so you will be able
to "use" and "require" files in this directory, and perl modules
developed for this application may be dropped into this directory,
for easy use.
<font face="courier new" size=3><pre>
</pre></font>Unless StateDir is configured, this directory must be some
writeable directory by the web server. $Session and $Application
object state files will be stored in this directory. If StateDir
site/config.html view on Meta::CPAN
or $Response->Include() syntax, may also be in this directory,
please see section on includes for more information.
<font face="courier new" size=3><pre>
PerlSetVar Global /tmp
</pre></font>
<p>
<a name=GlobalPackag78b2e61e></a>
<font face=verdana><font class=title size=-1 color=#555555><b>GlobalPackage</b></font>
<font face="courier new" size=3><pre>
</pre></font>Perl package namespace that all scripts, includes, & global.asa
events are compiled into. By default, GlobalPackage is some
obscure name that is uniquely generated from the file path of
the Global directory, and global.asa file. The use of explicitly
naming the GlobalPackage is to allow scripts access to globals
and subs defined in a perl module that is included with commands like:
<font face="courier new" size=3><pre>
in perl script: use Some::Package;
in apache conf: PerlModule Some::Package
PerlSetVar GlobalPackage Some::Package
</pre></font>
<p>
<a name=UniquePackagcf82a357></a>
<font face=verdana><font class=title size=-1 color=#555555><b>UniquePackages</b></font>
<font face="courier new" size=3><pre>
</pre></font>default 0. Set to 1 to compile each script into its own perl package,
so that subroutines defined in one script will not collide with another.
<font face="courier new" size=3><pre>
</pre></font>By default, ASP scripts in a web application are compiled into the
*same* perl package, so these scripts, their includes, and the
global.asa events all share common globals & subroutines defined by each other.
The problem for some developers was that they would at times define a
subroutine of the same name in 2+ scripts, and one subroutine definition would
redefine the other one because of the namespace collision.
<font face="courier new" size=3><pre>
PerlSetVar UniquePackages 0
</pre></font>
<p>
<a name=DynamicInclu7867a61a></a>
<font face=verdana><font class=title size=-1 color=#555555><b>DynamicIncludes</b></font>
site/config.html view on Meta::CPAN
<font face="courier new" size=3><pre>
PerlSetVar IncludesDir .
</pre></font>Also, multiple includes directories may be set by creating
a directory list separated by a semicolon ';' as in
<font face="courier new" size=3><pre>
PerlSetVar IncludesDir ../shared;/usr/local/asp/shared
</pre></font>Using IncludesDir in this way creates an includes search
path that would look like ., Global, ../shared, /usr/local/asp/shared
The current directory of the executing script is checked first
whenever an include is specified, then the Global directory
in which the global.asa resides, and finally the IncludesDir
setting.</font>
<p>
<a name=NoCache></a>
<font face=verdana><font class=title size=-1 color=#555555><b>NoCache</b></font>
<font face="courier new" size=3><pre>
</pre></font>Default 0, if set to 1 will make it so that neither script nor
include compilations are cached by the server. Using this configuration
will save on memory but will slow down script execution. Please
see the <a href=tuning.html><font size=-1 face=verdana><b>TUNING</b></font></a> section for other strategies on improving site performance.
site/config.html view on Meta::CPAN
PerlSetVar StateDir ./.state
</pre></font>
<p>
<a name=StateManager></a>
<font face=verdana><font class=title size=-1 color=#555555><b>StateManager</b></font>
<font face="courier new" size=3><pre>
</pre></font>default 10, this number specifies the numbers of times per SessionTimeout
that timed out sessions are garbage collected. The bigger the number,
the slower your system, but the more precise Session_OnEnd's will be
run from global.asa, which occur when a timed out session is cleaned up,
and the better able to withstand Session guessing hacking attempts.
The lower the number, the faster a normal system will run.
<font face="courier new" size=3><pre>
</pre></font>The defaults of 20 minutes for SessionTimeout and 10 times for
StateManager, has dead Sessions being cleaned up every 2 minutes.
<font face="courier new" size=3><pre>
PerlSetVar StateManager 10
</pre></font>
<p>
site/config.html view on Meta::CPAN
<font face="courier new" size=3><pre>
</pre></font>Default 0, this NON-PORTABLE configuration will allow sessions to span
multiple web sites that match the same domain root. This is useful if
your web sites are hosted on the same machine and can share the same
StateDir configuration, and you want to shared the $Session data
across web sites. Whatever this is set to, that will add a
<font face="courier new" size=3><pre>
; domain=$CookieDomain
</pre></font>part to the Set-Cookie: header set for the session-id cookie.
<font face="courier new" size=3><pre>
PerlSetVar CookieDomain .your.global.domain
</pre></font>
<p>
<a name=SessionTimeo21fc354e></a>
<font face=verdana><font class=title size=-1 color=#555555><b>SessionTimeout</b></font>
<font face="courier new" size=3><pre>
</pre></font>Default 20 minutes, when a user's session has been inactive for this
period of time, the Session_OnEnd event is run, if defined, for
that session, and the contents of that session are destroyed.
<font face="courier new" size=3><pre>
site/config.html view on Meta::CPAN
<p>
<a name=Developer%20Enc3495841></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Developer Environment</b></font>
</font>
<p>
<a name=UseStrict></a>
<font face=verdana><font class=title size=-1 color=#555555><b>UseStrict</b></font>
<font face="courier new" size=3><pre>
</pre></font>default 0, if set to 1, will compile all scripts, global.asa
and includes with "use strict;" inserted at the head of
the file, saving you from the painful process of strictifying
code that was not strict to begin with.
<font face="courier new" size=3><pre>
</pre></font>Because of how essential "use strict" programming is in
a <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a> environment, this default might be set to 1
one day, but this will be up for discussion before that
decision is made.
<font face="courier new" size=3><pre>
</pre></font>Note too that errors triggered by "use strict" are
site/config.html view on Meta::CPAN
<font face="courier new" size=3><pre>
</pre></font>If you define StatINCMatch, you do not need to define StatINC.
<font face="courier new" size=3><pre>
PerlSetVar StatINCMatch .*
</pre></font>
<p>
<a name=StatScripts></a>
<font face=verdana><font class=title size=-1 color=#555555><b>StatScripts</b></font>
<font face="courier new" size=3><pre>
</pre></font>default 1, if set to 0, changed scripts, global.asa, and includes
will not be reloaded. Coupled with Apache <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a> startup and restart
handlers executing Apache::ASP->Loader() for your application
this allows your application to be frozen, and only reloaded on the
next server restart or stop/start.
<font face="courier new" size=3><pre>
</pre></font>There are a few advantages for not reloading scripts and modules
in production. First there is a slight performance improvement
by not having to stat() the script, its includes and the global.asa
every request.
<font face="courier new" size=3><pre>
</pre></font>From an application deployment standpoint, you
also gain the ability to deploy your application as a
snapshot taken when the server starts and restarts.
This provides you with the reassurance that during a
production server update from development sources, you
do not have to worry with sources being used for the
wrong libraries and such, while they are all being
copied over.
site/eg/application.asp view on Meta::CPAN
$Application->Lock();
$Application->{Count}+=1;
$Application->UnLock();
%>
We just incremented the $Application->{Count} variable by 1.
Here is the value of the $Application->{Count} variable... <br>
<b><%= sprintf("%06d", $Application->{Count}) %></b>
<p>
We reset this value to 20 every Application_OnStart. Check
out the global.asa!
<!--#include file=footer.inc-->
site/eg/global.asa view on Meta::CPAN
use DemoASP;
# import basename() into global.asa namespace
use File::Basename qw(basename);
# when PerlSetVar UseStrict setting on, need to declare
# global variables with "use vars"
use vars qw($FontFace $GlobalFont %EG $title);
# static read only global
$GlobalFont = 'face=verdana,helvetica';
# this is run every request for all scripts that share this global.asa
sub Script_OnStart {
$Response->Debug("Script_OnStart $0 in global.asa");
$Session->{Started}++;
$title = '';
}
sub Script_OnEnd {
$Response->Debug("Script_OnEnd $0 in global.asa");
$Session->{Ended}++;
}
# modify data on the way out
sub Script_OnFlush {
if($Response->{ContentType} eq 'text/html') {
my $data = $Response->{BinaryRef};
$$data =~ s/(\<(body|td).*?\>)/$1\<font $GlobalFont\>/isg;
}
my $data = $Response->{BinaryRef};
$Response->Debug("Script_OnFlush: about to flush ".length($$data)." bytes to client");
}
sub Session_OnStart {
$Session->{Count} = 10;
$Session->{onstart} = time();
$Application->{'Session'.$Session->SessionID} = '?';
$Response->AppendToLog("Session_OnStart! in ./eg/global.asa ". $Session->SessionID);
}
sub Session_OnEnd {
my $t_session_active = time() - $Session->{onstart};
$Application->{'Session'.$Session->SessionID} = $t_session_active;
$Response->AppendToLog("Session_OnEnd! in ./eg/global.asa ". $Session->SessionID);
}
sub Application_OnStart {
$Response->AppendToLog("Application_OnStart! in ./eg/global.asa");
$Application->{Count} = 20;
}
sub Application_OnEnd {
$Response->AppendToLog("Application_OnEnd! in ./eg/global.asa");
}
# you can share globals between scripts as of v.10, as all scripts, including
# the global.asa are compiled into the same module
%EG = (
'.htaccess' => 'Configuration parameters that make Apache::ASP tick.',
'application.asp' => 'Uses $Application for incrementing a counter.',
'binary_write.htm' => '$Response->BinaryWrite() demo for an asp script serving a gif.',
'cgi.htm' => 'Shows compatibility with the CGI.pm library',
'counting.htm' => 'Simple asp syntax shown by wrapping a for loop around html and inserting a '.
site/eg/global.asa view on Meta::CPAN
'footer.inc' => 'Footer include for most of the scripts listed.',
'form.asp' => 'Shows simple use of $Request->Form() and how to get raw input data '.
' from $Request->BinaryRead()',
'formfill.asp' =>
'Shows use of FormFill feature, which auto fills HTML forms from '.
'$Request->Form() data. One must install HTML::FillInForm to use this feature. ',
'global.asa' => 'The global.asa is the nervous system of an ASP application and '.
'is where you define your event handlers.',
'global_asa_demo.asp' => 'Shows how the global.asa can be used to track users in an '.
'application',
'header.inc' => 'Header include for most of the scripts listed here.',
'include.htm' => 'Shows how you can decompose a script into common included files',
# 'ordered_collections.ixhtm' =>
# 'Used with Tie::IxHash, shows the natural ordering of the $Request->Form() collection '.
# 'by how the browser submitted the data, useful for some.',
site/eg/global.asa view on Meta::CPAN
'xslt.xml' => 'XSLT transformation of XML script, using XML::XSLT, and a DBM based cache with the XSLTCache setting. Also possible for the XSLTParser setting is XML::Sablotron for faster XSLT rendering.',
);
if($Apache::ASP::ModPerl2) {
delete $EG{'ssi_filter.ssi'};
delete $EG{'filter.filter'};
}
$SIG{__DIE__} = \&Carp::confess;
# note if you include XMLSubs in the global.asa, make sure to
# switch the package context to the XMLSubs namespace to avoid
# any odd variable scoping problems
package my;
sub my::include {
my($args, $text) = @_;
# reference the $Response object in the package namespace
# since we are in the my:: package and not the GlobalPackage/global.asa
$main::Response->Include($args->{src}, title => $args->{title});
}
sub my::ttb {
my($args, $text) = @_;
print "<font face=courier size=-1><b>$text</b></font>";
}
sub my::table {
my($args, $text) = @_;
site/eg/global_asa_demo.asp view on Meta::CPAN
#!/usr/bin/perl /usr/bin/asp-perl
<!--#include file="header.inc" args=""-->
This example serves as how one may use the global.asa
file event handlers. Please see the global.asa file
for the code relevant to this example.
<p>
The following table lists the sessions that have been
recorded in the global.asa file into $Application. When
a session ends, its time lived is recorded and displayed
below. Active sessions are also listed.
<p>
<%
my $count;
my @sessions;
for(keys %{$Application}) {
next unless ($_ =~ /^Session/);
$count++;
push(@sessions, $_);
site/eg/index.html view on Meta::CPAN
#!/usr/bin/perl /usr/bin/asp-perl
<%
# split the page in 2 for nice formatting and english style sorting
my(@col1, @col2);
my @keys = sort keys %EG;
@keys || die("\%EG is not defined, make sure you copied ./eg/global.asa correctly");
my $half = int(@keys/2) + 1;
for(my $i =0; $i <= $#keys; $i++) {
if($i < $half) {
push(@col1, $keys[$i]);
} else {
push(@col2, $keys[$i]);
}
}
$Response->Debug('col1', \@col1, 'col2', \@col2);
site/eg/session.asp view on Meta::CPAN
<% for (@rows){ %>
<tr>
<td><tt><%=$Server->HTMLEncode($_)%></tt></td>
<td><%=eval($_) || $@%></td>
</tr>
<% } %>
</table>
</center>
<p>
The value for $Session->{Count} gets reset to 10 on every session start
in the global.asa file.
<!--#include file=footer.inc-->
site/eg/xml_subs.asp view on Meta::CPAN
<% for("yellow", "red", "blue") { %>
<my:table bgcolor=$_ width=200 title=ucfirst($_)."Box" border=5>
Colored Box
</my:table>
<p>
<% } %>
<p>
The my::* perl subs defining the XMLSubs are located in the
global.asa.
<p>
<my:include src="footer.inc"/>
site/eg/xml_subs_strict.asp view on Meta::CPAN
not surrounded with quotes like bgcolor="red" or bgcolor='red'
</my:table>
<p>
<my:table width="400" title="Title Box" border='3'
bgcolor = 'red' >
The color='red' param is OK here as it had the correct syntax.
</my:table>
<p>
The my::* perl subs defining the XMLSubs are located in the
global.asa.
<p>
<my:include src="footer.inc"/>
site/events.html view on Meta::CPAN
<hr size=1>
<p>
<p>
<a name=Overview></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Overview</b></font>
<font face="courier new" size=3><pre>
</pre></font>The ASP platform allows developers to create Web Applications.
In fulfillment of real software requirements, ASP allows
event-triggered actions to be taken, which are defined in
a global.asa file. The global.asa file resides in the
Global directory, defined as a config option, and may
define the following actions:
<font face="courier new" size=3><pre>
Action Event
------ ------
Script_OnStart * Beginning of Script execution
Script_OnEnd * End of Script execution
Script_OnFlush * Before $Response being flushed to client.
Script_OnParse * Before script compilation
Application_OnStart Beginning of Application
Application_OnEnd End of Application
Session_OnStart Beginning of user Session.
Session_OnEnd End of user Session.
* These are API extensions that are not portable, but were
added because they are incredibly useful
</pre></font>These actions must be defined in the $Global/global.asa file
as subroutines, for example:
<font face="courier new" size=3><pre>
sub Session_OnStart {
$Application->{$Session->SessionID()} = started;
}
</pre></font>Sessions are easy to understand. When visiting a page in a
web application, each user has one unique $Session. This
session expires, after which the user will have a new
$Session upon revisiting.
<font face="courier new" size=3><pre>
site/events.html view on Meta::CPAN
the first $Session is created, the $Application is created.
When the last user $Session expires, that $Application
expires also. For some web applications that are always busy,
the Application_OnEnd event may never occur.</font>
<p>
<a name=Script_OnSta6a4cfa7f></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnStart & Script_OnEnd</b></font>
<font face="courier new" size=3><pre>
</pre></font>The script events are used to run any code for all scripts
in an application defined by a global.asa. Often, you would
like to run the same code for every script, which you would
otherwise have to add by hand, or add with a file include,
but with these events, just add your code to the global.asa,
and it will be run.
<font face="courier new" size=3><pre>
</pre></font>There is one caveat. Code in Script_OnEnd is not guaranteed
to be run when $Response->End() is called, since the program
execution ends immediately at this event. To always run critical
code, use the API extension:
<font face="courier new" size=3><pre>
$Server->RegisterCleanup()
</pre></font>
site/events.html view on Meta::CPAN
</pre></font>Thus I would not put anything mission-critical in the Session_OnEnd,
just stuff that would be nice to run whenever it gets run.</font>
<p>
<a name=Script_OnFludc73a8d8></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnFlush</b></font>
<font face="courier new" size=3><pre>
</pre></font>API extension. This event will be called prior to flushing
the $Response buffer to the web client. At this time,
the $Response->{BinaryRef} buffer reference may be used to modify
the buffered output at runtime to apply global changes to scripts
output without having to modify all the scripts.
<font face="courier new" size=3><pre>
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
</pre></font>Check out the <a href=eg/global.asa>./site/eg/global.asa</a> for an example of its use.</font>
<p>
<a name=Script_OnPar383e5cdf></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnParse</b></font>
<font face="courier new" size=3><pre>
</pre></font>This event allows one to set up a source filter on the script text,
allowing one to change the script on the fly before the compilation
stage occurs. The script text is available in the $Server->{ScriptRef}
scalar reference, and can be accessed like so:
<font face="courier new" size=3><pre>
site/events.html view on Meta::CPAN
PerlTransHandler
PerlFixupHandler
PerlHandler
PerlLogHandler
PerlCleanupHandler
</pre></font>For straight Apache::ASP programming, there are some
equivalents, say Script_OnStart event instead of Init/Fixup
stages, or $Server->RegisterCleanup() for Log/Cleanup stages,
but you can do things in the mod_perl handlers that you
cannot do in Apache::ASP, especially if you want to handle
all files globally, and not just ASP scripts.
<font face="courier new" size=3><pre>
</pre></font>For many Apache::* modules for use with mod_perl, of which
Apache::ASP is just one, check out
<a href=http://perl.apache.org/src/apache-modlist.html>http://perl.apache.org/src/apache-modlist.html</a>
<font face="courier new" size=3><pre>
</pre></font>To gain access to the ASP objects like $Session outside
in a non-PerlHandler mod_perl handler, you may use this API:
<font face="courier new" size=3><pre>
my $ASP = Apache::ASP->new($r); # $r is Apache->request object
</pre></font>as in this possible Authen handler:
site/faq.html view on Meta::CPAN
--disable-rule=EXPAT
^^^^^
</pre></font>keywords: segmentation fault, segfault seg fault</font>
<p>
<a name=Why%20do%20varia68e97184></a>
<font face=verdana><font class=title size=-1 color=#555555><b>Why do variables retain their values between requests?</b></font>
<font face="courier new" size=3><pre>
</pre></font>Unless scoped by my() or local(), perl variables in <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a>
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:
<font face="courier new" size=3><pre>
<HTML><BODY>
$counter++;
$Response->Write("<BR>Counter: $counter");
</BODY></HTML>
</pre></font>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:
<font face="courier new" size=3><pre>
use vars qw($counter);
</pre></font>You can make all your Apache::ASP scripts strict by
default by setting:
<font face="courier new" size=3><pre>
PerlSetVar UseStrict 1
</pre></font>
<p>
<a name=Apache%20errorf0bcd572></a>
site/faq.html view on Meta::CPAN
<a name=How%20do%20I%20acc6523fd95></a>
<font face=verdana><font class=title size=-1 color=#555555><b>How do I access the ASP Objects in general?</b></font>
<font face="courier new" size=3><pre>
</pre></font>All the ASP objects can be referenced through the main package with
the following notation:
<font face="courier new" size=3><pre>
$main::Response->Write("html output");
</pre></font>This notation can be used from anywhere in perl, including routines
registered with $Server->RegisterCleanup().
<font face="courier new" size=3><pre>
</pre></font>You use the normal notation in your scripts, includes, and global.asa:
<font face="courier new" size=3><pre>
$Response->Write("html output");
</pre></font>
<p>
<a name=Can%20I%20print%2874ba394b></a>
<font face=verdana><font class=title size=-1 color=#555555><b>Can I print() in ASP?</b></font>
<font face="courier new" size=3><pre>
</pre></font>Yes. You can print() from anywhere in an ASP script as it aliases
to the $Response->Write() method. Using print() is portable with
site/objects.html view on Meta::CPAN
<td valign=top bgcolor=white>
<font size=+0 face=verdana,arial>
<font face=verdana><font class=title size=+1 color=#555555><b>OBJECTS</b></font>
<font face="courier new" size=3><pre>
</pre></font>The beauty of the ASP Object Model is that it takes the
burden of <a href=cgi.html><font size=-1 face=verdana><b>CGI</b></font></a> and Session Management off the developer,
and puts them in objects accessible from any
ASP script & include. For the perl programmer, treat these objects
as globals accessible from anywhere in your ASP application.
<font face="courier new" size=3><pre>
</pre></font>The Apache::ASP object model supports the following:
<font face="courier new" size=3><pre>
Object Function
------ --------
$Session - user session state
$Response - output to browser
$Request - input from browser
$Application - application state
$Server - general methods
</pre></font>These objects, and their methods are further defined in the
following sections.
<font face="courier new" size=3><pre>
</pre></font>If you would like to define your own global objects for use
in your scripts and includes, you can initialize them in
the global.asa Script_OnStart like:
<font face="courier new" size=3><pre>
use vars qw( $Form $Site ); # declare globals
sub Script_OnStart {
$Site = My::Site->new; # init $Site object
$Form = $Request->Form; # alias form data
$Server->RegisterCleanup(sub { # garbage collection
$Site->DESTROY;
$Site = $Form = undef;
});
}
</pre></font>In this way you can create site wide application objects
and simple aliases for common functions.</font>
site/objects.html view on Meta::CPAN
</pre></font>This object manages the output from the ASP Application and the
client web browser. It does not store state information like the
$Session object but does have a wide array of methods to call.</font>
<p>
<a name=%24Response-%3E%7B4a870234></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Response->{BinaryRef}</b></font>
<font face="courier new" size=3><pre>
</pre></font>API extension. This is a perl reference to the buffered output of
the $Response object, and can be used in the Script_OnFlush
global.asa event to modify the buffered output at runtime
to apply global changes to scripts output without having to
modify all the scripts. These changes take place before
content is flushed to the client web browser.
<font face="courier new" size=3><pre>
sub Script_OnFlush {
my $ref = $Response->{BinaryRef};
$$ref =~ s/\s+/ /sg; # to strip extra white space
}
</pre></font>Check out the <a href=eg/global.asa>./site/eg/global.asa</a> for an example of its use.</font>
<p>
<a name=%24Response-%3E%7Ba1012197></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Response->{Buffer}</b></font>
<font face="courier new" size=3><pre>
</pre></font>Default 1, when TRUE sends output from script to client only at
the end of processing the script. When 0, response is not buffered,
and client is sent output as output is generated by the script.</font>
<p>
site/objects.html view on Meta::CPAN
<a name=%24Response-%3E%7Bf284792c></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Response->{IsClientConnected}</b></font>
<font face="courier new" size=3><pre>
</pre></font>1 if web client is connected, 0 if not. This value
starts set to 1, and will be updated whenever a
$Response->Flush() is called. If BufferingOn is
set, by default $Response->Flush() will only be
called at the end of the HTML output.
<font face="courier new" size=3><pre>
</pre></font>As of version 2.23 this value is updated correctly
before global.asa Script_OnStart is called, so
global script termination may be correctly handled
during that event, which one might want to do
with excessive user STOP/RELOADS when the web
server is very busy.
<font face="courier new" size=3><pre>
</pre></font>An API extension $Response->IsClientConnected
may be called for refreshed connection status
without calling first a $Response->Flush</font>
<p>
<a name=%24Response-%3E%7Bc48a3e9e></a>
site/objects.html view on Meta::CPAN
<p>
<a name=%24Request-%3EFo76659178></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Request->Form($name)</b></font>
<font face="courier new" size=3><pre>
</pre></font>Returns the value of the input of name $name used in a form
with POST method. If $name is not specified, returns a ref to
a hash of all the form data. One can use this hash to
create a nice alias to the form data like:
<font face="courier new" size=3><pre>
# in global.asa
use vars qw( $Form );
sub Script_OnStart {
$Form = $Request->Form;
}
# then in ASP scripts
<%= $Form->{var} %>
</pre></font>File upload data will be loaded into $Request->Form('file_field'),
where the value is the actual file name of the file uploaded, and
the contents of the file can be found by reading from the file
name as a file handle as in:
site/objects.html view on Meta::CPAN
<p>
<a name=%24Request-%3EPa455879ca></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Request->Params($name)</b></font>
<font face="courier new" size=3><pre>
</pre></font>API extension. If RequestParams <a href=config.html><font size=-1 face=verdana><b>CONFIG</b></font></a> is set, the $Request->Params
object is created with combined contents of $Request->QueryString
and $Request->Form. This is for developer convenience simlar
to <a href=http://stein.cshl.org/WWW/software/CGI/cgi_docs.html><font size=-1 face=verdana><b>CGI.pm</b></font></a>'s param() method. Just like for $Response->Form,
one could create a nice alias like:
<font face="courier new" size=3><pre>
# in global.asa
use vars qw( $Params );
sub Script_OnStart {
$Params = $Request->Params;
}
</pre></font>
<p>
<a name=%24Request-%3EQu7330a0a3></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Request->QueryString($name)</b></font>
<font face="courier new" size=3><pre>
site/objects.html view on Meta::CPAN
session ids are stored in $Application during Session_OnStart, with
full access to these sessions for administrative purposes.
<font face="courier new" size=3><pre>
</pre></font>Be careful not to expose full session ids over the net, as they
could be used by a hacker to impersonate another user. So when
creating a session manager, for example, you could create
some other id to reference the SessionID internally, which
would allow you to control the sessions. This kind of application
would best be served under a secure web server.
<font face="courier new" size=3><pre>
</pre></font>The <a href=eg/global_asa_demo.asp>./site/eg/global_asa_demo.asp</a> script makes use of this routine
to display all the data in current user sessions.</font>
<p>
<a name=%24Application7441b337></a>
<font face=verdana><font class=title size=-1 color=#555555><b>$Application->SessionCount()</b></font>
<font face="courier new" size=3><pre>
</pre></font>This NON-PORTABLE method returns the current number of active sessions
in the application, and is enabled by the SessionCount configuration setting.
This method is not implemented as part of the original ASP
object model, but is implemented here because it is useful. In particular,
site/ssi.html view on Meta::CPAN
<!--#include file=filename.inc-->
</pre></font>,the .inc being merely a convention, text from the included
file will be inserted directly into the script being executed
and the script will be compiled as a whole. Whenever the
script or any of its includes change, the script will be
recompiled.
<font face="courier new" size=3><pre>
</pre></font>Includes go a great length to promote good decomposition
and code sharing in ASP scripts, but they are still
fairly static. As of version .09, includes may have dynamic
runtime execution, as subroutines compiled into the global.asa
namespace. The first way to invoke includes dynamically is
<font face="courier new" size=3><pre>
<!--#include file=filename.inc args=@args-->
</pre></font>If @args is specified, Apache::ASP knows to execute the
include at runtime instead of inlining it directly into
the compiled code of the script. It does this by
compiling the script at runtime as a subroutine, and
caching it for future invocations. Then the compiled
subroutine is executed and has @args passed into its
as arguments.
site/style.html view on Meta::CPAN
<tr>
<td valign=top >
<font face="lucida console" size=-1>
<a href=#UseStrict>UseStrict</a>
</font>
</td>
<td valign=top >
<font face="lucida console" size=-1>
<a href=#Use%20global.ae21f52dc>Use global.asa's Script_On* Events</a>
</font>
</td>
</tr>
<tr>
<td valign=top >
<font face="lucida console" size=-1>
<a href=#Do%20not%20definc4a0555f>Do not define subroutines in scripts.</a>
site/style.html view on Meta::CPAN
</table>
<hr size=1>
<p>
<p>
<a name=UseStrict></a>
<font face=verdana><font class=title size=+0 color=#555555><b>UseStrict</b></font>
<font face="courier new" size=3><pre>
</pre></font>One of perl's blessings is also its bane, variables do not need to be
declared, and are by default globally scoped. The problem with this in
<a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a> is that global variables persist from one request to another
even if a different web browser is viewing a page.
<font face="courier new" size=3><pre>
</pre></font>To avoid this problem, perl programmers have often been advised to
add to the top of their perl scripts:
<font face="courier new" size=3><pre>
use strict;
</pre></font>In Apache::ASP, you can do this better by setting:
<font face="courier new" size=3><pre>
PerlSetVar UseStrict 1
</pre></font>which will cover both script & global.asa compilation and will catch
"use strict" errors correctly. For perl modules, please continue to
add "use strict" to the top of them.
<font face="courier new" size=3><pre>
</pre></font>Because its so essential in catching hard to find errors, this
configuration will likely become the default in some future release.
For now, keep setting it.</font>
<p>
<a name=Do%20not%20definc4a0555f></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Do not define subroutines in scripts.</b></font>
site/style.html view on Meta::CPAN
}
...
}
</pre></font>The biggest problem with subroutines defined in subroutines is the
side effect of creating closures, which will not behave as usually
desired in a <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a> environment. To understand more about closures,
please read up on them & "Nested Subroutines" at:
<font face="courier new" size=3><pre>
<a href=http://perl.apache.org/docs/general/perl_reference/perl_reference.html>http://perl.apache.org/docs/general/perl_reference/perl_reference.html</a>
</pre></font>Instead of defining subroutines in scripts, you may add them to your sites
global.asa, or you may create a perl package or module to share
with your scripts. For more on perl objects & modules, please see:
<font face="courier new" size=3><pre>
<a href=http://perldoc.perl.org/perlobj.html>http://perldoc.perl.org/perlobj.html</a>
</pre></font>
<p>
<a name=Use%20global.ae21f52dc></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Use global.asa's Script_On* Events</b></font>
<font face="courier new" size=3><pre>
</pre></font>Chances are that you will find yourself doing the same thing repeatedly
in each of your web application's scripts. You can use Script_OnStart
and Script_OnEnd to automate these routine tasks. These events are
called before and after each script request.
<font face="courier new" size=3><pre>
</pre></font>For example, let's say you have a header & footer you would like to
include in the output of every page, then you might:
<font face="courier new" size=3><pre>
# global.asa
sub Script_OnStart {
$Response->Include('header.inc');
}
sub Script_OnEnd {
$Response->Include('footer.inc');
}
</pre></font>Or let's say you want to initialize a global database connection
for use in your scripts:
<font face="courier new" size=3><pre>
# global.asa
use Apache::DBI; # automatic persistent database connections
use DBI;
use vars qw($dbh); # declare global $dbh
sub Script_OnStart {
# initialize $dbh
$dbh = DBI->connect(...);
# force you to explicitly commit when you want to save data
$Server->RegisterCleanup(sub { $dbh->rollback; });
}
sub Script_OnEnd {
site/tuning.html view on Meta::CPAN
a RAM disk and would be a good place to set the "StateDir" config
setting to. When cached file systems are used there is little
performance penalty for using state files. Linux tends to do a good job
caching its file systems, so pick a StateDir for ease of system
administration.
<font face="courier new" size=3><pre>
</pre></font>On Win32 systems, where <a href=http://perl.apache.org><font size=-1 face=verdana><b>mod_perl</b></font></a> requests are serialized, you
can freely use SessionSerialize to make your $Session requests
faster, and you can achieve similar performance benefits for
$Application if you call $Application->Lock() in your
global.asa's Script_OnStart.</font>
<p>
<a name=Low%20MaxClien5a8237ea></a>
<font face=verdana><font class=title size=+0 color=#555555><b>Low MaxClients</b></font>
<font face="courier new" size=3><pre>
</pre></font>Set your MaxClients low, such that if you have that
many httpd servers running, which will happen on busy site,
your system will not start swapping to disk because of
excessive RAM usage. Typical settings are less than 100
even with 1 gig RAM! To handle more client connections,
t/global_event_end.t view on Meta::CPAN
#!/usr/bin/perl
use Apache::ASP::CGI;
&Apache::ASP::CGI::do_self(Global => 'global_event_end', NoState => 1);
__END__
<% $t->not_ok; %>
t/reload_global_asa.t view on Meta::CPAN
use Apache::ASP::CGI;
use lib qw(t .);
use T;
use strict;
$SIG{__DIE__} = \&Carp::confess;
chdir('t');
my $r = Apache::ASP::CGI->init('reload_global_asa.t');
my %config = (
UseStrict => 1,
# Debug => -3,
);
for(keys %config) {
$r->dir_config->set($_, $config{$_});
}
my $t = T->new;