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;
24 my $base = $r->{config}->{uri_base};
28 objects => $r->objects,
34 $args{classmetadata} = {
36 table => $class->table,
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 },
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 $status = $self->template($r);
61 return $self->error($r) if $status != OK;
62 $r->{content_type} ||= "text/html";
63 $r->{document_encoding} ||= "utf-8";
70 if ($r->{error} =~ /not found$/) {
71 # This is a rough test to see whether or not we're a template or
73 return -1 unless @{$r->{objects}||[]};
77 <H1> Template not found </H1>
79 This template was not found while processing the following request:
81 <B>@{[$r->{action}]}</B> on table <B>@{[ $r->{table} ]}</B> with objects:
84 @{[join "\n", @{$r->{objects}}]}
87 Looking for template <B>@{[$r->{template}]}</B> in paths:
90 @{[ join "\n", $self->paths($r) ]}
93 $r->{content_type} = "text/html";
94 $r->{output} = $r->{error};
97 $r->{content_type} = "text/plain";
98 $r->{output} = $r->{error};
103 sub template { die shift()." didn't define a decent template method!" }