blib/lib/DTL/Fast/Cache.pm

filter: Statementstmt 79.0% 34 / 43 Branchbran 50.0% 9 / 18 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 7 totaltotal 56.5% 52 / 92 SCAR 31.8
CC
15
Cov
66%
validate_template
32.4
put
2.0
get
2.0
CRAP 24.1
« blib/lib/DTL/Fast/Filter/Slice.pm ↑ Summary blib/lib/DTL/Fast/Parser.pm »
1 package DTL::Fast::Cache;
2 98 ▶use strict; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 # This is a prototype class for caching templates
4  
5 sub new
6 {
7 7 ▶ my( $proto, %kwargs ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
8
9 7 @kwargs{'hits','misses'} = (0,0);
10
11 7 return bless{ %kwargs }, $proto;
12 }
13  
14 sub get
15 {
16 92 ▶ my( $self, $key ) = @_;
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
17
18 92 my $template = $self->validate_template(
19 $self->read_data(
20 $key
21 )
22 );
23
24 defined $template ?
25 $self->{'hits'}++
26 92 ▶ : $self->{'misses'}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $template ? : 24 68 92
27
28 92 return $template;
29 }
30  
31 sub put
32 {
33 53 ▶ my( $self, $key, $template, %kwargs ) = @_;
Subroutine put: called CC=2 SCAR=6.9
Pod undocumented
34
35 53 ▶ if( defined $template )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $template) 53 0 53
36 {
37 53 my @keys = ('cache','url_source');
38 53 my @backup = @{$template}{@keys};
39 53 delete @{$template}{@keys};
40 53 $self->write_data($key, $template, %kwargs);
41 53 @{$template}{@keys} = @backup;
42 }
43 53 return $self;
44 }
45  
46 sub read_data
47 {
48 0 ▶ my( $self, $key ) = @_;
Subroutine read_data: not called CC=1 SCAR=6.9
Pod undocumented
49 0 die "read_data method was not defined in ".(ref $self);
50 }
51  
52 sub clear
53 {
54 0 ▶ my( $self ) = @_;
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
55 0 die "clear method was not defined in ".(ref $self);
56 }
57  
58 sub write_data
59 {
60 0 ▶ my( $self, $key, $value ) = @_;
Subroutine write_data: not called CC=1 SCAR=6.9
Pod undocumented
61
62 0 die "write_data method was not defined in ".(ref $self);
63 }
64  
65 sub validate_template
66 {
67 92 ▶ my( $self, $template ) = @_;
Subroutine validate_template: called CC=13 SCAR=34.8
Pod undocumented
68 92 ▶ return if not defined $template;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $template 68 24 92
69
70 # here we check if template is still valid
71
72 # check perl version
73 24 ▶ return if not $template->{'perl'} or $template->{'perl'} != $];
Branch: 1 branch
BranchTrueFalseTotal
if not $template->{"perl"} or $template->{"perl"} != $] 0 24 24
Condition33%1/3
not $template->{"perl"} or $template->{"perl"} != $]
l!l&&r!l&&!r
0024
MC/DC0%0/2
not $template->{"perl"} or $template->{"perl"} != $]
not $template->{"perl"} $template->{"perl"} != $]
Truth table33%1/3
not(A) or B
A= not $template->{"perl"}B= $template->{"perl"} != $]
ABresult
1X1
011
000
74
75 # check modules version
76 24 ▶ if( my $modules = $template->{'modules'} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $modules = $template->{"modules"}) 24 0 24
77 {
78 24 foreach my $module (keys(%$modules))
79 {
80 82 ▶ my $current_version = $module->VERSION // $DTL::Fast::VERSION;
Condition66%2/3
$module->VERSION // $DTL::Fast::VERSION
l!l&&r!l&&!r
37450
MC/DC0%0/2
$module->VERSION // $DTL::Fast::VERSION
$module->VERSION $DTL::Fast::VERSION
Truth table66%2/3
A // B
A= $module->VERSIONB= $DTL::Fast::VERSION
ABresult
1X1
011
000
81 82 ▶ return if $modules->{$module} ne $current_version;
Branch: 1 branch
BranchTrueFalseTotal
if $modules->{$module} ne $current_version 0 82 82
82 }
83 }
84  
85 # check files modification
86 24 ▶ if( my $files = $template->{'inherits'} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $files = $template->{"inherits"}) 0 24 24
87 {
88 0 foreach my $file (keys( %$files ))
89 {
90 0 ▶ next if $file eq 'inline';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "inline" 0 0 0
91 return if
92 not -e $file
93 0 ▶ or $files->{$file} != (stat($file))[9]
Branch: 1 branch
BranchTrueFalseTotal
if not -e $file or $files->{$file} != (stat $file)[9] 0 0 0
Condition0%0/3
not -e $file or $files->{$file} != (stat $file)[9]
l!l&&r!l&&!r
000
MC/DC0%0/2
not -e $file or $files->{$file} != (stat $file)[9]
not -e $file $files->{$file} != (stat $file)[9]
Truth table0%0/3
not(A) or B
A= not -e $fileB= $files->{$file} != (stat $file)[9]
ABresult
1X1
011
000
94 }
95 }
96
97 24 return $template;
98 }
99  
100 98 1;
« blib/lib/DTL/Fast/Filter/Slice.pm ↑ Summary blib/lib/DTL/Fast/Parser.pm »