Catalyst::View::Petal - Petal View Class


Catalyst-View-Petal documentation Contained in the Catalyst-View-Petal distribution.

Index


Code Index:

NAME

Top

Catalyst::View::Petal - Petal View Class

SYNOPSIS

Top

    # 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');




DESCRIPTION

Top

This is the Petal view class. Your subclass should inherit from this class.

METHODS

process

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.

config

This allows your view subclass to pass additional settings to the Petal config hash.

SEE ALSO

Top

Petal, Catalyst, Catalyst::Base.

AUTHOR

Top

Christian Hansen, ch@ngmedia.com

COPYRIGHT

Top


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;