]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
changed template path ordering, no longer return empty paths in TT view
[maypole.git] / lib / Maypole.pm
index 0d0250dfcbde82a88953658dab393326a57504dc..5e85cdfe59b45b23e7cf16905b45598a926593ba 100644 (file)
@@ -1,4 +1,5 @@
 package Maypole;
+use Class::C3;
 use base qw(Class::Accessor::Fast Class::Data::Inheritable);
 use UNIVERSAL::require;
 use strict;
@@ -12,7 +13,7 @@ use URI::QueryParam;
 use NEXT;
 use File::MMagic::XS qw(:compat);
 
-our $VERSION = '2.11_pre4';
+our $VERSION = '2.12';
 our $mmagic = File::MMagic::XS->new();
 
 # proposed privacy conventions:
@@ -35,6 +36,9 @@ The canonical example used in the Maypole documentation is the beer database:
     
     # 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;
@@ -62,8 +66,8 @@ The canonical example used in the Maypole documentation is the beer database:
         date => [ qw/date/],
     );
 
-    # set everything up
-    __PACKAGE__->setup("dbi:SQLite:t/beerdb.db");
+    # note : set up model before calling this method
+    BeerDB::Beer->required_columns([qw/name/]); 
 
     1;    
 
@@ -91,7 +95,7 @@ configuration (B<before> calling setup.)
 
 Note that some details in some of these resources may be out of date.
 
-=over 4 
+=over 4
 
 =item The Maypole Manual
 
@@ -120,7 +124,7 @@ may be out of date.
 =item Web applications with Maypole
 
 A tutorial written by Simon Cozens for YAPC::EU 2005 -
-http://www.droogs.org/perl/maypole/maypole-tutorial.pdf [228KB].
+http://www.aarontrevena.co.uk/opensource/maypole/maypole-tutorial.pdf [228KB].
 
 =item A Database-Driven Web Application in 18 Lines of Code
 
@@ -148,7 +152,7 @@ http://www.perl.com/pub/a/2004/04/15/maypole.html
 =item Authentication
 
 Some notes written by Simon Cozens. A little bit out of date, but still 
-very useful: http://www.droogs.org/perl/maypole/authentication.html
+very useful: http://www.aarontrevena.co.uk/opensource/maypole/authentication.html
 
 =item CheatSheet
 
@@ -173,30 +177,6 @@ http://cpanratings.perl.org/dist/Maypole
 
 =back
 
-=head1 DEMOS
-
-A couple of demos are available, sometimes with source code and configs. 
-
-=over 4 
-
-=item http://maypole.perl.org/beerdb/
-
-The standard BeerDB example, using the TT factory templates supplied in the
-distribution.
-
-=item beerdb.riverside-cms.co.uk
-
-The standard BeerDB example, running on Mason, using the factory templates
-supplied in the L<MasonX::Maypole> distribution.
-
-=item beerfb.riverside-cms.co.uk
-
-A demo of L<Maypole::FormBuilder>. This site is running on the set of Mason 
-templates included in the L<Maypole::FormBuilder> distribution. See the 
-synopsis of L<Maypole::Plugin::FormBuilder> for an example driver
-
-=back
-
 =cut
 
 __PACKAGE__->mk_classdata($_) for qw( config init_done view_object model_classes_loaded);
@@ -204,7 +184,7 @@ __PACKAGE__->mk_classdata($_) for qw( config init_done view_object model_classes
 __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 status parent)
+        headers_in headers_out stash status parent build_form_elements)
 );
 
 __PACKAGE__->config( Maypole::Config->new() );
@@ -255,7 +235,7 @@ Some packages respond to higher debug levels, try increasing it to 2 or 3.
 
 =cut
 
-sub debug { 1 }
+sub debug { 0 }
 
 =item config
 
@@ -320,14 +300,10 @@ sub setup_model {
   # among other things, this populates $config->classes
   $config->model->setup_database($config, $class, @_);
 
-  foreach my $subclass ( @{ $config->classes } ) {
-    next if $subclass->isa("Maypole::Model::Base");
-    no strict 'refs';
-    unshift @{ $subclass . "::ISA" }, $config->model;
-  }
+  $config->model->add_model_superclass($config);
 
   # Load custom model code, if it exists - nb this must happen after the
-  # unshift, to allow code attributes to work, but before adopt(),
+  # adding the model superclass, to allow code attributes to work, but before adopt(),
   # in case adopt() calls overridden methods on $subclass
   foreach my $subclass ( @{ $config->classes } ) {
     $class->load_model_subclass($subclass) unless ($class->model_classes_loaded());
@@ -405,13 +381,12 @@ sub new
         config        => $class->config,
     }, $class;
 
-       $self->stash({});
-       $self->params({});
-       $self->query({});
-       $self->template_args({});
-       $self->args([]);
-       $self->objects([]);
-    
+    $self->stash({});
+    $self->params({});
+    $self->query({});
+    $self->template_args({});
+    $self->args([]);
+    $self->objects([]);
     return $self;
 }
 
@@ -501,7 +476,6 @@ sub component {
 
     $self->get_user;
     my $url = URI->new($path);
-    warn "path : $path\n";
     $self->{path} = $url->path;
     $self->parse_path;
     $self->params( $url->query_form_hash );
@@ -561,15 +535,13 @@ sub __call_hook
 This is the main request handling method and calls various methods to handle the
 request/response and defines the workflow within Maypole.
 
-B<Currently undocumented and liable to be refactored without warning>.
-
 =cut
 
 # The root of all evil
 sub handler_guts 
 {
     my ($self) = @_;
-    
+    $self->build_form_elements(1);
     $self->__load_request_model;
 
     my $applicable = $self->is_model_applicable == OK;
@@ -702,6 +674,29 @@ sub __call_process_view {
   return $status;
 }
 
+=item warn
+
+$r->warn('its all gone pete tong');
+
+Warn must be implemented by the backend, i.e. Apache::MVC
+and warn to stderr or appropriate logfile.
+
+You can also over-ride this in your Maypole driver, should you
+want to use something like Log::Log4perl instead.
+
+=cut
+
+sub warn { }
+
+=item build_form_elements
+
+$r->build_form_elements(0);
+
+Specify whether to build HTML form elements and populate
+the cgi element of classmetadata.
+
+=cut
+
 =item get_request
 
 You should only need to define this method if you are writing a new
@@ -819,9 +814,9 @@ sub is_model_applicable {
 
     if (not $ok) 
     {
-        warn "We don't have that table ($table).\n"
+        $self->warn ("We don't have that table ($table).\n"
             . "Available tables are: "
-            . join( ",", keys %$ok_tables )
+            . join( ",", keys %$ok_tables ))
                 if $self->debug and not $ok_tables->{$table};
                 
         return DECLINED;
@@ -831,7 +826,7 @@ sub is_model_applicable {
     my $action = $self->action;
     return OK if $self->model_class->is_public($action);
     
-    warn "The action '$action' is not applicable to the table '$table'"
+    $self->warn("The action '$action' is not applicable to the table '$table'")
          if $self->debug;
     
     return DECLINED;
@@ -994,7 +989,6 @@ sub parse_path
 
     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);
@@ -1175,6 +1169,11 @@ sub object {
 
 Get/set a hash of template variables.
 
+Maypole reserved words for template variables will over-ride values in template_variables.
+
+Reserved words are : r, request, object, objects, base, config and errors, as well as the
+current class or object name.
+
 =item stash
 
 A place to put custom application data. Not used by Maypole itself.