From: David Baird Date: Fri, 4 Nov 2005 16:34:55 +0000 (+0000) Subject: Added a canonical BeerDB example to Maypole::Application X-Git-Tag: 2.11~105 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=db03564d2a397a9c092d65fd790ccecde9c55d92;p=maypole.git Added a canonical BeerDB example to Maypole::Application git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@413 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Maypole/Application.pm b/lib/Maypole/Application.pm index 60542f9..38b1ec5 100644 --- a/lib/Maypole/Application.pm +++ b/lib/Maypole/Application.pm @@ -84,8 +84,18 @@ Maypole::Application - Universal Maypole Frontend This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI. -You can omit the Maypole::Plugin:: prefix from plugins. -So Maypole::Plugin::Config::YAML becomes Config::YAML. +Automatically determines the appropriate frontend for your environment (unless +you want to use L, in which case include C in the +arguments). + +Loads plugins supplied in the C statement. + +Responds to flags supplied in the C statement. + +Initializes the application's configuration object. + +You can omit the Maypole::Plugin:: prefix from plugins. So +Maypole::Plugin::Config::YAML becomes Config::YAML. use Maypole::Application qw(Config::YAML); @@ -93,10 +103,23 @@ You can also set special flags like -Setup, -Debug and -Init. use Maypole::Application qw(-Debug Config::YAML -Setup); -The position of plugins and flags in the chain is important, -because they are loaded/executed in the same order they appear. +The position of plugins in the chain is important, because they are +loaded/executed in the same order they appear. + +=head1 FRONTEND + +Under mod_perl (1 or 2), selects L. + +Otherwise, selects L. + +If C is specified, sets L as the frontend. This +currently also requires a mod_perl environment. + +=head1 FLAGS -=head2 -Setup +=over + +=item -Setup use Maypole::Application qw(-Setup); @@ -109,7 +132,7 @@ Note that no options are passed to C. You must ensure that the required model config parameters are set in Cconfig>. See L for more information. -=head2 -Init +=item -Init use Maypole::Application qw(-Setup -Init); @@ -128,7 +151,7 @@ Note that you must supply all the config data to your app before calling C and C, probably by using one of the C plugins. -=head2 -Debug +=item -Debug use Maypole::Application qw(-Debug); @@ -139,6 +162,51 @@ is equivalent to You can specify a higher debug level by saying C<-Debug2> etc. +=back + +=head1 BeerDB + +The canonical example used in the Maypole documentation is the beer database, +which starts like this: + + package BeerDB; + use strict; + use warnings; + + # choose a frontend, initialise the config object, and load a plugin + use Maypole::Application qw/Relationship/; + + # 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/], + ); + + # set everything up + __PACKAGE__->setup("dbi:SQLite:t/beerdb.db"); + + 1; + =head1 AUTHOR Sebastian Riedel, C