1 package Maypole::View::Base;
3 use UNIVERSAL::moniker;
5 use Maypole::Constants;
7 sub new { bless {}, shift } # By default, do nothing.
11 my $root = $r->{config}{template_root} || $r->get_template_root;
15 File::Spec->catdir($root, $r->model_class->moniker)),
16 File::Spec->catdir($root, "custom"),
17 File::Spec->catdir($root, "factory")
23 my $class = $r->model_class;
26 objects => $r->objects,
27 base => $r->config->{uri_base},
32 $args{classmetadata} = {
34 table => $class->table,
35 columns => [ $class->display_columns ],
36 colnames => { $class->column_names },
37 related_accessors => [ $class->related($r) ],
38 moniker => $class->moniker,
39 plural => $class->plural_moniker,
40 cgi => { $class->to_cgi },
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 $status = $self->template($r);
59 return $self->error($r) if $status != OK;
60 $r->{content_type} ||= "text/html";
67 if ($r->{error} =~ /not found$/) {
68 # This is a rough test to see whether or not we're a template or
70 return -1 unless @{$r->{objects}||[]};
74 <H1> Template not found </H1>
76 This template was not found while processing the following request:
78 <B>@{[$r->{action}]}</B> on table <B>@{[ $r->{table} ]}</B> with objects:
81 @{[join "\n", @{$r->{objects}}]}
84 Looking for template <B>@{[$r->{template}]}</B> in paths:
87 @{[ join "\n", $self->paths($r) ]}
90 $r->{content_type} = "text/html";
91 $r->{output} = $r->{error};
94 $r->{content_type} = "text/plain";
95 $r->{output} = $r->{error};
100 sub template { die shift()." didn't define a decent template method!" }