#####################################################################
#
# ASP - Facilitate integration of PerlScript with ASP
#
# Author: Tim Hammerquist
# Revision: 1.07
# NOTES: based on Matt Sergeant's Win32-ASP module.
#
#####################################################################
#
# Copyright 2000 Tim Hammerquist. All rights reserved.
#
# This file is distributed under the Artistic License.
# See http://www.perl.com/language/misc/Artistic.html or
# the license that comes with your perl distribution.
#
# Contact me at cafall@voffice.net with any comments,
# flames, queries, suggestions, or general curiosity.
#
#####################################################################
require 5.005;
use strict;
my ($APACHE, $WIN32);
$APACHE = $Apache::ASP::VERSION;
$WIN32 = $^O =~ /win/i;
package ASP::IO;
sub TIEHANDLE { shift->new(@_) }
sub PRINT { shift->print(@_) }
sub PRINTF { shift->print(sprintf(@_)) }
sub new { bless {}, shift; }
sub print {
my $self = shift;
ASP::Print(@_);
1;
}
1;
package ASP;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $ASPOUT);
require CGI;
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS
$Application $ObjectContext $Request $Response
$Server $Session $ScriptingNamespace @DeathHooks
);
@ISA = qw( Exporter );
%EXPORT_TAGS = (
basic => [qw(
Print Warn die exit param param_count
)],
strict => [qw(
Print Warn die exit param param_count
$Application $ObjectContext $Request
$Response $Server $Session
$ScriptingNamespace
)],
all => [qw(
Print Warn die exit param param_count
$Application $ObjectContext $Request
$Response $Server $Session
$ScriptingNamespace
DebugPrint HTMLPrint
escape unescape escapeHTML unescapeHTML
)],
);
Exporter::export_tags('basic');
Exporter::export_ok_tags('all');
$Application = $main::Application;
$ObjectContext = $main::ObjectContext;
$Request = $main::Request;
$Response = $main::Response;
$Server = $main::Server;
$Session = $main::Session;
$ScriptingNamespace = $main::ScriptingNamespace unless $APACHE;
if ($WIN32) {
%ENV = ();
for (Win32::OLE::in $Request->ServerVariables) {
$ENV{$_} = $Request->ServerVariables($_)->Item;
}
}
}
$VERSION='1.07';
$ASPOUT = tie *RESPONSE_FH, 'ASP::IO';
select RESPONSE_FH unless $APACHE;
$SIG{__WARN__} = sub { ASP::Print(@_) };
sub _END { &$_() for @DeathHooks; @DeathHooks = (); 1; }
=head1 NAME
ASP - a Module for ASP (PerlScript) Programming
=head1 SYNOPSIS
use strict;
use ASP qw(:strict);
print "Testing, testing.
";
my $item = param('item');
if($item eq 'Select one...') {
die "Please select a value from the list.";
}
print "You selected $item.";
exit;
=head1 DESCRIPTION
This module is based on Matt Sergeant's excellent
Win32::ASP module, which can be found at
EFE.
After using Mr. Sergeant's module, I took on the task of
customizing and optimizing it for my own purposes. Feel
free to use it if you find it useful.
=head1 NOTES
This module is designed to work with both ASP PerlScript on IIS4,
as well as mod_perl/Apache::ASP on *nix platforms. Apache::ASP
already provides some of the functionality provided by this module;
because of this (and to avoid redundancy), ASP.pm attempts to detect
its environment. Differences between Apache and MS ASP are noted.
Both of the print() and warn() standard perl funcs are overloaded
to output to the browser. print() is also available via the
$ASP::ASPOUT->print() method call.
$Request->ServerVariables are only stuffed into %ENV on Win32
platforms, as Apache::ASP already provides this.
ASP.pm also exports the $ScriptingNamespace symbol (Win32 only).
This symbol allows PerlScript to call subs/functions written in
another script language. For example:
<%@ language=PerlScript %>
<%
use ASP qw(:strict);
print $ScriptingNamespace->SomeSub("arg1");
%>
=head1 USE
=head2 use ASP qw(:basic);
Exports basic subs: Print, Warn, die, exit, param, param_count. Same
as C