ASP
view release on metacpan or search on metacpan
=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");
%>
<SCRIPT language=VBScript runat=server>
Function SomeSub (str)
SomeSub = SomethingThatReturnsSomething()
End Function
</SCRIPT>
=head1 USE
=head2 use ASP qw(:basic);
Exports basic subs: Print, Warn, die, exit, param, param_count. Same
as C<use ASP;>
=head2 use ASP qw(:strict);
Allows the use of the ASP objects under C<use strict;>.
NOTE: This is not the only way to accomplish this, but I think it's
the cleanest, most convenient way.
=head2 use ASP qw(:all);
Exports all subs except those marked 'not exported'.
=head2 use ASP ();
Overloads print() and warn() and provides the $ASP::ASPOUT object.
=head1 FUNCTION REFERENCE
=head2 warn LIST
C<warn> (or more specifically, the __WARN__ signal) has been re-routed to
output to the browser.
FYI: When implemented, this tweak led to the removal of the prototypes
Matt placed on his subs.
=head2 Warn LIST
C<Warn> is an alias for the ASP::Print method described below. The
overloading of C<warn> as described above does not currently work
in Apache::ASP, so this is provided.
=cut
sub Warn { ASP::Print(@_); }
=head2 print LIST
C<print> is overloaded to write to the browser by default. The inherent
behavior of print has not been altered and you can still use an alternate
filehandle as you normally would. This allows you to use print just
as you would in CGI scripts. The following statement would need no
modification between CGI and ASP PerlScript:
print param('URL'), " was requested by ", $ENV{REMOTE_HOST}, "\n";
=head2 Print LIST
Prints a string or comma separated list of strings to the browser. Use
as if you were using C<print> in a CGI application. Print gets around ASP's
limitations of 128k in a single $Response->Write() call.
NB: C<print> calls Print, so you could use either, but
print more closely resembles perl.
=cut
sub Print {
for (@_) {
if ( length($_) > 128000 ) {
ASP::Print( unpack('a128000a*', $_) );
} else {
$main::Response->Write($_);
}
}
}
=head2 DebugPrint LIST
Output is displayed between HTML comments so the output doesn't
interfere with page aesthetics.
=cut
sub DebugPrint { ASP::Print("<!--\n", @_, "\n-->"); }
=head2 HTMLPrint LIST
The same as C<Print> except the output is HTML-encoded so that
any HTML tags appear as sent, i.e. E<lt> becomes <, E<gt> becomes > etc.
=cut
sub HTMLPrint { map { ASP::Print($main::Server->HTMLEncode($_)) } @_ ; }
=head2 die LIST
Prints the contents of LIST to the browser and then exits. die
my($time) = @_;
my(%mult) = ('s'=>1,
'm'=>60,
'h'=>60*60,
'd'=>60*60*24,
'M'=>60*60*24*30,
'y'=>60*60*24*365);
# format for time can be in any of the forms...
# "now" -- expire immediately
# "+180s" -- in 180 seconds
# "+2m" -- in 2 minutes
# "+12h" -- in 12 hours
# "+1d" -- in 1 day
# "+3M" -- in 3 months
# "+2y" -- in 2 years
# "-3m" -- 3 minutes ago(!)
# If you don't supply one of these forms, we assume you are
# specifying the date yourself
my $offset;
if ( !$time || $time eq 'now' ) {
$offset = 0;
} elsif ( $time =~ /^([+-]?\d+)([mhdMy]?)/ ) {
$offset = ($mult{$2} || 1)*$1;
} else {
return $time;
}
return ($time + $offset);
}
=head1 AUTHOR
Tim Hammerquist E<lt>F<tim@dichosoft.com>E<gt>
=head1 HISTORY
=over 4
=item Version 1.07
Added Warn() because warn() overloading doesn't appear to work
under Apache::ASP.
Was forced to clear @DeathHooks array after calling _END() because
of the persistent state of Apache::ASP holding over contents across
executions.
Removed BinaryWrite(), SetCookie(), and Autoload functionality.
=item Version 1.00
The escapeHTML() and unescapeHTML() functions now accept array refs as well
as lists, as Win32::ASP::HTMLEncode() was supposed to.
Thanks to Matt Sergeant for the fix.
=item Version 0.97
Optimized and debugged.
=item Version 0.77
Overloaded warn() and subsequently removed prototypes.
Exported $ScriptingNamespace object.
Added methods escape(), unescape(), escapeHTML(), unescapeHTML().
Thanks to Bill Odom for pointing these out!
Re-implemented SetCookie and BinaryWrite functions.
=item Version 0.11
Optimized and debugged.
=back
=head1 SEE ALSO
ASP::NextLink(3)
=cut
1;
__END__
( run in 1.161 second using v1.01-cache-2.11-cpan-2398b32b56e )