| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not $template->{"perl"} or $template->{"perl"} != $]
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"} != $]
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # check modules version | ||||||||||||||||||||||||||||
| 76 | 24 | ▶ | if( my $modules = $template->{'modules'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 81 | 82 | ▶ | return if $modules->{$module} ne $current_version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # check files modification | ||||||||||||||||||||||||||||
| 86 | 24 | ▶ | if( my $files = $template->{'inherits'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | foreach my $file (keys( %$files )) | |||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | next if $file eq 'inline'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | return if | ||||||||||||||||||||||||||||
| 92 | not -e $file | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | or $files->{$file} != (stat($file))[9] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not -e $file or $files->{$file} != (stat $file)[9]
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]
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 24 | return $template; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 98 | 1; | |||||||||||||||||||||||||||