use Template;
use File::Spec;
use UNIVERSAL::moniker;
+use strict;
sub new { bless {}, shift } # Not worth having
sub _args {
my ($self, $r) = @_;
+ my $class = $r->model_class;
my %args = (
request => $r,
- class => $r->model_class,
+ class => $class,
objects => $r->objects,
+ base => $r->config->{uri_base},
# ...
);
+ $args{classmetadata} = {
+ name => $class,
+ columns => [ $class->columns ],
+ colnames => { $class->column_names },
+ moniker => $class->moniker,
+ plural => $class->plural_moniker,
+ cgi => { $class->to_cgi },
+ description => $class->description
+ };
# User-friendliness facility for custom template writers.
if (@{$r->objects} > 1){
sub process {
my ($self, $r) = @_;
- my $template = $self->_tt($r):
+ my $template = $self->_tt($r);
my $output;
- $template->process($r->template, { $self->_args($r) }, \$output);
+ $template->process($r->template, { $self->_args($r) }, \$output)
|| $self->error($r, $template->error);
$r->{ar}->content_type("text/html");
$r->{ar}->headers_out->set("Content-Length" => length $output);
- $r->send_http_header;
- $r->print($output);
+ $r->{ar}->send_http_header;
+ $r->{ar}->print($output);
return 200;
}
sub error {
my ($self, $r, $error) = @_;
- $r->{ar}_>content_type("text/plain");
- $r->send_http_header;
- $r->print($error);
- return 500;
+ $r->{ar}->send_http_header("text/plain");
+ $r->{ar}->print($error);
exit;
}