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   1709615 use strict; use warnings;
  1     1   2  
  1         24  
  1         5  
  1         2  
  1         54  
2              
3              
4             our $VERSION = '1.103';
5              
6             use MRO::Compat ();
7 1     1   6 use Catalyst::Utils ();
  1         2  
  1         21  
8 1     1   5  
  1         2  
  1         18  
9             use Catalyst::Component ();
10 1     1   6 our @ISA = 'Catalyst::Component';
  1         1  
  1         542  
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 44667 my %config = %$self;
26 5         12 delete @config{ 'catalyst_component_name', @attribute };
27 5         8045 $config{'INCLUDE_PATH'} = [ $c->path_to( 'root' ) ] unless exists $config{'INCLUDE_PATH'};
28 5         18 $self->template( $self->new_template( $c, \%config ) );
29 5 50       29 $self;
30 5         870 }
31 5         23257  
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 145 or die $self->class_name->error;
36 5         33 }
37 5 50       638  
38             my ( $self, $c ) = ( shift, @_ );
39              
40             my $template = $c->stash->{'template'} || $c->action->reverse;
41             my %vars = %{ $c->stash };
42 13     13 1 223891 my $output;
43              
44 13   66     35 $self->render ( $c, $template, \%vars, \$output )
45 13         1149 ? $self->process_output( $c, $template, \%vars, \$output )
  13         27  
46 13         679 : $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 90189 }
55 17 100       88  
56 17 0       1809 my ( $self, $c, $template, $vars, $output_ref ) = ( shift, @_ );
    50          
57             $c->res->content_type( $self->content_type ) unless $c->res->content_type;
58 17         90 $c->res->body( $$output_ref );
59             1;
60             }
61              
62 13     13 1 16426 my ( $self, $c, $template, $vars ) = ( shift, @_ );
63 13 50       40 my $error = qq[Couldn't render template "$template": ] . $self->template->error;
64 13         6746 $c->log->error( $error );
65 13         659 $c->error( $error );
66             !1;
67             }
68              
69 0     0 1   1;