1 package Maypole::View::TT;
3 use Lingua::EN::Inflect;
6 use UNIVERSAL::moniker;
10 sub new { bless {}, shift } # Not worth having
15 my $root = $r->{config}{template_root} || $r->get_template_root;
16 Template->new({ INCLUDE_PATH => [
18 ($r->model_class && File::Spec->catdir($root, $r->model_class->moniker)),
19 File::Spec->catdir($root, "custom"),
20 File::Spec->catdir($root, "factory")
26 my $class = $r->model_class;
29 objects => $r->objects,
30 base => $r->config->{uri_base},
35 $args{classmetadata} = {
37 columns => [ $class->display_columns ],
38 colnames => { $class->column_names },
39 related_accessors => [ $class->related($r) ],
40 moniker => $class->moniker,
41 plural => $class->plural_moniker,
42 cgi => { $class->to_cgi },
43 description => $class->description
46 # User-friendliness facility for custom template writers.
47 if (@{$r->objects || []} > 1) {
48 $args{$r->model_class->plural_moniker} = $r->objects;
50 ($args{$r->model_class->moniker}) = @{$r->objects ||[]};
55 %args = (%args, %{$r->{template_args}||{}});
61 my $template = $self->_tt($r);
63 $template->process($r->template, { $self->_args($r) }, \$output)
64 || return $self->error($r, $template->error);
66 $r->{content_type} ||= "text/html";
67 $r->{output} = $output;
72 my ($self, $r, $error) = @_;
74 if ($error =~ /not found$/) { return DECLINED }
75 $r->{content_type} = "text/plain";
76 $r->{output} = $error;