]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
components now work
[maypole.git] / lib / Maypole.pm
index 858c1eb608aa1dfa264b5e1206dedbad78399e9a..83607c8db34137662cf0694cf8a494179d319d18 100644 (file)
@@ -275,7 +275,7 @@ documentation. However here is the most usage of setup where
 Maypole::Model::CDBI is the base class.
 
  My::App->setup($data_source, $user, $password,
-       {  opitons => {  # These are DB connection options
+       {  options => {  # These are DB connection options
                AutoCommit => 0,
                RaiseError => 1,
                ...
@@ -481,18 +481,24 @@ request. You'll need to set up actions and templates
 which return fragments of HTML rather than entire pages, but once you've
 done that, you can use the C<component> method of the Maypole request object
 to call those actions. You may pass a query string in the usual URL style.
+
 You should not fully qualify the Maypole URLs.
 
+Note: any HTTP POST or URL parameters passed to the parent are not passed to the
+component sub-request, only what is included in the url passed as an argyument
+to the method
+
 =cut
 
 sub component {
     my ( $r, $path ) = @_;
-    my $self = bless { parent => $r }, ref $r;
+    my $self = bless { parent => $r, config => $r->{config}, template_args => {}, }, ref $r;
+    $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 );
-    $self->query( $r->params );
     $self->handler_guts;
     return $self->output;
 }
@@ -562,18 +568,13 @@ sub handler_guts
 
     my $applicable = $self->is_model_applicable == OK;
 
-    warn "applicable : $applicable";
-
-    $self->__setup_plain_template unless $applicable;
-
     my $status;
 
+    # handle authentication
     eval { $status = $self->call_authenticate };
-    
     if ( my $error = $@ ) 
     {
         $status = $self->call_exception($error, "authentication");
-        
         if ( $status != OK ) 
         {
             warn "caught authenticate error: $error";
@@ -581,7 +582,6 @@ sub handler_guts
                     $self->view_object->error($self, $error) : ERROR;
         }
     }
-    
     if ( $self->debug and $status != OK and $status != DECLINED ) 
     {
         $self->view_object->error( $self,
@@ -592,40 +592,32 @@ sub handler_guts
 
     # We run additional_data for every request
     $self->additional_data;
-    
-    if ($applicable) 
-    {
-        eval { $self->model_class->process($self) };
-        
-        if ( my $error = $@ ) 
+
+    if ($applicable) {
+      eval { $self->model_class->process($self) };
+      if ( my $error = $@ ) 
         {
-            $status = $self->call_exception($error, "model");
-            
-            if ( $status != OK ) 
+         $status = $self->call_exception($error, "model");
+         if ( $status != OK )
             {
-                warn "caught model error: $error";
-                return $self->debug ? 
-                    $self->view_object->error($self, $error) : ERROR;
+             warn "caught model error: $error";
+             return $self->debug ? 
+               $self->view_object->error($self, $error) : ERROR;
             }
         }
+    } else {
+      $self->__setup_plain_template;
     }
-    
+
     # less frequent path - perhaps output has been set to an error message
     return OK if $self->output;
-#    warn "output before processing view : ", $self->output;
 
     # normal path - no output has been generated yet
     my $processed_view_ok = $self->__call_process_view;
 
-    warn "output after processing view : ", $self->output;
-
-    warn "error after processing view : ", $self->{error};
-
     $self->{content_type}      ||= $self->__get_mime_type();
     $self->{document_encoding} ||= "utf-8";
 
-    warn "made it to end, processed_view_ok : $processed_view_ok";
 
     return $processed_view_ok;
 }
@@ -663,7 +655,7 @@ sub __load_request_model
 sub __setup_plain_template
 {
     my ($self) = @_;
-    
+
     # It's just a plain template
     $self->model_class(undef);