]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
changed template path ordering a bit more in TT
[maypole.git] / lib / Maypole.pm
index 56c94e3748fb28fa9e92daac0f79c881662287ae..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_pre5';
+our $VERSION = '2.12';
 our $mmagic = File::MMagic::XS->new();
 
 # proposed privacy conventions:
@@ -183,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() );
@@ -299,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());
@@ -384,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;
 }
 
@@ -480,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 );
@@ -540,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;
@@ -681,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
@@ -798,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;
@@ -810,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;
@@ -973,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);