pscript

perl-based web page scripting language 

Miscellaneous Information


DESCRIPTION

PScript provides the ability to write embedded scripts in web pages using the very popular and powerful perl language. In fact, PScript is perl: the same syntax, the same semantics. The following sections describe how to install and use PScript.

ActiveX and Active Server Pages

ActiveX and Active Server Pages (ASP) represent the two different host environments for embedding scripts in web pages (or HTML documents).

ActiveX refers to pages where the browser parses and runs any scripts contained in that web page. Currently, the only browser which supports ActiveX scripting is Microsoft Internet Explorer (IE). When you install the MKS Toolkit, the PScript DLLs are automatically installed and registered. As a result, if you use the Internet Explorer as your browser, you can immediately download ActiveX web pages with embedded PScript.

Active Server Pages or ASP represent the other side of the equation. These web pages are interpreted by the web server, that is, the site that actually stores the page you are downloading. Currently, only version 3 and later of Microsoft's Internet Information Server (IIS) supports ASP. If you are using IIS version 3+, you can run ASP by installing the ASP package available from Microsoft. Comments on installing the IIS ASP package can be found at the beginning of the regps.ksh file.

Active Server Pages may always be written in any supported scripting language by using the HTML <SCRIPT ...> and </SCRIPT> tags. However, you can gain more flexibility and access to a shorthand syntax by setting a default scripting language. To set Pscript as your default scripting language, run

regps

to set the appropriate registry entries. To set the default language to something else, run

regps lang

where lang can be either VBScript or JScript.

For more information about ASP, consult the Active Server Pages Road Map that was installed with the ASP package.

Embedding PScript in a Web Page

As mentioned earlier, scripts can be embedded in web pages by using the HTML <SCRIPT ...> and </SCRIPT> tags. For ActiveX scripts, the <SCRIPT> tag takes a Language attribute which identifies the scripting language that the browser must use to run that script. The general syntax for running PScript ActiveX scripts is

<SCRIPT Language=PScript>

	script body

</SCRIPT>

The syntax for ASP scripts is similar but you must also specify the Runat=Server attribute to distinguish between ASP scripts and ActiveX scripts. Thus, the general syntax for ASP scripts is

<SCRIPT Language=PScript Runat=Server>

	script body

</SCRIPT>

Scripts may also be associated with events for controls such as buttons by specifying both the Language attribute and an onEvent attribute. For example, to run a perl function when a button is pressed, you could use:

<BUTTON ... onChange="onChangeFunction()" Language=PScript>

The onChangeFunction() function must be specified in another SCRIPT tag.

The script bodies contained by these tags must be complete syntactic units. That is, you cannot specify any incomplete statements, blocks or functions. Scripts of this form may be used with both ActiveX and Active Server Pages.

The other option when using PScript in conjunction with ASP is to set PScript as the default scripting language on your server using the regps script described earlier. With PScript set as the default language, you can use the <%...%> tag to embed perl code in your web page. The following list describes the variations of the <%...%> tag:

<% perl-code %> 

runs the perl code specified by perl-code. perl-code does not need to be a complete script. In fact each line of a script may be individually tagged and HTML tags can be intermixed allowing for examples like this:

<% if ($feeling eq "good") { %>
	<B>Hello world!</B>
<% } else { %>
	<B>Good-bye cruel world!</B>
<% } %>
<%= perl-expr %> 

embeds the result of perl-expr as part of the web page that the server shows to the user. perl-expr can be any valid perl expression. For example, to embed the current date and time, you could use the tag

<%= scalar(localtime) %>
<%@ DefaultLanguage=lang %> 

overrides the registry's DefaultScriptLanguage setting for the current page. lang can be either VBScript or JScript. This must be the first line of the page.

Because the ASP parser ignores white space following <%, you must be careful when using perl arrays if PScript is the default language. The line

<% @array = (one, two, three); %>

is incorrectly interpreted by the ASP parser as a <%@ tag. Instead, you must use

<% ; @array = (one, two, three); %>

Finally, you must be careful if you are trying to "comment out" a PScript script using the HTML <!-- ... --> comment tags. If the enclosed Pscript script contains the perl object deference operator (the ->), the HTML parser misinterprets this operator as the end of comment tag and the rest of the page is not correctly parsed.

Accessing ActiveX Objects

ActiveX objects are groups of methods, properties, and collections that can be accessed by the user of the object. ActiveX objects in PScript are made available as Perl objects implemented via an internal Perl package and their methods, properties, and collections can accessed in the same manner as those of COM objects as described in the perlcom reference page.

You can call the method of an ActiveX object using the following syntax:

$var=$object->method-name(args)

where $object is the name of the object, method-name is the name of the desired method, args is the list of arguments to be passed to the method, and $var is a variable to hold the value returned by the method. Some methods do not take arguments and some do not return values.

You can assign a value to an object's property with the following syntax:

$object->{property-name}=value

where $object is the name of the object,property-name is the name of the desired property, and value is the value to be assigned.

Similarly, you can obtain the value of an object's property with:

$var=$object->{property-name}

where $var is the perl variable in which this value is stored.

Some properties are read-only while others are write-only. Attempting to set a read-only property or read a write-only property generates an error message.

There is also a particular type of property known as a collection. A collection is a set of values associated with a single property. PScript uses a reference to a perl array to represent a collection. You can refer to a specific element of a collection with the following syntax:

$object->{collection-name}->[num}

where $object is the name of the object, collection-name is the name of the collection and num is a number indicating which element of the collection you wish to access.

For example, if $object indicates an object which has a collection named fields as one of its properties, you can access the fifth element of this collection with

$object->{fields}->[5]

Normally, collections have their own properties such as Count and Items; however, these properties are not directly accessible to perl. Instead, you should use the normal perl syntax for accessing elements and for determining the length of an array. You can also use the foreach statement to process all elements of a collection.

ActiveX and ASP both provide a set of predefined objects. The objects for ActiveX are:

Window
Document
Form
Location
Link
Anchor
Element
History
Navigator

The predefined objects for ASP are:

Application
Request
Response
Server
Session

Descriptions of these objects can be found in the Object Reference section of the Active Server Pages Road Map. In addition, other components available to ASP programmers can be found in the Component Reference section of the Road Map.

Samples of both ActiveX and ASP web pages are provided with the other MKS Toolkit examples.

Security Features

The use of ActiveX in conjunction with any scripting language allows the writer of the script to access resources on the client machine. To prevent accidental or malicious destruction of data, certain perl features have been disabled in PScript. The following functions and extensions fail due to a lack of privileges.

Input and output functions:

binmode        close          closedir       dbmclose       dbmopen
die            eof            fileno         flock          readdir
rewinddir      seek           seekdir        select         syscall
sysread        syswrite       tell           telldir        truncate
Functions for filehandles, files, or directories:

chdir          chmod          chown          chroot         fcntl
ioctl          link           lstat          mkdir          open
opendir        readlink       rename         rmdir          stat
symlink        umask          unlink
Functions for processes and process groups:

exec           fork           getpgrp        getppid        getpriority
kill           pipe           qx/STRING/     setpgrp        setpriority
system         wait           waitpid
Low-level socket functions:

accept         bind           connect        getpeername    getsockname
getsockopt     listen         recv           send           setsockopt
shutdown       socket         socketpair
Keywords related to perl modules:

import         no             require        use
System V interprocess communication functions:

msgctl         msgget         msgrcv         msgsnd         semctl
semget         semop          shmctl         shmget         shmread
shmwrite
Fetching user and group info:

endgrent       endhostent     endnetent      endpwent       getgrent
getgrgid       getgrnam       getlogin       getpwent       getpwnam
getpwuid       setgrent       setpwent
Fetching network info:

endprotoent    endservent     gethostbyaddr  gethostbyname  gethostent
getprotoent    getservbyname  getservbyport  getservent     sethostent
setnetent      setprotoent    setservent

AVAILABILITY

MKS Toolkit for Developers
MKS Toolkit for Interoperability
MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
perl

Miscellaneous:
perlcom