File Coverage

blib/lib/Text/MicroMason/CompileCache.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 6 66.6
condition 2 3 66.6
subroutine 4 4 100.0
pod 1 1 100.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package Text::MicroMason::CompileCache;
2              
3 4     4   2001 use strict;
  4         8  
  4         108  
4 4     4   43 use Carp;
  4         7  
  4         986  
5              
6             require Text::MicroMason::Cache::Simple;
7             require Text::MicroMason::Cache::File;
8              
9             ######################################################################
10             # What cache class should we use for each src_type?
11              
12             my %CACHE_CLASS = (
13             file => 'Text::MicroMason::Cache::File',
14             text => 'Text::MicroMason::Cache::Simple',
15             );
16              
17             ######################################################################
18              
19             # $code_ref = compile( file => $filename );
20             sub compile {
21 64     64 1 556 my $self = shift;
22 64         105 my ( $src_type, $src_data, %options ) = @_;
23 64 50       122 my $cache = $self->_compile_cache( $src_type )
24             or return $self->NEXT('compile', @_);
25 64         142 my $key = $self->cache_key(@_);
26 64 100       128 $cache->get( $key ) or $cache->set( $key,
27             $self->NEXT('compile', @_),
28             );
29             }
30              
31             sub _compile_cache {
32 64     64   83 my ($self, $type) = @_;
33 64 50       122 $CACHE_CLASS{$type} or return;
34            
35 64   66     220 $self->{compile_cache}{$type} ||= $CACHE_CLASS{$type}->new();
36             }
37              
38             ######################################################################
39              
40              
41             1;
42              
43             __END__