1 package Maypole::View::Base;
3 use UNIVERSAL::moniker;
6 sub new { bless {}, shift } # By default, do nothing.
10 my $root = $r->{config}{template_root} || $r->get_template_root;
14 File::Spec->catdir($root, $r->model_class->moniker)),
15 File::Spec->catdir($root, "custom"),
16 File::Spec->catdir($root, "factory")
22 my $class = $r->model_class;
25 objects => $r->objects,
26 base => $r->config->{uri_base},
31 $args{classmetadata} = {
33 table => $class->table,
34 columns => [ $class->display_columns ],
35 colnames => { $class->column_names },
36 related_accessors => [ $class->related($r) ],
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 ||[]};
52 %args = (%args, %{$r->{template_args}||{}});
58 my $template = Template->new({ INCLUDE_PATH => [ $self->paths($r) ]});
60 if ($template->process($r->template, { $self->args($r) }, \$output)) {
61 $r->{output} = $output;
64 $r->{error} = $template->error;
71 $self->template($r) || return $self->error($r);
72 $r->{content_type} ||= "text/html";
79 if ($r->{error} =~ /not found$/) { return -1 }
80 $r->{content_type} = "text/plain";
81 $r->{output} = $r->{error};
85 sub template { die shift()." didn't define a decent template method!" }