Labyrinth/Writer/Parser/TT.pm

filter: Statementstmt 44.6% 21 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 36.1% 30 / 83 CC 10 SCAR 31.3
CC
10
Cov
31%
parse_to_file
42.0
parser
30.0
new
2.0
CRAP 22.8
« Labyrinth/CookieLib.pm ↑ Summary Labyrinth/Variables.pm »
1 package Labyrinth::Writer::Parser::TT;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $VERSION = '5.32';
8  
9 =head1 NAME
10  
11 Labyrinth::Writer::Parser::TT - Template Toolkit Renderer for Labyrinth
12  
13 =head1 SYNOPSIS
14  
15 use Labyrinth::Writer::Parser::TT;
16 my $tt = Labyrinth::Writer::Parser::TT->new();
17 $tt->parser('mytemplate.html');
18  
19 =head1 DESCRIPTION
20  
21 This package provides the ability to parse a given template, with a given set
22 of template variables using Template Toolkit.
23  
24 =cut
25  
26 # -------------------------------------
27 # Library Modules
28  
29 4 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 # -------------------------------------
35 # Variables
36  
37 4 my %config = ( # default config info
38 RELATIVE => 1,
39 ABSOLUTE => 1,
40 INTERPOLATE => 0,
41 POST_CHOMP => 1,
42 TRIM => 1,
43 );
44  
45 # -------------------------------------
46 # The Subs
47  
48 =head1 METHODS
49  
50 =over 4
51  
52 =item new
53  
54 Object constructor.
55  
56 =item parser( $template, $variables )
57  
58 Parses a given template, via Template Toolkit. Returns a string of the
59 parsed template.
60  
61 =item parse_to_file( $template, $variables, $file, $binary )
62  
63 Parses a given template, via Template Toolkit. Writes the result to the named
64 file, marking as binary if requested.
65  
66 =back
67  
68 =cut
69  
70 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
71 0 my($class) = @_;
72  
73 0 my $self = bless { config => \%config }, $class;
74 0 $self;
75 }
76  
77 0 ▶sub parser {
Subroutine parser: not called CC=5 SCAR=34.0
Pod documented
78 0 my ($self, $layout, $vars) = @_;
79 0 my $path = $settings{'templates'};
80 0 my $output;
81  
82 # use Data::Dumper;
83 # LogDebug( "layout=[$layout]" );
84 # LogDebug( "vars=".Dumper($vars) );
85  
86 0 $self->{config}{INCLUDE_PATH} = $path;
87 0 ▶ $self->{config}{EVAL_PERL} = ($settings{evalperl} || $vars->{evalperl} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$Labyrinth::Writer::Parser::TT::settings{'evalperl'} || $vars->{'evalperl'} ? : 0 0 0
Condition0%0/3
$Labyrinth::Writer::Parser::TT::settings{"evalperl"} or $vars->{"evalperl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Labyrinth::Writer::Parser::TT::settings{"evalperl"} or $vars->{"evalperl"}
$Labyrinth::Writer::Parser::TT::settings{"evalperl"} $vars->{"evalperl"}
Truth table0%0/3
A or B
A= $Labyrinth::Writer::Parser::TT::settings{"evalperl"}B= $vars->{"evalperl"}
ABresult
1X1
011
000
88 0 $self->{config}{OUTPUT_PATH} = $vars->{cache};
89  
90 0 my $parser = Template->new($self->{config}); # initialise parser
91 0 eval { $parser->process($layout,$vars,\$output) };
92 0 ▶ die "TT PARSER ERROR: " . $parser->error() if($@ || !$output);
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not $output 0 0 0
Condition0%0/3
$@ or not $output
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $output
$@ not $output
Truth table0%0/3
A or not(B)
A= $@B= not $output
ABresult
1X1
011
000
93  
94 0 return \$output;
95 }
96  
97 0 ▶sub parse_to_file {
Subroutine parse_to_file: not called CC=6 SCAR=37.4
Pod documented
98 0 my ($self, $layout, $vars, $file, $binary) = @_;
99 0 my $path = $settings{'templates'};
100  
101 # use Data::Dumper;
102 0 LogDebug( "file=[$file], binary=[$binary]" );
103 # LogDebug( "layout=[$layout]" );
104 # LogDebug( "vars=".Dumper($vars) );
105  
106 0 $self->{config}{INCLUDE_PATH} = $path;
107 0 ▶ $self->{config}{EVAL_PERL} = ($vars->{evalperl} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$vars->{'evalperl'} ? : 0 0 0
108 0 $self->{config}{OUTPUT_PATH} = $vars->{cache};
109  
110 0 my $parser = Template->new($self->{config}); # initialise parser
111  
112 0 eval {
113 0 ▶ if($binary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($binary) { } 0 0 0
114 # parse to binary
115 0 ▶ $parser->process($layout,$vars,$file, binmode => 1) or die $parser->error();
Branch: 1 branch
BranchTrueFalseTotal
$parser->process($layout, $vars, $file, "binmode", 1) or die $parser->error 0 0 0
116 } else {
117 # parse to text
118 0 ▶ $parser->process($layout,$vars,$file) or die $parser->error();
Branch: 1 branch
BranchTrueFalseTotal
$parser->process($layout, $vars, $file) or die $parser->error 0 0 0
119 }
120 };
121  
122 0 ▶ die "TT PARSER ERROR: eval=$@, error=" . $parser->error if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
123 }
124  
125 4 1;
126  
127 __END__
« Labyrinth/CookieLib.pm ↑ Summary Labyrinth/Variables.pm »