1 package Maypole::View::TT;
2 use Lingua::EN::Inflect;
5 use UNIVERSAL::moniker;
9 sub new { bless {}, shift } # Not worth having
14 my $root = $r->{config}{template_root} || $r->get_template_root;
15 Template->new({ INCLUDE_PATH => [
17 ($r->model_class && File::Spec->catdir($root, $r->model_class->moniker)),
18 File::Spec->catdir($root, "custom"),
19 File::Spec->catdir($root, "factory")
25 my $class = $r->model_class;
28 objects => $r->objects,
29 base => $r->config->{uri_base},
34 $args{classmetadata} = {
36 columns => [ $class->display_columns ],
37 colnames => { $class->column_names },
38 related_accessors => [ $class->related($r) ],
39 moniker => $class->moniker,
40 plural => $class->plural_moniker,
41 cgi => { $class->to_cgi },
42 description => $class->description
45 # User-friendliness facility for custom template writers.
46 if (@{$r->objects || []} > 1) {
47 $args{$r->model_class->plural_moniker} = $r->objects;
49 ($args{$r->model_class->moniker}) = @{$r->objects ||[]};
54 %args = (%args, %{$r->{template_args}||{}});
60 my $template = $self->_tt($r);
62 $template->process($r->template, { $self->_args($r) }, \$output)
63 || return $self->error($r, $template->error);
65 $r->{content_type} ||= "text/html";
66 $r->{output} = $output;
71 my ($self, $r, $error) = @_;
73 if ($error =~ /not found$/) { return -1 }
74 $r->{content_type} = "text/plain";
75 $r->{output} = $error;