]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
Re-wrote Manual::Termonology to emphasize that Maypole's model
[maypole.git] / lib / Maypole.pm
index d8e893dadb7693d141eee068e80032a215c69c88..087f2b9daae744671f8cf3af72cd4886531edab8 100644 (file)
@@ -22,7 +22,45 @@ Maypole - MVC web application framework
 
 =head1 SYNOPSIS
 
-See L<Maypole::Application>.
+The 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/;
+    
+    # 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 DESCRIPTION
 
@@ -38,8 +76,8 @@ application. This is the C<BeerDB> package used as an example in the manual.
 
 This needs to first use L<Maypole::Application> which will make your package
 inherit from the appropriate platform driver such as C<Apache::MVC> or
-C<CGI::Maypole>. Then, the driver calls C<setup>.  This sets up the model classes and
-configures your application. The default model class for Maypole uses
+C<CGI::Maypole>. Then, the driver calls C<setup>. This sets up the model classes
+and configures your application. The default model class for Maypole uses
 L<Class::DBI> to map a database to classes, but this can be changed by altering
 configuration (B<before> calling setup.)
 
@@ -161,7 +199,7 @@ __PACKAGE__->mk_classdata($_) for qw( config init_done view_object );
 __PACKAGE__->mk_accessors(
     qw( params query objects model_class template_args output path
         args action template error document_encoding content_type table
-        headers_in headers_out stash session)
+        headers_in headers_out stash session user)
 );
 
 __PACKAGE__->config( Maypole::Config->new() );
@@ -172,7 +210,7 @@ __PACKAGE__->init_done(0);
 
 As a framework, Maypole provides a number of B<hooks> - methods that are
 intended to be overridden. Some of these methods come with useful default
-behaviour, others do nothing by default. Likely hooks include:
+behaviour, others do nothing by default. Hooks include:
 
     Class methods
     -------------
@@ -393,11 +431,13 @@ sub handler : method
     $self->get_request($req);
     $self->parse_location;
     
-    # hook useful for declining static requests e.g. images
+    # hook useful for declining static requests e.g. images, or perhaps for 
+    # sanitizing request parameters
     my $status = $self->start_request_hook;
     return $status unless $status == Maypole::Constants::OK();
     
     $self->session($self->get_session);
+    $self->user($self->get_user);
     
     $status = $self->handler_guts;
     
@@ -652,12 +692,30 @@ sub is_model_applicable
 
 =item get_session
 
+Called immediately after C<start_request_hook()>.
+
+This method should return a session, which will be stored in the request's
+C<session> attribute.
+
 The default method is empty. 
 
 =cut
 
 sub get_session { }
 
+=item get_user
+
+Called immediately after C<get_session>.
+
+This method should return a user, which will be stored in the request's C<user>
+attribute.
+
+The default method is empty.
+
+=cut
+
+sub get_user {}
+
 =item call_authenticate
 
 This method first checks if the relevant model class
@@ -719,6 +777,7 @@ sub call_exception
     return $self->exception($error);
 }
 
+
 =item exception
 
 This method is called if any exceptions are raised during the authentication or
@@ -780,11 +839,11 @@ sub parse_path
     $self->$_(undef) for qw/action table args/;
     
     $self->preprocess_path;
-
     $self->path || $self->path('frontpage');
-    
+
     my @pi = grep {length} split '/', $self->path;
-    
+
+
     $self->table  || $self->table(shift @pi);
     $self->action || $self->action( shift @pi or 'index' );
     $self->args   || $self->args(\@pi);
@@ -1160,7 +1219,7 @@ calls during processing of a request. This is a brief summary:
            |                        |                  |
            |-----+ init             |                  |
            ||<---+                  |                  |
-           ||                       |     new          |     view_object: e.g
+           ||                       |     new          |     view_object: e.g.
            ||---------------------------------------------> Maypole::View::TT
            |                        |                  |          |
            |                        |                  |          |
@@ -1190,6 +1249,9 @@ calls during processing of a request. This is a brief summary:
             |         ||-----+ get_session         |       |         |
             |         |||<---+                     |       |         |
             |         ||                           |       |         |
+            |         ||-----+ get_user            |       |         |
+            |         |||<---+                     |       |         |
+            |         ||                           |       |         |
             |         ||-----+ handler_guts        |       |         |
             |         |||<---+                     |       |         |
             |         |||     class_of($table)     |       |         |
@@ -1205,14 +1267,14 @@ calls during processing of a request. This is a brief summary:
             |         |||                          |       |         |
             |         |||-----+ additional_data    |       |         |
             |         ||||<---+                    |       |         |
-            |         |||             process      |       |   fetch_objects
-            |         |||--------------------------------->||-----+  |
+            |         |||             process      |       |         |
+            |         |||--------------------------------->||  fetch_objects
+            |         |||                          |       ||-----+  |
             |         |||                          |       |||<---+  |
             |         |||                          |       ||        |
             |         |||                          |       ||   $action
             |         |||                          |       ||-----+  |
-            |         |||                          |       |||<---+  |
-            |         |||                          |       |         |
+            |         |||                          |       |||<---+  |            
             |         |||         process          |       |         |
             |         |||------------------------------------------->|| template
             |         |||                          |       |         ||-----+
@@ -1233,7 +1295,7 @@ calls during processing of a request. This is a brief summary:
 
 =head1 SEE ALSO
 
-There's more documentation, examples, and information on our mailing lists
+There's more documentation, examples, and information on our mailing lists
 at the Maypole web site:
 
 L<http://maypole.perl.org/>
@@ -1242,12 +1304,15 @@ L<Maypole::Application>, L<Apache::MVC>, L<CGI::Maypole>.
 
 =head1 AUTHOR
 
-Maypole is currently maintained by Aaron Trevena
+Maypole is currently maintained by Aaron Trevena, David Baird, Dave Howorth and
+Peter Speltz.
 
 =head1 AUTHOR EMERITUS
 
 Simon Cozens, C<simon#cpan.org>
 
+Simon Flack maintained Maypole from 2.05 to 2.09
+
 Sebastian Riedel, C<sri#oook.de> maintained Maypole from 1.99_01 to 2.04
 
 =head1 THANKS TO