# Win32::ASP.pm
#
# Win32::ASP - a Module for ASP (PerlScript) Programming
#
# Authors:
# Matt Sergeant (through 2.12)
# Bill Odom (2.15 and later)
#
# Revision: 2.15
#
# Changes:
# - Commented and reformatted code.
# - Removed experimental STDIN support (see sections commented out below).
# - Removed autosplit/autoloading (for now).
# - Removed END block death hook handling.
# - Fixed param() call.
# - Added LoadEnvironment().
# - Began cleaning up the POD.
#
# 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.
#
use strict;
# print overloading
package Win32::ASP::IO;
use Win32::OLE::Variant;
sub new
{
my $self = bless {}, shift;
# WNO: Removed experimental STDIN support.
#
# my $request = shift;
# $self->{input_data} = Win32::OLE::Variant->new( VT_UI1, $request->BinaryRead(
# $request->{TotalBytes} ) )->Value;
# $self->{current_pos} = 0;
#
$self;
}
# end sub new
sub print
{
my $self = shift;
Win32::ASP::Print(@_);
1;
}
# end sub print
sub TIEHANDLE { shift->new(@_) }
sub PRINT { shift->print(@_) }
sub PRINTF { shift->print(sprintf(@_)) }
# WNO: Removed experimental STDIN support.
#
# sub READ
# {
# my $self = shift;
# my $bufref;
#
# $$bufref = \$_[0];
#
# my (undef, $len, $offset) = @_;
#
# if (defined $offset)
# {
# $self->{current_pos} = $offset;
# }
#
# my $string = substr($self->{input_data}, $self->{current_pos}, $len);
#
# $self->{current_pos} += $len;
#
# $$bufref = $string;
#
# return length($string);
#
# }
# # end sub READ
#
#
# sub READLINE
# {
# my $self = shift;
# my $string;
# while (my $char = $self->GETC)
# {
# $string .= $char;
# last if $char eq "\015";
# }
# return $string;
# }
# # end sub READLINE
#
#
# sub GETC
# {
# my $char;
#
# return undef unless shift->READ($char, 1);
# return $char;
# }
# # end sub GETC
#
1;
# end print overloading
## Win32::ASP Module Interface
package Win32::ASP;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
BEGIN
{
require Exporter;
# require AutoLoader;
use vars
qw(
@ISA
@EXPORT
@EXPORT_OK
%EXPORT_TAGS
$Application
$ObjectContext
$Request
$Response
$Server
$Session
@DeathHooks
);
@ISA =
qw(
Exporter
# AutoLoader
);
@EXPORT =
qw(
Print
wprint
die
exit
GetFormValue
GetFormCount
param
);
%EXPORT_TAGS =
(
strict =>
[ qw(
Print
wprint
die
exit
GetFormValue
GetFormCount
$Application
$ObjectContext
$Request
$Response
$Server
$Session
) ]
);
@EXPORT_OK = qw( SetCookie );
# Add all strict vars to @EXPORT_OK.
#
Exporter::export_ok_tags('strict');
# Set up the exportable ASP objects, while avoiding "only used once"
# warnings.
#
$Application = $::Application = $::Application;
$ObjectContext = $::ObjectContext = $::ObjectContext;
$Request = $::Request = $::Request;
$Response = $::Response = $::Response;
$Server = $::Server = $::Server;
$Session = $::Session = $::Session;
}
# end BEGIN block
$VERSION='2.15';
# Create tied filehandle for print overloading.
#
tie *RESPONSE_FH, 'Win32::ASP::IO';
select RESPONSE_FH;
# WNO: Removed experimental STDIN support.
#
# close STDIN;
# tie *STDIN, 'Win32::ASP::IO', $Request;
#
# Preloaded methods go here.
sub _END
{
my $func;
for $func (@DeathHooks)
{
$func->();
}
}
# end sub _END
# Autoload methods go after =cut, and are processed by the autosplit program.
# WNO: Commented out until I reinstate autoloading.
# 1;
# __END__
=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
I knocked these routines together one day when I was wondering
"Why don't my C statements output to the browser?" and
"Why don't C and C end my script?" So I started investigating how
I could overload the core functions. C is overloaded via the C
mechanism (thanks to Eryq (F), Zero G Inc. for the
code which I ripped from IO::Scalar).
Also added recently was C, which allows cleanup code to
be executed upon an C or C. C wraps up Unicode
conversion and C<< $Response->BinaryWrite >> in one call. Finally, I was
annoyed that I couldn't just develop a script using GET, then change to
POST for release, since ASP code handles each one differently. C
solves that one.
=head2 Installation instructions
Assuming the ActiveState repository is up-to-date with the latest archive
from CPAN, you should be able to type:
ppm install Win32-ASP
on the command line. Make sure you're connected to the Internet first.
Installing via MakeMaker is pretty standard -- just download
the archive from CPAN, extract it to some directory, then type in that
directory:
perl Makefile.PL
nmake
nmake install
Don't do C because the ASP objects won't be available.
=head1 Function Reference
=head2 Print LIST
Obsolete - use C instead.
Outputs a string or comma-separated list of strings to the browser. Use
as if you were using C in a CGI application. C handles the ASP
limitation of 128K per C<< $Response->Write >> call.
Note: C calls C, so you can actually use either one,
but C is more integrated with "the Perl way."
=cut
sub Print
{
for my $output (@_)
{
if (length($output) > 128000)
{
Win32::ASP::Print(unpack('a128000a*', $output));
}
else
{
$::Response->Write($output);
}
}
}
# end sub Print
=head2 DebugPrint LIST
The same as C, except the output is wrapped in HTML comment markers,
so that you can only see it by viewing the page source. C is
not exported, so call it as
Win32::ASP::DebugPrint($val);
This function is useful for debugging your application. For example, I
use it to print out SQL before it is executed.
=cut
sub DebugPrint(@)
{
Print "\n";
}
# end sub DebugPrint
=head2 HTMLPrint LIST
The same as C, except the output is encoded so that
any HTML tags appear as sent, i.e. E becomes <, E becomes >, etc.
C is not exported, so call it as
Win32::ASP::HTMLPrint($val);
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(@)
{
for my $output (@_)
{
Print $::Server->HTMLEncode($output);
}
}
# end sub HTMLPrint
=head2 wprint LIST
Deprecated - use C instead.
=cut
# WNO: Consider changing the wprint-to-Print calling method, similar to
# the param-to-GetFormValue change.
sub wprint(@)
{
Print @_;
}
# end sub wprint
=head2 die LIST
Outputs the contents of LIST to the browser and then exits. C automatically
calls C<< $Response->End >> and executes any cleanup code added with
C.
=cut
sub die(@)
{
Print @_;
Print "