1 package Apache::MVC::View::TT;
2 use Lingua::EN::Inflect;
5 use UNIVERSAL::moniker;
9 sub new { bless {}, shift } # Not worth having
13 my $root = $r->config->{template_root};
14 Template->new({ INCLUDE_PATH => [
16 File::Spec->catdir($root, $r->model_class->moniker),
17 File::Spec->catdir($root, "custom"),
18 File::Spec->catdir($root, "factory")
24 my $class = $r->model_class;
28 objects => $r->objects,
29 base => $r->config->{uri_base},
33 $args{classmetadata} = {
35 columns => [ $class->columns ],
36 colnames => { $class->column_names },
37 moniker => $class->moniker,
38 plural => $class->plural_moniker,
39 cgi => { $class->to_cgi },
40 description => $class->description
43 # User-friendliness facility for custom template writers.
44 if (@{$r->objects} > 1){
45 $args{$r->model_class->plural_moniker} = $r->objects;
47 ($args{$r->model_class->moniker}) = @{$r->objects};
51 %args = (%args, %{$r->{template_args}||{}});
57 my $template = $self->_tt($r);
59 $template->process($r->template, { $self->_args($r) }, \$output)
60 || $self->error($r, $template->error);
61 $r->{ar}->content_type("text/html");
62 $r->{ar}->headers_out->set("Content-Length" => length $output);
63 $r->{ar}->send_http_header;
64 $r->{ar}->print($output);
69 my ($self, $r, $error) = @_;
70 $r->{ar}->send_http_header("text/plain");
71 $r->{ar}->print($error);