| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Text::MicroMason::Cache::File; | 
| 2 |  |  |  |  |  |  | @ISA = 'Text::MicroMason::Cache::Simple'; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 4 |  |  | 4 |  | 24 | use strict; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 125 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # Array field names | 
| 7 | 4 |  |  | 4 |  | 20 | use constant LAST_CHECK => 0; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 327 |  | 
| 8 | 4 |  |  | 4 |  | 24 | use constant AGE        => 1; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 164 |  | 
| 9 | 4 |  |  | 4 |  | 21 | use constant VALUE      => 2; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 1141 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | ###################################################################### | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub get { | 
| 14 | 26 |  |  | 26 | 1 | 54 | my ( $self, $file ) = @_; | 
| 15 | 26 | 100 |  |  |  | 70 | my $entry = $self->SUPER::get( $file ) | 
| 16 |  |  |  |  |  |  | or return; | 
| 17 | 17 | 50 | 33 |  |  | 85 | unless (ref($entry) eq 'ARRAY' and @$entry == 3 ) { | 
| 18 | 0 |  |  |  |  | 0 | Carp::croak("MicroMason: cache '$self' data corrupted; " . | 
| 19 |  |  |  |  |  |  | "value for '$file' should not be '$entry'"); | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 17 |  |  |  |  | 29 | my $time = time(); | 
| 23 | 17 | 100 |  |  |  | 41 | if ( $entry->[LAST_CHECK] < $time ) { # don't check more than once per second | 
| 24 | 2 |  |  |  |  | 29 | my $current_age = -M $file; | 
| 25 | 2 | 50 |  |  |  | 12 | if ( $entry->[AGE] > $current_age ) { | 
| 26 | 2 |  |  |  |  | 42 | @$entry = ( 0, 0, undef ); # file has changed; cache invalid | 
| 27 | 2 |  |  |  |  | 15 | return; | 
| 28 |  |  |  |  |  |  | } else { | 
| 29 | 0 |  |  |  |  | 0 | $entry->[LAST_CHECK] = $time; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | } | 
| 32 | 15 |  |  |  |  | 71 | return $entry->[VALUE]; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub set { | 
| 36 | 11 |  |  | 11 | 1 | 85 | my ($self, $file, $sub) = @_; | 
| 37 | 11 |  |  |  |  | 210 | $self->SUPER::set( $file => [ time(), -M $file, $sub ] ); | 
| 38 | 11 |  |  |  |  | 57 | return $sub; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | ###################################################################### | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | 1; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | __END__ |