File Coverage

blib/lib/Catalyst/View/Template.pm
Criterion Covered Total %
statement 39 44 88.6
branch 7 14 50.0
condition 2 3 66.6
subroutine 10 11 90.9
pod 6 6 100.0
total 64 78 82.0


line stmt bran cond sub pod time code
1 1     1   1644479 use strict; use warnings;
  1     1   2  
  1         24  
  1         4  
  1         3  
  1         53  
2              
3              
4             our $VERSION = '1.102';
5              
6             use MRO::Compat ();
7 1     1   6 use Catalyst::Utils ();
  1         1  
  1         27  
8 1     1   5  
  1         2  
  1         19  
9             use Catalyst::Component ();
10 1     1   5 our @ISA = 'Catalyst::Component';
  1         2  
  1         523  
11              
12             __PACKAGE__->mk_accessors( my @attribute = qw( class_name template_ext content_type template ) );
13              
14             __PACKAGE__->config(
15             class_name => 'Template',
16             template_ext => '',
17             content_type => 'text/html; charset=utf-8',
18             EVAL_PERL => 0,
19             ENCODING => 'UTF-8',
20             # cannot set INCLUDE_PATH before the app class is set up...
21             );
22              
23             my ( $class, $c, $args ) = ( shift, @_ );
24             my $self = $class->next::method( @_ );
25 5     5 1 43457 my %config = %$self;
26 5         17 delete @config{ 'catalyst_component_name', @attribute };
27 5         7814 $config{'INCLUDE_PATH'} = [ $c->path_to( 'root' ) ] unless exists $config{'INCLUDE_PATH'};
28 5         17 $self->template( $self->new_template( $c, \%config ) );
29 5 50       29 $self;
30 5         874 }
31 5         22290  
32             my ( $self, $c, $config ) = ( shift, @_ );
33             Catalyst::Utils::ensure_class_loaded $self->class_name;
34             $self->class_name->new( $config )
35 5     5 1 138 or die $self->class_name->error;
36 5         60 }
37 5 50       634  
38             my ( $self, $c ) = ( shift, @_ );
39              
40             my $template = $c->stash->{'template'} || $c->action->reverse;
41             my %vars = %{ $c->stash };
42 13     13 1 217087 my $output;
43              
44 13   66     37 $self->render ( $c, $template, \%vars, \$output )
45 13         1106 ? $self->process_output( $c, $template, \%vars, \$output )
  13         24  
46 13         673 : $self->process_error ( $c, $template, \%vars, )
47             }
48 13 50       42  
49             my ( $self, $c, $template, $vars, $output_ref ) = ( shift, @_ );
50             $template .= $self->template_ext unless 'SCALAR' eq ref $template;
51             $c->log->debug( sprintf 'Rendering template "%s"', ref $template ? "\\\Q$$template\E" : $template )
52             if $c->debug;
53             $self->template->process( $template, $vars, $output_ref );
54 17     17 1 85930 }
55 17 100       82  
56 17 0       1786 my ( $self, $c, $template, $vars, $output_ref ) = ( shift, @_ );
    50          
57             $c->res->content_type( $self->content_type ) unless $c->res->content_type;
58 17         89 $c->res->body( $$output_ref );
59             1;
60             }
61              
62 13     13 1 16186 my ( $self, $c, $template, $vars ) = ( shift, @_ );
63 13 50       38 my $error = qq[Couldn't render template "$template": ] . $self->template->error;
64 13         6416 $c->log->error( $error );
65 13         613 $c->error( $error );
66             !1;
67             }
68              
69 0     0 1   1;