Using pike scripts
A Pike script is essentially a Pike file containing at least a
parse(). The first time a Pike script is requested
Challenger will compile it and call its parse() method.
Subsequent requests will just have to call the parse()
method of the already loaded script.
Pike scripts are reloaded by requesting it with the pragma no-cache
header. This is usually achieved by pressing reload, or shift reload,
in the web browser. The behavior can be changed by the
no_reload() method.
A pike script should usually inherit roxenlib, to get
access to all library methods.
The methods available to a Pike script are:
- string|mapping|object parse( object id )
-
The parse() is called once for each request. It returns
either a string containing RXML code, a response mapping created via
one of the response methods or a file object. The response methods are
documented in the Responses chapter.
The id argument is the id object of the request. The id object is
documented in the Id object chapter.
- int no_reload( object id )
-
The no_reload() is called when the script is invoked
via a pragma no-cache request. The script will only be reloaded if the
no_reload() returns 0. This method exists to ensure
that only the administrator or programmer can reload a script, in case
this is an expensive operation. The usual implementation will check in
the id object for certain conditions when the script should be
reloaded, for example depending on the ip number of the computer the
browser is run on.
Example
inherit "roxenlib";
string parse( object id )
{
return "<html>\n<head>\n"
"<title>Simple Pike Script Example</title>\n"
"</head>\n"
"<body>\n"
"You gave the following index argument: "
"<gtext>\n"
+ html_encode_string( id->variables->index )
+ "</gtext></body></html>";
}
The Example script will return the value of the form variable index,
rendered by the <gtext> tag. Note the call to the
html_encode_string(), this is to prevent anyone from
sending dangerous RXML code in the form variable. It is always
necessary to perform such quoting when handling user input together
with RXML.
|