OpenFrame::WebApp::Template::Petal - a Petal template processing wrapper


OpenFrame-WebApp documentation Contained in the OpenFrame-WebApp distribution.

Index


Code Index:

NAME

Top

OpenFrame::WebApp::Template::Petal - a Petal template processing wrapper

SYNOPSIS

Top

  use OpenFrame::WebApp::Template::Petal;

  my $tmpl = new OpenFrame::WebApp::Template::Petal;
  $tmpl->file( $local_file_path )
       ->template_vars( { fred => fish } )
       ->processor( new Petal( %args ) ); # optional

  try {
      $response = $tmpl->process;
  } catch OpenFrame::WebApp::Template::Error with {
      my $e = shift;
      print $e->flag, $e->message;
  }

DESCRIPTION

Top

The OpenFrame::WebApp::Template::Petal class is wrapper around Petal. It inherits its functionality from OpenFrame::WebApp::Template.

Uses XHTML Petal input by default, set processor() manually to override this.

TEMPLATE TYPE

Top

petal

AUTHOR

Top

Steve Purkis <spurkis@epn.nu>

COPYRIGHT

Top

SEE ALSO

Top

Petal, OpenFrame::WebApp::Template, OpenFrame::WebApp::Template::Factory


OpenFrame-WebApp documentation Contained in the OpenFrame-WebApp distribution.
package OpenFrame::WebApp::Template::Petal;

use strict;
use warnings::register;

use Petal;
use Error qw( :try );
use OpenFrame::WebApp::Template::Error;

use base qw( OpenFrame::WebApp::Template );

our $VERSION = (split(/ /, '$Revision: 1.7 $'))[1];


## use new petal instance as default
sub default_processor {
    my $self = shift;
    $Petal::INPUT = 'XHTML';
    return new Petal( $self->file );
}

## always need a new petal processor, if one was not already set:
sub process {
    my $self = shift;

    my $undef_processor = $self->processor ? 0 : 1;

    my $ofResult = $self->SUPER::process(@_);

    $self->processor( undef ) if $undef_processor;

    return $ofResult;
}

## process the template file
sub process_template {
    my $self = shift;

    my $output;
    eval {
	$output = $self->processor->process( $self->template_vars );
    };

    unless ($output) {
	throw OpenFrame::WebApp::Template::Error(
						 flag     => eTemplateError,
						 template => $self->file,
						 message  => $@,
						);
    }

    return $output;
}


1;

__END__