docs.roxen.comView this page in a printer friendly mode
DocsRoxenWebServer 5.1System Developer Manual PikeProgramming Languages
Copyright  2013, Roxen Internet Software
Suggestions, comments & compliments

Pike Script
Pike Processing Instruction
Using In-Line Perl Code
Running Perl Scripts
Supported mod_perl API Methods
What is a CGI Script?
CGI Environment Variables
CGI I/O Via Standard Streams

Pike Processing Instruction

How to use the <?pike ... ?> processing instruction.

The <?pike ... ?> processing instruction tag (PI for short) is used to smoothly inline pike code in your pages. The perhaps most usable aspect of this is for quickly throwing together a small webpage application or for experimenting and toying around with the roxen programming environment. Since the code resides in the page, it will not be so reusable a component, as would a Roxen module, but the short cycle time between applying a change and seeing the results right after another page reload make it an ideal development tool.


Three additional methods set the Pike PI tag apart from those present everywhere else within Roxen. These handle the output facilities of the tag:

void write(string fmt, mixed ... args)

Outputs the string to the page. Takes the same arguments as write or sprintf in common pike, but appends the result to the output buffer. If given only one string argument, it is written directly to the output buffer without being interpreted as a format specifier.

string flush()

Returns the contents of the output buffer and resets it. This buffer contains everything written so far via write (or, by inference, the available convenience syntaxes for write) since the start of the processing instruction or the last call to flush().

string rxml(string rxml_code)

Parses the string with the RXML parser, returning the result after parsing.

Special Variables


The RequestID object, bearing all request local state, is available in the 'id' variable.

scopes and entities

All scopes (including _) are accessable directly as variables named after the scope itself; hence _, roxen, form, variables and so on are present for easy reading (and/or tampering :-). Thus roxen.uptime, for instance, is an integer marking the number of seconds since Roxen was started, just as &roxen.uptime; would be in a section of RXML code (these shorthands for RXML.user_get_var and RXML.user_set_var only work for entities in scopes available in the context when the parser encountered the processing instruction).

For meshing pike, RXML code and common HTML, there are other convenience features present, in the form of certain comments treated specially. //O (the letter O) comments are written out directly into the page, and //X comments are parsed as RXML on the spot and written out into the result page. These shorthands are equivalent to the calls write(my_string) and write(rxml(my_string)) respectively.

An example pike processing instruction that shows some server info and toggles the value of a cookie:

  //X <gtext>Server Info</gtext><br />
  write("This is %s running %s, and we've been up for %d seconds.",
  roxen.version, roxen["pike-version"], roxen.uptime);

  //X <br /><gtext>Cookies</gtext><br />
  //X <pre><insert scope='cookie' variables='full' /></pre>
  if(cookie.hi == "Hi!")
    cookie.hi = "Ho!";
    cookie.hi = "Hi!";