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 },
41 description => $class->description
44 # User-friendliness facility for custom template writers.
45 if (@{$r->objects || []} > 1) {
46 $args{$r->model_class->plural_moniker} = $r->objects;
48 ($args{$r->model_class->moniker}) = @{$r->objects ||[]};
53 %args = (%args, %{$r->{template_args}||{}});
59 my $status = $self->template($r);
60 return $self->error($r) if $status != OK;
61 $r->{content_type} ||= "text/html";
68 if ($r->{error} =~ /not found$/) { return -1 }
69 $r->{content_type} = "text/plain";
70 $r->{output} = $r->{error};
75 sub template { die shift()." didn't define a decent template method!" }