PET::ActionMapper

Class to map URI-s to ACTION-s.  That is: the URI of the incoming (HTTP) requests are mapped to Perl object method calls.  For example, you can map http://youriste.com/foobar.pet to YourClass->ACTION_foobar()

This is the base class, it cannot be used directly: real mapping is done by subclasses, e.g.  PET::ActionMapper::Subdir.

The main config file defines which ActionMapper is used by the site at “actionmapper/class”.  An instance of the named actionmapper is created at init time when the PET application is started, and the “init” method is called.  The “call” method is called subsequently when there is an incoming request.

Subclasses should override the resolveCall method, which does the real mapping.

This class also does the creation of objects from you API(s).

By default, there is no actionmapping -- your .pet files are processed as “simple” TT templates.

This assumes that you have your own modules (API-s) in $BASEDIR/modules.  This cannot be overriden.

Summary
PET::ActionMapperClass to map URI-s to ACTION-s.
Variables
$DISPAn instance of PET::Dispatcher.
$LOGAn instance of PET::Logger.
$modulesdirSet at init time, stores “$BASEPATH/modules” for later usage (module repository).
%APISTOREWe store instanteniated api objects here.
Functions
new ($class)Instanteniate class.
init ($disp)Inits class.
call ($uri)$uri -- the REQUEST_URI
resolveCall ($uri)This method does the real URI-to-method mapping.

Variables

$DISP

my $DISP

An instance of PET::Dispatcher.

$LOG

my $LOG

An instance of PET::Logger.

$modulesdir

our $modulesdir

Set at init time, stores “$BASEPATH/modules” for later usage (module repository).

%APISTORE

our %APISTORE

We store instanteniated api objects here.  (In some cases only one, but that depends on the dispatcher.)

Functions

new ($class)

sub new

Instanteniate class.  We don’t do anything here -- init is called externally.

init ($disp)

sub init

Inits class.  Sets $DISP, $LOG and $modulesdir.

Parameters

$disp -- a PET::Dispatcher instance

Returns: -

call ($uri)

sub call

Parameters

$uri -- the REQUEST_URI

Returns

{ ‘subst’ => \%hash | $string, ‘gsubst’ => { ...}  }

Called by PET::Dispatcher when there is an incoming request.

This method also does the following

  • instanteniates, initiates and stores user API-s (which it gets from the “resolveCall” calls)
  • reloads modules on-demand (this is set by a config parameter “reloadmodules = On|Off”)
  • calls “getGlobalSubst”, “addGlobalSubst” and “start” methods of the user API(s)

resolveCall ($uri)

sub resolveCall

This method does the real URI-to-method mapping.

Parameter

$uri

Returns

($class, $method)

This is an abstract method.  Children must implement it, otherwise it croaks!

This shall give back something like “YourClass::API”, “methodname”.

The simplest PET::ActionMapper subclass.
This is a subclass of PET::ActionMapper, which implement URI mappings in a way that each slash (/) in the URI is mapperd to a package separator (::).
my $DISP
An instance of PET::Dispatcher.
my $LOG
An instance of PET::Logger.
our $modulesdir
Set at init time, stores “$BASEPATH/modules” for later usage (module repository).
our %APISTORE
We store instanteniated api objects here.
sub new
Instanteniate class.
sub init
Inits class.
sub call
$uri -- the REQUEST_URI
sub resolveCall
This method does the real URI-to-method mapping.
Close