| Catalyst-View-Petal documentation | Contained in the Catalyst-View-Petal distribution. |
Catalyst::View::Petal - Petal View Class
# use the helper
create.pl view Petal Petal
# lib/MyApp/View/Petal.pm
package MyApp::View::Petal;
use base 'Catalyst::View::Petal';
__PACKAGE__->config(
input => 'XML',
output => 'XML',
error_on_undef_var => 0
);
1;
# Meanwhile, maybe in an 'end' action
$c->forward('MyApp::View::Petal');
This is the Petal view class. Your subclass should inherit from this
class.
Renders the template specified in $c->stash->{template} or $c->request->match.
Template variables are set up from the contents of $c->stash,
augmented with base set to $c->req->base, c to $c and
name to $c->config->{name}. Output is stored in
$c->response->body.
This allows your view subclass to pass additional settings to the Petal config hash.
Christian Hansen, ch@ngmedia.com
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| Catalyst-View-Petal documentation | Contained in the Catalyst-View-Petal distribution. |
package Catalyst::View::Petal; use strict; use base 'Catalyst::View'; use Petal; our $VERSION = '0.03';
sub process { my ( $self, $c ) = @_; my $file = $c->stash->{template} || $c->req->match; unless ($file) { $c->log->debug('No template specified for rendering') if $c->debug; return 0; } my %options = ( base_dir => [ $c->config->{root}, $c->config->{root} . "/base" ], file => $file ); unless ( $c->debug ) { $options{debug_dump} = 0; $options{error_on_undef_var} = 0; } my $process = { base => $c->req->base, c => $c, name => $c->config->{name}, %{ $c->stash } }; $c->log->debug(qq/Rendering template "$file"/) if $c->debug; my $petal = Petal->new( %options, %{ $self->config } ); my $body; eval { $body = $petal->process($process) }; if ( my $error = $@ ) { chomp $error; $error = qq/Couldn't render template "$file". Error: "$error"/; $c->log->error($error); $c->error($error); return 0; } unless ( $c->response->headers->content_type ) { $c->res->headers->content_type('text/html; charset=utf-8'); } $c->response->body($body); return 1; }
1;