#####################################################################
#
# Win32::ASP - a Module for ASP (PerlScript) Programming
#
# Author: Matt Sergeant
# Revision: 1.9
# Last Change: Added SetCookie
#####################################################################
# Copyright 1998 Matt Sergeant. All rights reserved.
#
# This file is distributed under the Artistic License. See
# http://www.ActiveState.com/corporate/artistic_license.htm or
# the license that comes with your perl distribution.
#
# The most up to date version of this script should always be available
# at http://come.to/fastnet
#
# For comments, questions, bugs or general interest, feel free to
# contact me at msergeant@ndirect.co.uk
#####################################################################
package Win32::ASP;
use strict;
=head1 NAME
Win32::ASP - a Module for ASP (PerlScript) Programming
=head1 Synopsis
use Win32::ASP;
print "This is a test
";
$PageName = GetFormValue('PageName');
if($PageName eq 'Select a page...') {
die "Please go back and select a value from the Pages list";
}
print "You selected the ", $PageName, " page";
exit;
=head1 Description
These routines are some I knocked together one day when I was saying the
following: "Why don't my "print" statements output to the browser?" and
"Why doesn't exit and die end my script?". So I started investigating how
I could overload the core functions. "print" is overloaded via the tie
mechanism (thanks to Eryq (F), Zero G Inc. for the
code which I ripped from IO::Scalar). You can also get at print using the
OO mechanism with $Win32::ASP::SH->print(). Also added recently was code
that allowed cleanup stuff to be executed when you exit() or die(), this
comes in the form of the C function. The C function
simply wraps up unicode conversion and BinaryWrite in one call. Finally I
was annoyed that I couldn't just develop a script
using GET and then change to POST for release because of the difference in
how the ASP code handles the different formats, GetFormValue solves that one.
=head2 Installation instructions
Download the file. If you get it from my geocities web site you will have
to rename it (they don't like .pm extensions). Make sure the file is called
ASP.pm
Now move the file into the perl\site\\lib\win32 directory (where
is your perl version).
That's it - you're ready to start PerlScripting with ease.
=head1 Function Reference
=cut
BEGIN {
use Exporter ();
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS
$Application
$ObjectContext
$Request
$Response
$Server
$Session
@DeathHooks
);
@ISA = qw(Exporter);
@EXPORT = qw( Print
wprint
die
exit
GetFormValue
GetFormCount
);
%EXPORT_TAGS = ( 'strict' => [qw(
Print
wprint
die
exit
GetFormValue
GetFormCount
$Application
$ObjectContext
$Request
$Response
$Server
$Session
)]
);
@EXPORT_OK = qw ( SetCookie );
Exporter::export_ok_tags('strict'); # Add all strict vars to @EXPORT_OK
$Application = $main::Application;
$ObjectContext = $main::ObjectContext;
$Request = $main::Request;
$Response = $main::Response;
$Server = $main::Server;
$Session = $main::Session;
# my $Servs = $Request->ServerVariables;
# foreach my $env (in $Servs) {
# $ENV{$env} = $Request->ServerVariables($env);
# }
}
$Win32::ASP::VERSION='1.9';
my $SH = tie *RESPONSE_FH, 'Win32::ASP::IO';
select RESPONSE_FH;
=over 4
=item use Win32::ASP qw(:strict);
This allows you to use the ASP module in a "strict" perl script. Normally under "use strict"
PerlScript would complain that the ASP objects ($Response, $Session etc) were not
initialised: "Global symbol "Response" requires explicit package name at - line XXX".
To get around this I simply assign and assign back the variables, and export them into
the main namespace.
Note: In order to use this feature you may have to make changes to the registry.
This is at your own risk. If your computer stops working after you make these
changes I am not responsible. I have made the changes myself and they appear to
work, but please be careful.
Change the following keys:
HKEY_LOCAL_MACHINE\
SYSTEM\
CurrentControlSet\
Services\
W3SVC\
ASP\
LanguageEngines\
PerlScript
Write = "$main::Response->write(|);"
WriteBlock = "$main::Response->writeblock(|);"
The change should be just to add the "main::" after the "$" and before "Response".
=item Print LIST
Prints a string or comma separated list of strings to the browser. Use
as if you were using print in a CGI application. Print gets around ASP's
limitations of 128k in a single Response->Write call.
Obsolete - use C instead.
NB: C calls Print, so you could use either, but print is more integrated
with "the perl way".
=cut
sub Print (@) {
my ($output);
foreach $output (@_) {
if (length($output) > 128000) {
Print (unpack('a128000a*', $output));
}
else {$main::Response->Write($output);}
}
}
=item DebugPrint LIST
The same as C except the output is between HTML comments
so that you can only see it with "view source". DebugPrint is
not exported so you have to use it as Win32::ASP::DebugPrint()
This function is useful to debug your application. For example I
use it to print out SQL before it is executed.
=cut
sub DebugPrint (@) {
Print "\n";
}
=item HTMLPrint LIST
The same as C except the output is taken and encoded so that
any html tags appear as sent, i.e. < becomes <, > becomes > etc.
HTMLPrint is not exported, so use it like Win32::ASP::HTMLPrint.
This function is useful for printing output that comes from a database
or a file, where you don't have total control over the input.
=cut
sub HTMLPrint (@) {
my ($output);
foreach $output (@_) {
Print $Server->HTMLEncode($output);
}
}
=item wprint LIST
Obsolete: Use C instead
=cut
sub wprint (@) {
Print @_;
}
=item die LIST
Prints the contents of LIST to the browser and then exits. C automatically
calls $Response->End for you, it also executes any cleanup code you have
added with C.
=cut
sub die (@) {
Print @_;
Print "