]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/View/TT.pm
Remove dependency on Apache.
[maypole.git] / lib / Maypole / View / TT.pm
index babd0f457a9260735ccd438eb88c5b2ce2c00837..bdcebb2fee120f62e7ac46f31efd5f89847f75d3 100644 (file)
@@ -1,5 +1,4 @@
-package Apache::MVC::View::TT;
-use Apache::Constants;
+package Maypole::View::TT;
 use Lingua::EN::Inflect;
 use Template;
 use File::Spec;
@@ -11,8 +10,8 @@ sub new { bless {}, shift } # Not worth having
 
 sub _tt {
     my ($self, $r) = @_;
-    my $root = $r->{ar}->document_root . "/". $r->{ar}->location;
-    warn "Root was $root";
+    # This bit sucks.
+    my $root = $r->{config}{template_root} || $r->get_template_root;
     Template->new({ INCLUDE_PATH => [
         $root,
         ($r->model_class && File::Spec->catdir($root, $r->model_class->moniker)),
@@ -34,7 +33,7 @@ sub _args {
     if ($class) { 
         $args{classmetadata} = {
             name => $class,
-            columns => [ $class->columns ],
+            columns => [ $class->display_columns ],
             colnames => { $class->column_names },
             related_accessors => [ $class->related($r) ],
             moniker => $class->moniker,
@@ -47,7 +46,7 @@ sub _args {
         if (@{$r->objects || []} > 1) { 
             $args{$r->model_class->plural_moniker} = $r->objects;
         } else {
-            ($args{$r->model_class->moniker}) = @{$r->objects};
+            ($args{$r->model_class->moniker}) = @{$r->objects ||[]};
         }
     }
 
@@ -63,19 +62,18 @@ sub process {
     $template->process($r->template, { $self->_args($r) }, \$output)
     || return $self->error($r, $template->error);
 
-    $r->{ar}->content_type("text/html");
-    $r->{ar}->headers_out->set("Content-Length" => length $output);
-    $r->{ar}->send_http_header;
-    $r->{ar}->print($output);
+    $r->{content_type} ||= "text/html";
+    $r->{output} = $output;
     return 200;
 }
 
 sub error {
     my ($self, $r, $error) = @_;
     warn $error;
-    if ($error =~ /not found$/) { return DECLINED }
-    $r->{ar}->send_http_header("text/plain");
-    $r->{ar}->print($error);
+    if ($error =~ /not found$/) { return -1 }
+    $r->{content_type} = "text/plain";
+    $r->{output} = $error;
+    $r->send_output;
     exit;
 }