| 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 |  |  |  |  | 118 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # Array field names | 
| 7 | 4 |  |  | 4 |  | 19 | use constant LAST_CHECK => 0; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 331 |  | 
| 8 | 4 |  |  | 4 |  | 23 | use constant AGE        => 1; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 166 |  | 
| 9 | 4 |  |  | 4 |  | 21 | use constant VALUE      => 2; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 964 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | ###################################################################### | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub get { | 
| 14 | 26 |  |  | 26 | 1 | 37 | my ( $self, $file ) = @_; | 
| 15 | 26 | 100 |  |  |  | 60 | my $entry = $self->SUPER::get( $file ) | 
| 16 |  |  |  |  |  |  | or return; | 
| 17 | 17 | 50 | 33 |  |  | 74 | 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 |  |  |  |  | 25 | my $time = time(); | 
| 23 | 17 | 100 |  |  |  | 32 | if ( $entry->[LAST_CHECK] < $time ) { # don't check more than once per second | 
| 24 | 2 |  |  |  |  | 26 | my $current_age = -M $file; | 
| 25 | 2 | 50 |  |  |  | 11 | if ( $entry->[AGE] > $current_age ) { | 
| 26 | 2 |  |  |  |  | 33 | @$entry = ( 0, 0, undef ); # file has changed; cache invalid | 
| 27 | 2 |  |  |  |  | 11 | return; | 
| 28 |  |  |  |  |  |  | } else { | 
| 29 | 0 |  |  |  |  | 0 | $entry->[LAST_CHECK] = $time; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | } | 
| 32 | 15 |  |  |  |  | 45 | return $entry->[VALUE]; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub set { | 
| 36 | 11 |  |  | 11 | 1 | 80 | my ($self, $file, $sub) = @_; | 
| 37 | 11 |  |  |  |  | 197 | $self->SUPER::set( $file => [ time(), -M $file, $sub ] ); | 
| 38 | 11 |  |  |  |  | 62 | return $sub; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | ###################################################################### | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | 1; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | __END__ |