File Coverage

blib/lib/Template/Alloy/Tmpl.pm
Criterion Covered Total %
statement 49 56 87.5
branch 8 16 50.0
condition 9 19 47.3
subroutine 11 15 73.3
pod 11 12 91.6
total 88 118 74.5


line stmt bran cond sub pod time code
1             package Template::Alloy::Tmpl;
2              
3             =head1 NAME
4              
5             Template::Alloy::Tmpl - Text::Tmpl role
6              
7             =cut
8              
9 2     2   15 use strict;
  2         3  
  2         78  
10 2     2   11 use warnings;
  2         4  
  2         52  
11 2     2   10 use Template::Alloy;
  2         4  
  2         13  
12              
13             our $VERSION = $template::Alloy::VERSION;
14             our $error;
15              
16 0     0 0 0 sub new { die "This class is a role for use by packages such as Template::Alloy" }
17              
18             ###----------------------------------------------------------------###
19              
20             sub parse_tree_tmpl {
21 106     106 1 158 my $self = shift;
22              
23 106         186 local @{ $Template::Alloy::Parse::ALIASES }{qw(ECHO INCLUDE IFN ENDCOMMENT ENDIF ENDIFN ENDLOOP)}
  106         463  
24             = qw(GET PROCESS UNLESS END END END END);
25 106 50       343 local $self->{'V1DOLLAR'} = defined($self->{'V1DOLLAR'}) ? $self->{'V1DOLLAR'} : 1;
26 106 50       242 local $self->{'ANYCASE'} = defined($self->{'ANYCASE'}) ? $self->{'ANYCASE'} : 1;
27 106   50     340 local $self->{'TAG_STYLE'} = $self->{'TAG_STYLE'} || 'html';
28              
29 106         340 return $self->parse_tree_tt3(@_);
30             }
31              
32             ###----------------------------------------------------------------###
33             ### support for few Text::Tmpl calling syntax
34              
35             sub set_delimiters {
36 98     98 1 353 my $self = shift;
37 98   33     291 $self->{'START_TAG'} = quotemeta(shift || $self->throw('set', 'missing start_tag'));
38 98   33     274 $self->{'END_TAG'} = quotemeta(shift || $self->throw('set', 'missing end_tag'));
39             }
40              
41 0     0 1 0 sub strerror { $Template::Alloy::Tmpl::error }
42              
43 98 50   98 1 294 sub set_strip { my $self = shift; $self->{'POST_CHOMP'} = $_[0] ? '-' : '+'; 1 }
  98         228  
  98         148  
44              
45 0     0 1 0 sub set_value { my $self = shift; $self->{'_vars'}->{$_[0]} = $_[1]; 1 }
  0         0  
  0         0  
46              
47 108   100 108 1 341 sub set_values { my ($self, $hash) = @_; @{ $self->{'_vars'} ||= {} }{keys %$hash} = values %$hash; 1 }
  108         291  
  108         487  
  108         242  
48              
49 98     98 1 519 sub parse_string { my $self = shift; return $self->parse_file(\$_[0]) }
  98         200  
50              
51             sub set_dir {
52 98     98 1 377 my $self = shift;
53 98         254 $self->{'INCLUDE_PATHS'} = [shift, './'];
54             }
55              
56             sub parse_file {
57 98     98 1 152 my ($self, $content) = @_;
58              
59 98   50     263 my $vars = $self->{'_vars'} || {};
60              
61 98   50     380 local $self->{'SYNTAX'} = $self->{'SYNTAX'} || 'tmpl';
62 98         171 local $Template::Alloy::QR_PRIVATE = undef;
63 98 50       300 local $self->{'ABSOLUTE'} = defined($self->{'ABSOLUTE'}) ? $self->{'ABSOLUTE'} : 1;
64 98 50       267 local $self->{'RELATIVE'} = defined($self->{'RELATIVE'}) ? $self->{'RELATIVE'} : 1;
65              
66 98         185 $error = undef;
67              
68 98         152 my $out = '';
69 98 50       269 $self->process_simple($content, $vars, \$out)
70             || ($error = $self->error);
71 98         444 return $out;
72             }
73              
74             sub loop_iteration {
75 10     10 1 69 my $self = shift;
76 10         16 my $name = shift;
77 10   100     42 my $ref = $self->{'_vars'}->{$name} ||= [];
78 10         15 my $vars;
79              
80 10 50       43 $self->throw('loop', "Variable $name is not an arrayref during loop_iteration") if ref($ref) ne 'ARRAY';
81 10 50       24 if (defined(my $index = shift)) {
82 0   0     0 $vars = $ref->[$index] || $self->throw('loop', "Index $index is not yet defined on loop $name");
83             } else {
84 10         18 $vars = {};
85 10         20 push @$ref, $vars;
86             }
87              
88 10         32 return ref($self)->new('_vars' => $vars);
89             }
90              
91 0     0 1   sub fetch_loop_iteration { shift->loop_iteration(@_) }
92              
93             ###----------------------------------------------------------------###
94              
95             1;
96              
97             __END__