|
NAMEMaypole - MVC web application framework SYNOPSISThe canonical example used in the Maypole documentation is the beer database: package BeerDB;
use strict;
use warnings;
# choose a frontend, initialise the config object, and load a plugin
use Maypole::Application qw/Relationship/;
# set everything up
__PACKAGE__->setup("dbi:SQLite:t/beerdb.db");
# get the empty config object created by Maypole::Application
my $config = __PACKAGE__->config;
# basic settings
$config->uri_base("http://localhost/beerdb");
$config->template_root("/path/to/templates");
$config->rows_per_page(10);
$config->display_tables([qw/beer brewery pub style/]);
# table relationships
$config->relationships([
"a brewery produces beers",
"a style defines beers",
"a pub has beers on handpumps",
]);
# validation
BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
BeerDB::Pub->untaint_columns( printable => [qw/name notes url/] );
BeerDB::Style->untaint_columns( printable => [qw/name notes/] );
BeerDB::Beer->untaint_columns(
printable => [qw/abv name price notes/],
integer => [qw/style brewery score/],
date => [ qw/date/],
);
# note : set up model before calling this method
BeerDB::Beer->required_columns([qw/name/]);
1;
DESCRIPTIONThis documents the Maypole request object. See the Maypole::Manual, for a detailed guide to using Maypole. Maypole is a Perl web application framework similar to Java's struts. It is essentially completely abstracted, and so doesn't know anything about how to talk to the outside world. To use it, you need to create a driver package which represents your entire application. This is the "BeerDB" package used as an example in the manual. This needs to first use Maypole::Application which will make your package inherit from the appropriate platform driver such as "Apache::MVC" or "CGI::Maypole". Then, the driver calls "setup". This sets up the model classes and configures your application. The default model class for Maypole uses Class::DBI to map a database to classes, but this can be changed by altering configuration (before calling setup.) DOCUMENTATION AND SUPPORTNote that some details in some of these resources may be out of date.
HOOKABLE METHODSAs a framework, Maypole provides a number of hooks - methods that are intended to be overridden. Some of these methods come with useful default behaviour, others do nothing by default. Hooks include: Class methods
-------------
debug
setup
setup_model
load_model_subclass
init
Instance methods
----------------
start_request_hook
is_model_applicable
get_session
authenticate
exception
additional_data
preprocess_path
CLASS METHODS
INSTANCE METHODSWorkflow
Path processing and manipulation
Request properties
Request parametersThe source of the parameters may vary depending on the Maypole backend, but they are usually populated from request query string and POST data. Maypole supplies several approaches for accessing the request parameters. Note that the current implementation (via a hashref) of "query" and "params" is likely to change in a future version of Maypole. So avoid direct access to these hashrefs: $r->{params}->{foo} # bad
$r->params->{foo} # better
$r->{query}->{foo} # bad
$r->query->{foo} # better
$r->param('foo') # best
Utility methods
SEQUENCE DIAGRAMSSee Maypole::Manual::Workflow for a detailed discussion of the sequence of calls during processing of a request. This is a brief summary: INITIALIZATION
Model e.g.
BeerDB Maypole::Model::CDBI
| |
setup | |
o-------->|| |
|| setup_model | setup_database() creates
||------+ | a subclass of the Model
|||<----+ | for each table
||| | |
||| setup_database | |
|||--------------------->|| 'create' *
||| ||----------> $subclass
||| | |
||| load_model_subclass | |
foreach |||------+ ($subclass) | |
$subclass ||||<----+ | require |
||||--------------------------------------->|
||| | |
||| adopt($subclass) | |
|||--------------------->|| |
| | |
| | |
|-----+ init | |
||<---+ | |
|| | new | view_object: e.g.
||---------------------------------------------> Maypole::View::TT
| | | |
| | | |
| | | |
| | | |
| | | |
HANDLING A REQUEST
BeerDB Model $subclass view_object
| | | |
handler | | | |
o-------->| new | | |
|-----> r:BeerDB | | |
| | | | |
| | | | |
| || | | |
| ||-----+ parse_location | | |
| |||<---+ | | |
| || | | |
| ||-----+ start_request_hook | | |
| |||<---+ | | |
| || | | |
| ||-----+ get_session | | |
| |||<---+ | | |
| || | | |
| ||-----+ get_user | | |
| |||<---+ | | |
| || | | |
| ||-----+ handler_guts | | |
| |||<---+ | | |
| ||| class_of($table) | | |
| |||------------------------->|| | |
| ||| $subclass || | |
| |||<-------------------------|| | |
| ||| | | |
| |||-----+ is_model_applicable| | |
| ||||<---+ | | |
| ||| | | |
| |||-----+ call_authenticate | | |
| ||||<---+ | | |
| ||| | | |
| |||-----+ additional_data | | |
| ||||<---+ | | |
| ||| process | | |
| |||--------------------------------->|| fetch_objects
| ||| | ||-----+ |
| ||| | |||<---+ |
| ||| | || |
| ||| | || $action
| ||| | ||-----+ |
| ||| | |||<---+ |
| ||| process | | |
| |||------------------------------------------->|| template
| ||| | | ||-----+
| ||| | | |||<---+
| ||| | | |
| || send_output | | |
| ||-----+ | | |
| |||<---+ | | |
$status | || | | |
<------------------|| | | |
| | | | |
| X | | |
| | | |
| | | |
| | | |
SEE ALSOThere's more documentation, examples, and information on our mailing lists at the Maypole web site: <http://maypole.perl.org/> Maypole::Application, Apache::MVC, CGI::Maypole. AUTHORMaypole is currently maintained by Aaron Trevena. AUTHOR EMERITUSSimon Cozens, "simon#cpan.org" Simon Flack maintained Maypole from 2.05 to 2.09 Sebastian Riedel, "sri#oook.de" maintained Maypole from 1.99_01 to 2.04 THANKS TOSebastian Riedel, Danijel Milicevic, Dave Slack, Jesse Sheidlower, Jody Belka, Marcus Ramberg, Mickael Joanne, Randal Schwartz, Simon Flack, Steve Simms, Veljko Vidovic and all the others who've helped. LICENSEYou may distribute this code under the same terms as Perl itself.
|