View/HTML/Embperl.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Helper/View/HTML/Embperl.pm ↑ Summary
1 package Catalyst::View::HTML::Embperl;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base 'Catalyst::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 0 ▶use HTML::Embperl;
Subroutine BEGIN: called CC=1 SCAR=2.6
6  
7 our $VERSION = '0.01';
8  
9 =head1 NAME
10  
11 Catalyst::View::HTML::Embperl - HTML::Embperl View Class
12  
13 =head1 SYNOPSIS
14  
15 # use the helper
16 create.pl view HTML::Embperl HTML::Embperl
17  
18 # lib/MyApp/View/HTML/Embperl.pm
19 package MyApp::View::HTML::Embperl;
20  
21 use base 'Catalyst::View::HTML::Embperl';
22  
23 1;
24  
25 # Meanwhile, maybe in an 'end' action
26 $c->forward('MyApp::View::HTML::Embperl');
27  
28  
29 =head1 DESCRIPTION
30  
31 This is the C<HTML::Embperl> view class. Your subclass should inherit from this
32 class.
33  
34 =head2 METHODS
35  
36 =over 4
37  
38 =item process
39  
40 Renders the template specified in C<< $c->stash->{template} >> or C<<
41 $c->request->match >>.
42 Template params FDAT are set up from the contents of C<< $c->req->parameters >> first,
43 then overwritten by C<< $c->stash >>.
44 Global variables C<base> set to C<< $c->req->base >>,
45 C<name> to C<< $c->config->{name} >> and C<c> to Catalyst context.
46 Output is stored in C<< $c->response->body >>.
47  
48 =cut
49  
50 sub process {
51 my ( $self, $c ) = @_;
52  
53 my $filename = $c->stash->{template} || $c->req->match;
54  
55 unless ( $filename ) {
56 $c->log->debug('No template specified for rendering') if $c->debug;
57 return 0;
58 }
59  
60 $c->log->debug( "Rendering template \"$filename\"" ) if $c->debug;
61  
62 $Catalyst::View::HTML::Embperl::T::base = $c->req->base;
63 $Catalyst::View::HTML::Embperl::T::name = $c->config->{name};
64 $Catalyst::View::HTML::Embperl::T::c = $c;
65  
66 my $body;
67  
68 eval {
69 HTML::Embperl::Execute( {
70 'path' => $c->config->{root},
71 'inputfile' => $filename,
72 'package' => 'Catalyst::View::HTML::Embperl::T',
73 'fdat' => { %{$c->req->parameters}, %{$c->stash} },
74 'output' => \$body
75 } );
76 };
77  
78 if ( my $error = $@ ) {
79 chomp $error;
80 $error = "Couldn't render template \"$filename\". Error: \"$error\"";
81 $c->log->error( $error );
82 $c->error( $error );
83 return 0;
84 }
85  
86 unless ( $c->response->headers->content_type ) {
87 $c->res->headers->content_type( 'text/html' );
88 }
89  
90 $c->response->body( $body );
91  
92 return 1;
93 }
94  
95 =head1 SEE ALSO
96  
97 L<HTML::Embperl>, L<Catalyst>, L<Catalyst::Base>.
98  
99 =head1 AUTHOR
100  
101 Aldo LeTellier, C<aldoletellier@bigfoot.com>
102  
103 =head1 COPYRIGHT
104  
105 This program is free software, you can redistribute it and/or modify it
106 under the same terms as Perl itself.
107  
108 =cut
109  
110 1;
« Helper/View/HTML/Embperl.pm ↑ Summary