WebApp/Template/Petal.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 53 CC 4 SCAR 16.4
CC
4
Cov
0%
process
12.0
process_template
6.0
default_processor
2.0
CRAP 5.2
1 =head1 NAME
2  
3 OpenFrame::WebApp::Template::Petal - a Petal template processing wrapper
4  
5 =head1 SYNOPSIS
6  
7 use OpenFrame::WebApp::Template::Petal;
8  
9 my $tmpl = new OpenFrame::WebApp::Template::Petal;
10 $tmpl->file( $local_file_path )
11 ->template_vars( { fred => fish } )
12 ->processor( new Petal( %args ) ); # optional
13  
14 try {
15 $response = $tmpl->process;
16 } catch OpenFrame::WebApp::Template::Error with {
17 my $e = shift;
18 print $e->flag, $e->message;
19 }
20  
21 =cut
22  
23 package OpenFrame::WebApp::Template::Petal;
24  
25 use strict;
26 use warnings::register;
27  
28 use Petal;
29 use Error qw( :try );
30 use OpenFrame::WebApp::Template::Error;
31  
32 use base qw( OpenFrame::WebApp::Template );
33  
34 our $VERSION = (split(/ /, '$Revision: 1.7 $'))[1];
35  
36  
37 ## use new petal instance as default
38 sub default_processor {
39 my $self = shift;
40 $Petal::INPUT = 'XHTML';
41 return new Petal( $self->file );
42 }
43  
44 ## always need a new petal processor, if one was not already set:
45 sub process {
46 my $self = shift;
47  
48 my $undef_processor = $self->processor ? 0 : 1;
49  
50 my $ofResult = $self->SUPER::process(@_);
51  
52 $self->processor( undef ) if $undef_processor;
53  
54 return $ofResult;
55 }
56  
57 ## process the template file
58 sub process_template {
59 my $self = shift;
60  
61 my $output;
62 eval {
63 $output = $self->processor->process( $self->template_vars );
64 };
65  
66 unless ($output) {
67 throw OpenFrame::WebApp::Template::Error(
68 flag => eTemplateError,
69 template => $self->file,
70 message => $@,
71 );
72 }
73  
74 return $output;
75 }
76  
77  
78 1;
79  
80 __END__