Puma::ServerPages
O b j e c t s
SourceForge.net Logo

GLOBAL OBJECTS
There are two objects that are imported by default into the Puma::ServerPages environment: %ENV and $server.
The %ENV object is a hash table of environment variables that is a standard part of Perl with added values from Apache and Puma::ServerPages. If you want to see the content if this hash, look at it using Data::Dumper.
The $server object is an instantiation of the Puma::ServerPages::Server module. It provides functionality similar to the CGI object. The $server object provides a number of functions for cookie and stateful object management (which we won't cover here) and a number of other useful methods:
  • param() and paramHash() - returns the parameters passed to the page via a form or querystring. The param() method has the same syntax as the CGI->param() method (it's just a pass through) and paramHash() takes no input parameters and returns a hash of all form/querystring keys and values.
  • header() - prints the HTTP header. This method is almost the same as the CGI->header() method except that it handles programmatic redirects much better (an advantage that comes as a result of output buffering!)
  • redirect(URL) - used for redirecting to another page without sending any output to the browser.
  • cwd() - returns the current working directory relative to the filesystem root (not the web root)
  • getConfig() - returns a hash of configuration information gleaned from Puma's configuration files (the global config.xml and local .config.xml files)
  • cgi() - returns the $server's CGI object
STATEFUL OBJECTS
Puma has full support for stateful objects, and they're all configured dynamically to boot.
By default, the /etc/puma/config.xml has two stateful objects defined: the $session and the $user objects. The $session object lives for the length of the browser session and the $user object lives for 30 days. Both are serialized in the $ENV{DOCUMENT_ROOT}/state directory.
All of these parameters are configurable in the global config.xml.
Using the $session and $user objects is a simple task - they're just hash references that will hold their values between pages.