PET::Dispatcher

Summary
PET::Dispatcher
Variables
$BASEPATHBase directory to this PET installation.
$DOCROOT
$TEMPLATETemplate handling Object (of TT2).
$TCONFIGConfig for Template.pm’s “new” method.
$GCONFThe (default) values for global.conf
$GCONF_LASTMODBroken, but this shall hold the last modification time of global.conf
$SESSIONSession object (if any).
$DEBUGDebug mode (broken!)
$UTILHoldig Util instances, e.g.
$UtilWe use this for Template.pm.
$MAPPERFIXME, this is not (yet) working.
$PAGECONFper-page config data
$LOGPET::Log objektum.
%VOLATILEFor caching data in-memory (refreshing automatically).
%BM
$MODEIn which mode are we currently running (e.g.
$CACHEIf we hace a cache set up.
$CCTRLCache-control object init-ed once only.
$IFPROFIf profiling is switched in.
%FILTERSFilters objects are stored here.
%FilterFilters that have short names are stored here.
$PETEXT
Functions
newConstructor method.
_initInits some default stuff.
_fetchGlobals
_globalPostprocess
_initAPIInstanteniates the chosen (global.conf) actionmapper.
_fileUnchanged
_start
_getQuery ()
_fillQuery
setHeader(%p)Sets header(s).
addHeader(%p)Adds header to output HTTP header.
self_url (%p)Calls the same method of CGI::Simple if ‘full’ is given, otherwise uses REQUEST_URI (default).
setRC
setContentType
setAttr
getAttr
doRequest
compilePetAndRun
logPerf
preprocessTemplate ($filename)We run the template preprocess phase here.
getDefaultSubsts
_startCookie
getCookie
cookieOnce ($key)Set a cookie.
setCookie (%p)A method to create (and “emit’) a cookie.
deleteCookieDeletes the name cookie.
_initcache ()If there is a cache/class, then we init it!
apck ($select, $pagekey)Auto Page Cache Key.
toCache
fromCache
getRealUrl
getGconf
getConf ($path)Get a config value from global.conf.
setConf
_getLastMod()Returns the “last modification time” (mtime) of the given file.
getSession()Shortcut to return a given Session value (if sessions are enabled).
setSession()Shortcut to access the setter method of the implementing Session object.
getSessionId
invalidateSession
getSessionObjectReturns the Session object, if any.
getBASEPATH()This is an accessor, that returns the $BASEPATH value.
getLog()This is an accessor, that returns the $LOG value, which is a PET::Log
*getUtil*Returns the already instanteniated PET::Dispatcher object.
getUtil
getUtilHash
getPageKey()Returns the current key for this page (generated from the URL).
reloadModule(Re)loads a (Perl) module using “require”.
getCACHE
get500
skipOn ($string)Cache-control, skipon tag.
servePetAdmin ()

Variables

$BASEPATH

my $BASEPATH

Base directory to this PET installation.

$DOCROOT

my $DOCROOT
DOCUMENT_ROOT (of the VirtualHostshould be $BASEPATH.”/html’;

$TEMPLATE

my $TEMPLATE

Template handling Object (of TT2).

$TCONFIG

my $TCONFIG

Config for Template.pm’s “new” method.

$GCONF

my $GCONF

The (default) values for global.conf

$GCONF_LASTMOD

my $GCONF_LASTMOD

Broken, but this shall hold the last modification time of global.conf

$SESSION

my $SESSION

Session object (if any).

$DEBUG

our $DEBUG

Debug mode (broken!)

$UTIL

our $UTIL

Holdig Util instances, e.g.  $DISP::UTIL::mysql->selectrow(); We use fully qualified names here...

$Util

my $Util

We use this for Template.pm.

$MAPPER

our $MAPPER

FIXME, this is not (yet) working.  Should map URI-s to ACTION-s.

$PAGECONF

our $PAGECONF

per-page config data

$LOG

my $LOG

PET::Log objektum.

%VOLATILE

our %VOLATILE

For caching data in-memory (refreshing automatically).

%BM

our %BM

$MODE

our $MODE

In which mode are we currently running (e.g.  ‘CRON’, ‘FastCGI’)

$CACHE

our $CACHE

If we hace a cache set up.

$CCTRL

our $CCTRL

Cache-control object init-ed once only.

$IFPROF

my $IFPROF

If profiling is switched in.

%FILTERS

my %FILTERS

Filters objects are stored here.

%Filter

my %Filter

Filters that have short names are stored here.

$PETEXT

my $PETEXT

Functions

new

sub new

Constructor method.

Parameters: %p, which currently only holds ‘basedir’.  Calls _init, and sets $BASEPATH.

_init

sub _init

Inits some default stuff.  Actually lots of default stuff... very expensive, only called at init time.  This: set $DOCROOT, calls _fetchGlobals, sets <$FILTERS>, creates $TEMPLATE, creates $UTIL, creates $SESSION, calls <_startCache>, and inits the API (if any)

_fetchGlobals

sub _fetchGlobals

_globalPostprocess

sub _globalPostprocess

_initAPI

sub _initAPI

Instanteniates the chosen (global.conf) actionmapper.  This mapper in turn inits the API (calls the mapper’s “init” method).

_fileUnchanged

sub _fileUnchanged

_start

sub _start

_getQuery ()

_fillQuery

sub _fillQuery

setHeader(%p)

sub setHeader

Sets header(s).  Overrides key with value if already present.

addHeader(%p)

sub addHeader

Adds header to output HTTP header.  Makes scalar => array if multiple values should be set (e.g. for cookies).

self_url (%p)

sub self_url

Calls the same method of CGI::Simple if ‘full’ is given, otherwise uses REQUEST_URI (default).  If ‘encode’ is true, then makes it URLEncode-d.

setRC

sub setRC

setContentType

sub setContentType

setAttr

sub setAttr

getAttr

sub getAttr

doRequest

sub doRequest

compilePetAndRun

sub compilePetAndRun

logPerf

sub logPerf

preprocessTemplate ($filename)

sub preprocessTemplate

We run the template preprocess phase here. general/template/filters stores the list of modules (defined by their name) here.  They are initied at _init().  The order is important!  We check for .pet chanes -- if they change, we re-run the filter, otherwise they are considered unchanged.

Returns: a filename (name of the new, generated file).

This mechanism is used to change .pet files “on the fly”.  This is used for example by multilingual modules to generate the localized version of the given template.

getDefaultSubsts

sub getDefaultSubsts

_startCookie

sub _startCookie

getCookie

sub getCookie

cookieOnce ($key)

sub cookieOnce

Set a cookie.  Returns 1 if it was already set.  Should move this to something like UTIL::HTML or something.

setCookie (%p)

sub setCookie

A method to create (and “emit’) a cookie.  Often called from external modules, or from the template directly.  Uses CGI::Simple::Cookie almost directly, so most parameters are identical to the parameters passed to the new() method of the above module.

The cookie string is added to the headers, and are set when the page is emitted (even if it is a redirect).

Mandatory parameters

namename of the cookie
key [DEPRECATED!]or-ed with “name”
valuevalue to set (can be a hashref or a string!)

Optional parameters

domaindomain of the cookie
expiresexpiration (see CGI::Simple::Cookie for syntax!)  FIXME: Path should be set, too...

Note that we do not do any real syntax/semantic checking here.

deleteCookie

sub deleteCookie

Deletes the name cookie.

_initcache ()

sub _initcache

If there is a cache/class, then we init it!

apck ($select, $pagekey)

sub apck

Auto Page Cache Key.  See documentation for explanation!

toCache

sub toCache

fromCache

sub fromCache

getRealUrl

sub getRealUrl

getGconf

sub getGconf

getConf ($path)

sub getConf

Get a config value from global.conf.  The <pages> part overrides all default settings!  (FIXME) This is always a VALUE, never a NODE, as NODE-s are not MERGE-d!!!!

setConf

sub setConf

_getLastMod()

sub _getLastMod

Returns the “last modification time” (mtime) of the given file.  Returns undef if there is no such file...

getSession()

sub getSession

Shortcut to return a given Session value (if sessions are enabled).  This just calls the Session object (set in global.conf).

setSession()

sub setSession

Shortcut to access the setter method of the implementing Session object.

getSessionId

sub getSessionId

invalidateSession

sub invalidateSession

getSessionObject

sub getSessionObject

Returns the Session object, if any.

getBASEPATH()

sub getBASEPATH

This is an accessor, that returns the $BASEPATH value.

getLog()

sub getLog

This is an accessor, that returns the $LOG value, which is a PET::Log

*getUtil*

Returns the already instanteniated PET::Dispatcher object.

getUtil

sub getUtil

getUtilHash

sub getUtilHash

getPageKey()

sub getPageKey

Returns the current key for this page (generated from the URL).  This is something like “index” or “foo/bar”.

reloadModule

sub reloadModule

(Re)loads a (Perl) module using “require”.

We use this to load modules at runtime (so BEGIN blocks are not run).  The module name is passed as a string.  When in debug mode, reloadModule actually reloads the named module (first deleting it from %INC).  Returns: 1 -> (re)loaded, 0 -> already loaded, -1 -> compilation error Compilation error is only logged at the error_log.  The return value basically shows if we have to re-init the module or not.

getCACHE

sub getCACHE

get500

sub get500

skipOn ($string)

sub skipOn

Cache-control, skipon tag.  This string is used to determine if we should skip caching for the named page.  E.g. a main page of a site is cached, except for when a “login” button is pressed.  The format is: “$key.$subkey”, e.g.  ‘form.login’ FIXME : this should DWIM, now it is rather plain...

servePetAdmin ()

sub servePetAdmin
my $BASEPATH
Base directory to this PET installation.
my $DOCROOT
my $TEMPLATE
Template handling Object (of TT2).
my $TCONFIG
Config for Template.pm’s “new” method.
my $GCONF
The (default) values for global.conf
my $GCONF_LASTMOD
Broken, but this shall hold the last modification time of global.conf
my $SESSION
Session object (if any).
our $DEBUG
Debug mode (broken!)
our $UTIL
Holdig Util instances, e.g.
my $Util
We use this for Template.pm.
our $MAPPER
FIXME, this is not (yet) working.
our $PAGECONF
per-page config data
my $LOG
PET::Log objektum.
our %VOLATILE
For caching data in-memory (refreshing automatically).
our %BM
our $MODE
In which mode are we currently running (e.g.
our $CACHE
If we hace a cache set up.
our $CCTRL
Cache-control object init-ed once only.
my $IFPROF
If profiling is switched in.
my %FILTERS
Filters objects are stored here.
my %Filter
Filters that have short names are stored here.
my $PETEXT
sub new
Constructor method.
sub _init
Inits some default stuff.
sub _fetchGlobals
sub _globalPostprocess
sub _initAPI
Instanteniates the chosen (global.conf) actionmapper.
sub _fileUnchanged
sub _start
sub _fillQuery
sub setHeader
Sets header(s).
sub addHeader
Adds header to output HTTP header.
sub self_url
Calls the same method of CGI::Simple if ‘full’ is given, otherwise uses REQUEST_URI (default).
sub setRC
sub setContentType
sub setAttr
sub getAttr
sub doRequest
sub compilePetAndRun
sub logPerf
sub preprocessTemplate
We run the template preprocess phase here.
sub getDefaultSubsts
sub _startCookie
sub getCookie
sub cookieOnce
Set a cookie.
sub setCookie
A method to create (and “emit’) a cookie.
sub deleteCookie
Deletes the name cookie.
sub _initcache
If there is a cache/class, then we init it!
sub apck
Auto Page Cache Key.
sub toCache
sub fromCache
sub getRealUrl
sub getGconf
sub getConf
Get a config value from global.conf.
sub setConf
sub _getLastMod
Returns the “last modification time” (mtime) of the given file.
sub getSession
Shortcut to return a given Session value (if sessions are enabled).
sub setSession
Shortcut to access the setter method of the implementing Session object.
sub getSessionId
sub invalidateSession
sub getSessionObject
Returns the Session object, if any.
sub getBASEPATH
This is an accessor, that returns the $BASEPATH value.
sub getLog
This is an accessor, that returns the $LOG value, which is a PET::Log
sub getUtil
sub getUtilHash
sub getPageKey
Returns the current key for this page (generated from the URL).
sub reloadModule
(Re)loads a (Perl) module using “require”.
sub getCACHE
sub get500
sub skipOn
Cache-control, skipon tag.
sub servePetAdmin
Close