1 package Maypole::View::Base;
3 use UNIVERSAL::moniker;
5 use Maypole::Constants;
7 sub new { bless {}, shift } # By default, do nothing.
10 my ( $self, $r ) = @_;
11 my $root = $r->config->template_root || $r->get_template_root;
16 && File::Spec->catdir( $root, $r->model_class->moniker )
18 File::Spec->catdir( $root, "custom" ),
19 File::Spec->catdir( $root, "factory" )
24 my ( $self, $r ) = @_;
25 my $class = $r->model_class;
26 my $base = $r->config->uri_base;
30 objects => $r->objects,
37 $args{classmetadata} = {
39 table => $class->table,
40 columns => [ $class->display_columns ],
41 colnames => { $class->column_names },
42 related_accessors => [ $class->related($r) ],
43 moniker => $class->moniker,
44 plural => $class->plural_moniker,
45 cgi => { $class->to_cgi },
48 # User-friendliness facility for custom template writers.
49 if ( @{ $r->objects || [] } > 1 ) {
50 $args{ $r->model_class->plural_moniker } = $r->objects;
53 ( $args{ $r->model_class->moniker } ) = @{ $r->objects || [] };
58 %args = ( %args, %{ $r->{template_args} || {} } );
63 my ( $self, $r ) = @_;
64 $r->{content_type} ||= "text/html";
65 $r->{document_encoding} ||= "utf-8";
66 my $status = $self->template($r);
67 return $self->error($r) if $status != OK;
72 my ( $self, $r ) = @_;
74 if ( $r->{error} =~ /not found$/ ) {
76 # This is a rough test to see whether or not we're a template or
78 return -1 unless @{ $r->{objects} || [] };
82 <H1> Template not found </H1>
84 This template was not found while processing the following request:
86 <B>@{[$r->{action}]}</B> on table <B>@{[ $r->{table} ]}</B> with objects:
89 @{[join "\n", @{$r->{objects}}]}
92 Looking for template <B>@{[$r->{template}]}</B> in paths:
95 @{[ join "\n", $self->paths($r) ]}
98 $r->{content_type} = "text/html";
99 $r->{output} = $r->{error};
102 $r->{content_type} = "text/plain";
103 $r->{output} = $r->{error};
108 sub template { die shift() . " didn't define a decent template method!" }