XPP/Cache/Expiry/Duration.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 84 CC 6 SCAR 26.6
CC
6
Cov
0%
new
30.0
is_expired
6.0
BEGIN
2.0
CRAP 14.3
1 # Apache::XPP::Cache::Expiry::Duration
2 # ----------------------------------------
3 # $Revision: 1.6 $
4 # $Date: 2002/01/16 21:06:01 $
5 #------------------------------------------------------------------
6  
7 =head1 NAME
8  
9 Apache::XPP::Cache::Expiry::Duration - Duration based cache expiry.
10  
11 =cut
12  
13 package Apache::XPP::Cache::Expiry::Duration;
14  
15 =head1 SYNOPSIS
16  
17 ...
18  
19 =head1 REQUIRES
20  
21 Apache::XPP::Cache::Expiry
22  
23 =cut
24  
25 use Carp;
26 use strict;
27 use Apache::XPP::Cache::Expiry;
28 use vars qw( @ISA $debug $debuglines );
29  
30 BEGIN {
31 @ISA = qw( Apache::XPP::Cache::Expiry );
32 $Apache::XPP::Cache::Expiry::Duration::REVISION = (qw$Revision: 1.6 $)[-1];
33 $Apache::XPP::Cache::Expiry::Duration::VERSION = '2.01';
34 $debug = undef;
35 $debuglines = 1;
36 }
37  
38 =head1 EXPORTS
39  
40 Nothing
41  
42 =head1 DESCRIPTION
43  
44 Apache::XPP::Cache::Expiry::Duration handles the expiring of caches based on a duration
45 of time on behalf of Apache::XPP::Cache.
46  
47 =head1 METHODS
48  
49 =over
50  
51 =item C<new> ( $name, $group, \%instance_data, $duration )
52  
53 Creates a new Duration expiry object. The contents of %instance_data will be placed in
54 the object as instance data (for Apache request object, etc.).
55  
56 =cut
57 { # BEGIN PRIVATE CODEBLOCK
58 my %multiplier = (
59 'y' => [365, 'd'],
60 'M' => [28, 'd'],
61 'w' => [7, 'd'],
62 'd' => [24, 'h'],
63 'h' => [60, 'm'],
64 'm' => [60, 's'],
65 's' => [1, 's']
66 );
67 sub new {
68 my $proto = shift;
69 my $class = ref($proto) || $proto;
70 my $name = shift;
71 my $group = shift;
72 my $instance = shift;
73
74 my $self = bless( { %{ ref($instance) ? $instance : {} } }, $class );
75
76 $self->name( $name );
77 $self->group( $group );
78
79 if (my $duration = shift) {
80 if ($duration =~ /^(\d+)$/) {
81 $self->duration( $duration );
82 } else {
83 return undef unless ($duration =~ /^([\d.]+)([yMwdhms])$/);
84 my ($multiple, $specifier) = ($1, $2);
85 while ($specifier ne 's') {
86 my $tmp = $multiplier{ $specifier };
87 $multiple *= $tmp->[0];
88 $specifier = $tmp->[1];
89 }
90
91 $self->duration( $multiple );
92 }
93 }
94
95 return $self;
96 } # END constructor new
97 } # END PRIVATE CODEBLOCK
98  
99 =item C<is_expired> ( $store_object )
100  
101 Returns TRUE if the cache (whose store is passed as an argument) has expired,
102 FALSE otherwise.
103  
104 =cut
105 sub is_expired {
106 my $self = shift;
107 my $class = ref($self) || return undef;
108 my $store = shift;
109
110 my $mtime = $store->mtime;
111 my $duration = $self->duration;
112
113 return (time > ($mtime + $duration)) ? 1 : 0;
114 } # END method is_expired
115  
116  
117  
118 1;
119  
120 __END__