| 1 | package Text::MicroMason::Cache::File; | ||||||||||||||||||||||||||||
| 2 | 4 | @ISA = 'Text::MicroMason::Cache::Simple'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Array field names | ||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use constant LAST_CHECK => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use constant AGE => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use constant VALUE => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | ###################################################################### | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 26 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 26 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 15 | 26 | ▶ | my $entry = $self->SUPER::get( $file ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | or return; | ||||||||||||||||||||||||||||
| 17 | 17 | ▶ | unless (ref($entry) eq 'ARRAY' and @$entry == 3 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $entry eq "ARRAY" and @$entry == 3
MC/DC0%0/2
ref $entry eq "ARRAY" and @$entry == 3
ref $entry eq "ARRAY"
@$entry == 3
Truth table33%1/3
A and B
A= ref $entry eq "ARRAY"B= @$entry == 3
| |||||||||||||||||||||||||||||
| 18 | 0 | Carp::croak("MicroMason: cache '$self' data corrupted; " . | |||||||||||||||||||||||||||
| 19 | "value for '$file' should not be '$entry'"); | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 17 | my $time = time(); | |||||||||||||||||||||||||||
| 23 | 17 | ▶ | if ( $entry->[LAST_CHECK] < $time ) { # don't check more than once per second | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 2 | my $current_age = -M $file; | |||||||||||||||||||||||||||
| 25 | 2 | ▶ | if ( $entry->[AGE] > $current_age ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 2 | @$entry = ( 0, 0, undef ); # file has changed; cache invalid | |||||||||||||||||||||||||||
| 27 | 2 | return; | |||||||||||||||||||||||||||
| 28 | } else { | ||||||||||||||||||||||||||||
| 29 | 0 | $entry->[LAST_CHECK] = $time; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 15 | return $entry->[VALUE]; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 11 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 11 | my ($self, $file, $sub) = @_; | |||||||||||||||||||||||||||
| 37 | 11 | $self->SUPER::set( $file => [ time(), -M $file, $sub ] ); | |||||||||||||||||||||||||||
| 38 | 11 | return $sub; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ###################################################################### | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||