sub object :Chained('base') :PathPart('id') :CaptureArgs(1) {
my ($self, $c, $key) = @_;
my $object = $self->get_collection($c)->find($key);
- confess "Object? what object?" unless $object; # should be a 404.
+ $c->detach("/error_404") unless $object;
$c->stash(object => $object);
}
$ctx->stash->{window}->flush;
}
+sub error_404 :Private {
+ my ($self, $c) = @_;
+ $c->res->body("Error 404: File not Found");
+ $c->res->status(404);
+}
+
+sub error_403 :Private {
+ my ($self, $c) = @_;
+ $c->res->body("Error 403: Forbidden");
+ $c->res->status(403);
+}
+
1;
=head1 NAME
my ($data, $text) = ($1, $2);
if ($data =~ /^for layout (\S+)/) {
my $fname = $1;
- $layouts->{$fname} = $text;
+ #remove extra whitespace without killing indentation
+ #remove all empty leading lines. and trailing whitespace
+ ($layouts->{$fname}) =
+ ($text =~ /^(?:\s*\n)*((?:.*?\n)*(?:.*?\S+.*?\n))\s*$/m);
} elsif ($data =~ /^extends (\S+)/) {
my $super_name = $1;
$self->super($build_args->{view}->create_layout_set($super_name))
my $name = $self->name;
$name =~ s/\//__/g; #slashes are not happy here...
my $layouts = $self->layouts;
- my $tt_source = qq{[% VIEW ${name};\n\n}.
- join("\n\n",
- map {
- qq{BLOCK $_; -%]\n}.$layouts->{$_}.qq{\n[% END;};
- } keys %$layouts
- ).qq{\nEND; # End view\ndata.view = ${name};\n %]};
+
+ my $tt_source = join("\n", "[%- VIEW ${name};",
+ (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
+ "END; # End view\ndata.view = ${name}; -%]" );
+
$tt_object->process(\$tt_source, $tt_args)
|| confess "Template processing error: ".$tt_object->error
." processing:\n${tt_source}";