Why not adopt me?
NAME
Win32::ASP::CGI - A module for Classic ASP (PerlScript) Programming
SYNOPSIS
<% @Language=PerlScript%>
<%
use Win32::ASP::CGI;
my $r = Win32::ASP::CGI->new;
$r->header(
-type => 'text/xml',
-charset => 'utf8',
'-Content-Length' => 1200,
);
my $test = $r->param('test');
my @select = $r->param('fruits');
$r->print("Hello from Win32::ASP::CGI!");
%>
<% print "A bare print is also OK" %>
DESCRIPTION
This module is somewhat a re-write of Win32::ASP. The main purpose of this module is to provide an OO plug for abstract Request classes which are mostly implemented to support only CGI
and mod_perl
(and fastcgi). Win32::ASP::CGI
supplies a CGI.pm like interface for ASP programming.
This module may or may not be compatible with Win32::ASP. Staying compatible with Win32::ASP is not intended.
METHODS
env
Wrapper around $Request->ServerVariables
:
my $qs = $r->env('QUERY_STRING');
redirect URL
Redirects to the supplied URL.
charset
Set/Get the current charset.
url
self_url
See the "CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION" section in CGI.
FETCHING ENVIRONMENT VARIABLES
Some of the more useful environment variables can be fetched through this interface. See CGI for more information on these methods. The methods are as follows:
query_string
server_port
server_protocol
request_method
content_type
path_translated
request_uri
remote_addr
remote_host
server_software
server_name
remote_ident
remote_user
auth_type
user_name
referer
virtual_port
virtual_host
user_agent
Accept
http
https
path_info
script_name
Function Reference
Overloaded built-ins
print LIST
Outputs a string or comma-separated list of strings to the browser. Use as if you were using print
in a CGI application. print
handles the ASP limitation of 128K per $Response->Write
call.
die LIST
Outputs the contents of LIST to the browser and then exits. die
automatically calls $Response->End
and executes any cleanup code added with AddDeathHook
.
exit
Exits the current script. exit
automatically calls $Response->End
and executes any cleanup code added with AddDeathHook
.
Web I/O Functions
param [NAME [, INDEX]]
Returns the value passed from a form (or non-form GET request). Use this method if you want to be able to develop in GET mode (for ease of debugging) and move to POST mode for release. The second (optional) parameter is for getting multiple parameters, as in
http://localhost/scripts/test.asp?Q=a&Q=b
In the above, param("Q", 1)
returns "a" and param("Q", 2)
returns "b".
param
will work in an array context too, returning all the values for a particular parameter. For example, with the above URL:
my @AllQs = param('Q');
will result in the array @AllQs
containing ('a', 'b')
.
If you call param
without any parameters, it will return a list of form parameters in the same way that CGI.pm's param
function does. This allows easy iteration over the form elements:
foreach my $key (param()) {
print "$key = ", param($key), "<br>\n";
}
cookie [NAME [, VALUE [, HASH ] ] ]
This function tries to act like CGI::param
. It has two modes: read & write.
If called with no parameters, returns the names of the available cookies.
If called with a single parameter, then, it will be recognized as cookie NAME
and the value of the related cookie will be returned.
If called with two or more parameters, then it will write the cookie named NAME
with value VALUE
to the client. The optional HASH is used for write mode and can contain any of the following parameters:
-expires => A CGI.pm style expires value (see the CGI.pm header() documentation).
-domain => a domain in the style ".matt.com" that the cookie is returned to.
-path => a path that the cookie is returned to.
-secure => cookie only gets returned under SSL if this is true.
-httponly => cookie will have a HttpOnly flag if this is true.
count EXPR
Returns the number of times EXPR appears in the request (Form or QueryString). Use this value as $i
to iterate over param(EXPR, $i)
.
For example, if the URL is:
http://localhost/scripts/myscript.asp?Q=a&Q=b
And code is:
my $numQs = count('Q');
Then $numQs
will equal 2.
bprint
Alias for "BinaryWrite".
Utility functions
The following are ported from Win32::ASP.
AddDeathHook LIST
This frightening-sounding function allows you to have cleanup code executed when you die
or exit
. For example, you may want to disconnect from your database if there is a problem:
<%
my $Conn = $Server->CreateObject('ADODB.Connection');
$Conn->Open( "DSN=BADEV1;UID=sa;DATABASE=ProjAlloc" );
$Conn->BeginTrans();
Win32::ASP::AddDeathHook( sub { $Conn->Close if $Conn; } );
%>
Now when you die
because of an error, your database connection will close gracefully, instead of you having loads of rogue connections that you have to kill by hand, or restart your database once a day.
Death hooks are not executed upon the normal termination of the script, so if you have processing that should occur upon a normal exit, be sure to execute it directly.
BinaryWrite LIST
Performs the same function as $Response->BinaryWrite
, but handles Perl's Unicode-related null padding. This function is not exported, so call it as
Win32::ASP::BinaryWrite($val);
Also available as bprint
AUTHOR
Burak Gürsoy <burak@cpan.org>.
COPYRIGHT
This module includes modified code portions from CGI.pm distribution.
CGI.pm Copyright 1995-1998 Lincoln D. Stein. All rights reserved.
http://stein.cshl.org/WWW/software/CGI/
This module includes modified code portions from Win32::ASP
Win32::ASP Copyright 1998 Matt Sergeant. All rights reserved.
Win32::ASP Authors:
Matt Sergeant (through 2.12)
Bill Odom (2.15 and later)
Win32::ASP::CGI Copyright (c) 2008 Burak Gürsoy. All rights reserved.
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.