From: Simon Cozens Date: Sat, 24 Jan 2004 14:03:57 +0000 (+0000) Subject: Slight refactoring, send out the template output, and provide an error routine. X-Git-Tag: 2.10~356 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=cac38e4a644618bbc965d5349723638df1c2e711;hp=fa685ce517bd35c12ed6681803d9d0d6b1793159;p=maypole.git Slight refactoring, send out the template output, and provide an error routine. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@6 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Apache/MVC/View/TT.pm b/lib/Apache/MVC/View/TT.pm index 5c67d50..30e0f89 100644 --- a/lib/Apache/MVC/View/TT.pm +++ b/lib/Apache/MVC/View/TT.pm @@ -4,19 +4,22 @@ use Template; use File::Spec; use UNIVERSAL::moniker; -sub template_root { "/opt/houseshare/templates" } # For now sub new { bless {}, shift } # Not worth having -sub process { +sub _tt { my ($self, $r) = @_; - my $root = $self->template_root; - my $template = Template->new({ INCLUDE_PATH => [ + my $root = $r->config->{template_root}; + Template->new({ INCLUDE_PATH => [ $root, File::Spec->catdir($root, $r->model_class->moniker), File::Spec->catdir($root, "custom"), File::Spec->catdir($root, "factory") ]}); +} + +sub _args { + my ($self, $r) = @_; my %args = ( request => $r, class => $r->model_class, @@ -30,6 +33,27 @@ sub process { } else { ($args{$r->model_class->moniker}) = @{$r->objects}; } + %args; +} + +sub process { + my ($self, $r) = @_; + my $template = $self->_tt($r): + my $output; + $template->process($r->template, { $self->_args($r) }, \$output); + || $self->error($r, $template->error); + $r->{ar}->content_type("text/html"); + $r->{ar}->headers_out->set("Content-Length" => length $output); + $r->send_http_header; + $r->print($output); + return 200; +} - $template->process($r->template, \%args); +sub error { + my ($self, $r, $error) = @_; + $r->{ar}_>content_type("text/plain"); + $r->send_http_header; + $r->print($error); + return 500; + exit; }