WSST/CodeTemplate.pm

filter: Statementstmt 100% 38 / 38 Branchbran 50.0% 2 / 4 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 5 / 5 totaltotal 96.6% 58 / 60 CC 6 SCAR 9.2
CC
6
Cov
96%
expand
4.0
new
3.0
BEGIN
1.0
CRAP 2.5
« WSST/Schema/Data.pm ↑ Summary WSST/SchemaParserManager.pm »
1 package WSST::CodeTemplate;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.1.1';
7  
8 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
9 2 my $class = shift;
10
11 2 my $self = {@_};
12 2 ▶ $self->{tmpl_dirs} ||= [];
Condition100%2/2
$self->{"tmpl_dirs"} ||= []
l!l
11
MC/DC100%1/1
$self->{"tmpl_dirs"} ||= []
$self->{"tmpl_dirs"}
Truth table100%2/2
A
A= $self->{"tmpl_dirs"}
Aresult
11
00
13 2 ▶ $self->{vars} ||= {};
Condition100%2/2
$self->{"vars"} ||= {}
l!l
11
MC/DC100%1/1
$self->{"vars"} ||= {}
$self->{"vars"}
Truth table100%2/2
A
A= $self->{"vars"}
Aresult
11
00
14
15 2 bless($self, $class);
16
17 2 return $self;
18 }
19  
20 4 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
21 4 my $self = shift;
22 4 my $key = shift;
23 4 return $self->{vars}->{$key};
24 }
25  
26 2 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
27 2 my $self = shift;
28 2 %{$self->{vars}} = (%{$self->{vars}}, @_);
29 }
30  
31 1 ▶sub expand {
Subroutine expand: called CC=4 SCAR=13.9
Pod documented
32 1 my $self = shift;
33 1 my $name = shift;
34 1 my %local_vars = @_;
35
36 1 my $tmpl = $self->new_template($name);
37
38 1 my $vars = {%{$self->{vars}}, %local_vars};
39
40 1 my $output;
41 1 my $res = $tmpl->process($name, $vars, \$output);
42  
43 1 ▶ die "TemplateError: $name: " . $tmpl->error() unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 1 1
44
45 1 foreach my $key (keys %$vars) {
46 1 ▶ next if exists $local_vars{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $local_vars{$key} 0 1 1
47 1 $self->{vars}->{$key} = $vars->{$key};
48 }
49
50 1 return $output;
51 }
52  
53 2 ▶sub new_template {
Subroutine new_template: called CC=1 SCAR=0.0
Pod documented
54 2 my $self = shift;
55 2 my $name = shift;
56  
57 my $conf = {
58 INCLUDE_PATH => $self->{tmpl_dirs},
59 2 };
60 2 return Template->new($conf);
61 }
62  
63 =head1 NAME
64  
65 WSST::CodeTemplate - CodeTemplate class of WSST
66  
67 =head1 DESCRIPTION
68  
69 CodeTemplate is class encapsulating the Template Toolkit.
70  
71 =head1 METHODS
72  
73 =head2 new
74  
75 Constructor.
76  
77 =head2 get
78  
79 Returns template variable of the specified name.
80  
81 =head2 set
82  
83 Set template variable.
84  
85 =head2 expand
86  
87 Expand the specified template file.
88  
89 =head2 new_template
90  
91 Create new Template object.
92  
93 =head1 SEE ALSO
94  
95 http://code.google.com/p/wsst/
96  
97 =head1 AUTHORS
98  
99 Mitsuhisa Oshikawa <mitsuhisa [at] gmail.com>
100 Yusuke Kawasaki <u-suke [at] kawa.net>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 Copyright 2008 WSS Project Team
105  
106 =cut
107 2 1;
« WSST/Schema/Data.pm ↑ Summary WSST/SchemaParserManager.pm »