| 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
Condition0%0/3
$Labyrinth::Writer::Parser::TT::settings{"evalperl"} or $vars->{"evalperl"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$@ or not $output
MC/DC0%0/2
$@ or not $output
$@
not $output
Truth table0%0/3
A or not(B)
A= $@B= not $output
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 114 | # parse to binary | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $parser->process($layout,$vars,$file, binmode => 1) or die $parser->error(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||
| 117 | # parse to text | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $parser->process($layout,$vars,$file) or die $parser->error(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | die "TT PARSER ERROR: eval=$@, error=" . $parser->error if($@); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 4 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||