Tmojo/TemplateLoader.pm

filter: Statementstmt 80.0% 28 / 35 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 4 totaltotal 69.2% 36 / 52 CC 6 SCAR 12.4
CC
6
Cov
74%
template_exists
6.0
load_template
4.1
template_package_name
2.0
CRAP 3.5
« Tmojo/Filters.pm ↑ Summary
1 ###########################################################################
2 # Copyright 2004 Lab-01 LLC <http://lab-01.com/>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Tmojo(tm) is a trademark of Lab-01 LLC.
17 ###########################################################################
18  
19 package HTML::Tmojo::TemplateLoader;
20  
21 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
24 5 my ($class, $template_dir, $tmojo_lite) = @_;
25
26 5 $template_dir =~ s/\/$//;
27
28 5 my $self = {
29 template_dir => $template_dir,
30 tmojo_lite => $tmojo_lite,
31 };
32
33 5 return bless $self, $class;
34 }
35  
36 9 ▶sub load_template {
Subroutine load_template: called CC=4 SCAR=14.2
Pod undocumented
37 9 my ($self, $normalized_template_id, $cache_time_stamp) = @_;
38
39 9 my $file_name = "$self->{template_dir}$normalized_template_id";
40
41 9 ▶ unless (-r $file_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file_name) 0 9 9
42 0 die "couldn't find template '$normalized_template_id' ($file_name)";
43 }
44
45 9 ▶ if (-d $file_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file_name) 0 9 9
46 0 die "template '$normalized_template_id' ($file_name) is a directory";
47 }
48
49 9 my $source_time_stamp = (stat($file_name))[9];
50
51 9 ▶ if ($source_time_stamp > $cache_time_stamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_time_stamp > $cache_time_stamp) { } 8 1 9
52 # LOAD AND RETURN THE FILE
53 8 open my ($fh), $file_name;
54 8 local $/ = "\n"; # THIS CAN GET EXTRA SCREWED UP IN MOD_PERL
55 8 my @template_lines = <$fh>;
56 8 close $fh;
57
58 8 return \@template_lines, $self->{tmojo_lite};
59 }
60 else {
61 1 return 0;
62 }
63 }
64  
65 0 ▶sub template_exists {
Subroutine template_exists: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my ($self, $normalized_template_id) = @_;
67
68 0 my $file_name = "$self->{template_dir}$normalized_template_id";
69
70 0 ▶ if (-r $file_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $file_name) { } 0 0 0
71 0 return 1;
72 }
73 else {
74 0 return 0;
75 }
76 }
77  
78 9 ▶sub template_package_name {
Subroutine template_package_name: called CC=2 SCAR=6.9
Pod undocumented
79 9 my ($self, $normalized_template_id) = @_;
80
81 9 my $package = "$self->{template_dir}$normalized_template_id";
82
83 9 for ($package) {
84 9 tr/:/_/;
85 9 s{/}{::}g;
86 9 s/[^\d\w:]/_/g;
87 }
88
89 9 $package = "HTML::Tmojo::TemplateLoader::$package";
90
91 9 return $package;
92 }
93  
94 5 1;
« Tmojo/Filters.pm ↑ Summary