![]() | |||||||||||||||||||
|
OBJECTS
The beauty of the ASP Object Model is that it takes the
burden of CGI and Session Management off the developer,
and puts them in objects accessible from any
ASP script & include. For the perl programmer, treat these objects
as globals accesible from anywhere in your ASP application.
$Session Object
The $Session object keeps track of user + web client state, in
a persistent manner, making it relatively easy to develop web
applications. The $Session state is stored accross HTTP connections,
in database files in the Global directory, and will persist across
server restarts.
$Session->{CodePage}
Not implemented. May never be until someone explains what its
supposed to do.
$Session->{LCID}
Not implemented. May never be until someone explains what its
supposed to do.
$Session->{SessionID}
SessionID property, returns the id for the current session,
which is exchanged between the client and the server as a cookie.
$Session->{Timeout} [= $minutes]
Timeout property, if minutes is being assigned, sets this
default timeout for the user session, else returns
the current session timeout.
$Session->Abandon()
The abandon method times out the session immediately. All Session
data is cleared in the process, just as when any session times out.
$Session->Lock()
API extension. If you are about to use $Session for many consecutive
reads or writes, you can improve performance by explicitly locking
$Session, and then unlocking, like:
$Session->UnLock()
API Extension. Unlocks the $Session explicitly. If you do not call this,
$Session will be unlocked automatically at the end of the
script.
$Response Object
This object manages the output from the ASP Application and the
client web browser. It does not store state information like the
$Session object but does have a wide array of methods to call.
$Response->{Buffer}
Default 1, when TRUE sends output from script to client only at
the end of processing the script. When 0, response is not buffered,
and client is sent output as output is generated by the script.
$Response->{CacheControl}
Default "private", when set to public allows proxy servers to
cache the content. This setting controls the value set
in the HTTP header Cache-Control
$Response->{Charset}
This member when set appends itself to the value of the Content-Length
HTTP header. If $Response->{Charset} = 'ISO-LATIN-1' is set, the
corresponding header would look like:
$Response->{Clean} = 0-9;
API extension. Set the Clean level, default 0, on a per script basis.
Clean of 1-9 compresses text/html output. Please see
the Clean config option for more information.
$Response->{ContentType} = "text/html"
Sets the MIME type for the current response being sent to the client.
Sent as an HTTP header.
$Response->{Expires} = $time
Sends a response header to the client indicating the $time
in SECONDS in which the document should expire. A time of 0 means
immediate expiration. The header generated is a standard
HTTP date like: "Wed, 09 Feb 1994 22:23:32 GMT".
$Response->{ExpiresAbsolute} = $date
Sends a response header to the client with $date being an absolute
time to expire. Formats accepted are all those accepted by
HTTP::Date::str2time(), e.g.
$Response->{IsClientConnected}
Not implemented, but returns 1 currently for portability. This is
value is not yet relevant, and may not be until apache 1.3.6, which will
be tested shortly. Apache versions less than 1.3.6 abort the perl code
immediately upon the client dropping the connection.
$Response->{PICS}
If this property has been set, a PICS-Label HTTP header will be
sent with its value. For those that do not know, PICS is a header
that is useful in rating the internet. It stands for
Platform for Internet Content Selection, and you can find more
info about it at: http://www.w3.org
$Response->{Status} = $status
Sets the status code returned by the server. Can be used to
set messages like 500, internal server error
$Response->AddHeader($name, $value)
Adds a custom header to a web page. Headers are sent only before any
text from the main page is sent, so if you want to set a header
after some text on a page, you must turn BufferingOn.
$Response->AppendToLog($message)
Adds $message to the server log. Useful for debugging.
$Response->BinaryWrite($data)
Writes binary data to the client. The only
difference from $Response->Write() is that $Response->Flush()
is called internally first, so the data cannot be parsed
as an html header. Flushing flushes the header if has not
already been written.
$Response->Clear()
Erases buffered ASP output.
$Response->Cookies($name, [$key,] $value)
Sets the key or attribute of cookie with name $name to the value $value.
If $key is not defined, the Value of the cookie is set.
ASP CookiePath is assumed to be / in these examples.
$Response->Debug(@args)
API Extension. If the Debug config option is set greater than 0,
this routine will write @args out to server error log. refs in @args
will be expanded one level deep, so data in simple data structures
like one-level hash refs and array refs will be displayed. CODE
refs like
$Response->End()
Sends result to client, and immediately exits script.
Automatically called at end of script, if not already called.
$Response->Flush()
Sends buffered output to client and clears buffer.
$Response->Include($filename, @args)
This API extension calls the routine compiled from asp script
in $filename with the args @args. This is a direct translation
of the SSI tag
$Response->Redirect($url)
Sends the client a command to go to a different url $url.
Script immediately ends.
$Response->Write($data)
Write output to the HTML page. <%=$data%> syntax is shorthand for
a $Response->Write($data). All final output to the client must at
some point go through this method.
$Request Object
The request object manages the input from the client brower, like
posts, query strings, cookies, etc. Normal return results are values
if an index is specified, or a collection / perl hash ref if no index
is specified. WARNING, the latter property is not supported in
Activeware PerlScript, so if you use the hashes returned by such
a technique, it will not be portable.
$Request->{TotalBytes}
The amount of data sent by the client in the body of the
request, usually the length of the form data. This is
the same value as $Request->ServerVariables('CONTENT_LENGTH')
$Request->BinaryRead($length)
Returns a scalar whose contents are the first $length bytes
of the form data, or body, sent by the client request.
This data is the raw data sent by the client, without any
parsing done on it by Apache::ASP.
$Request->ClientCertificate()
Not implemented.
$Request->Cookies($name [,$key])
Returns the value of the Cookie with name $name. If a $key is
specified, then a lookup will be done on the cookie as if it were
a query string. So, a cookie set by:
$Request->Form($name)
Returns the value of the input of name $name used in a form
with POST method. If $name is not specified, returns a ref to
a hash of all the form data.
$Request->QueryString($name)
Returns the value of the input of name $name used in a form
with GET method, or passed by appending a query string to the end of
a url as in http://localhost/?data=value.
If $name is not specified, returns a ref to a hash of all the query
string data.
$Request->ServerVariables($name)
Returns the value of the server variable / environment variable
with name $name. If $name is not specified, returns a ref to
a hash of all the server / environment variables data. The following
would be a common use of this method:
$Application Object
Like the $Session object, you may use the $Application object to
store data across the entire life of the application. Every
page in the ASP application always has access to this object.
So if you wanted to keep track of how many visitors there where
to the application during its lifetime, you might have a line
like this:
$Application->Lock()
Locks the Application object for the life of the script, or until
UnLock() unlocks it, whichever comes first. When $Application
is locked, this gaurantees that data being read and written to it
will not suddenly change on you between the reads and the writes.
$Application->UnLock()
Unlocks the $Application object. If already unlocked, does nothing.
$Application->SessionCount()
This NON-PORTABLE method returns the current number of active sessions,
in the application. This method is not implemented as part of the ASP
object model, but is implemented here because it is useful. In particular,
when accessing databases with license requirements, one can monitor usage
effectively through accessing this value.
$Server Object
The server object is that object that handles everything the other
objects do not. The best part of the server object for Win32 users is
the CreateObject method which allows developers to create instances of
ActiveX components, like the ADO component.
$Server->{ScriptTimeout} = $seconds
Not implemented. May never be. Please see the
Apache Timeout configuration option, normally in httpd.conf.
$Server->CreateObject($program_id)
Allows use of ActiveX objects on Win32. This routine returns
a reference to an Win32::OLE object upon success, and nothing upon
failure. It is through this mechanism that a developer can
utilize ADO. The equivalent syntax in VBScript is
$Server->HTMLEncode($string)
Returns an HTML escapes version of $string. &, ", >, <, are each
escapes with their HTML equivalents. Strings encoded in this nature
should be raw text displayed to an end user, as HTML tags become
escaped with this method. "
$Server->MapPath($url);
Given the url $url, absolute, or relative to the current executing script,
this method returns the equivalent filename that the server would
translate the request to, regardless or whether the request would be valid.
$Server->URLEncode($string)
Returns the URL-escaped version of the string $string. +'s are substituted in
for spaces and special characters are escaped to the ascii equivalents.
Strings encoded in this manner are safe to put in url's... they are especially
useful for encoding data used in a query string as in:
$Server->RegisterCleanup($sub_reference)
|
||||||||||||||||||
Copyright (c) 1998-1999, Joshua Chamas, Chamas Enterprises Inc. |