| 1 | # Apache::XPP::Cache | ||||||||||||||||||||
| 2 | # -------------------- | ||||||||||||||||||||
| 3 | # $Revision: 1.9 $ | ||||||||||||||||||||
| 4 | # $Date: 2002/01/16 21:06:01 $ | ||||||||||||||||||||
| 5 | #----------------------------- | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | Apache::XPP::Cache - XPP Cache manegment module | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | package Apache::XPP::Cache; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | use Apache::XPP::Cache; | ||||||||||||||||||||
| 18 | $cache = Apache::XPP::Cache->new( %options ); | ||||||||||||||||||||
| 19 | $cache = Apache::XPP::Cache->is_cached( %options ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 REQUIRES | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | Apache::XPP | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 3 | ▶ | use vars qw( $debug $debuglines ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 3 | $Apache::XPP::Cache::REVISION = (qw$Revision: 1.9 $)[-1]; | |||||||||||||||||||
| 33 | 3 | $Apache::XPP::Cache::VERSION = '2.01'; | |||||||||||||||||||
| 34 | 3 | $debug = undef; | |||||||||||||||||||
| 35 | 3 | $debuglines = 1; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 EXPORTS | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | Nothing | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Apache::XPP::Cache is an interface to both Store and Expire caching modules. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 METHODS | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =over | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =item new( $name, $group, \%instance_data, [ $storetype, @store_options ], [ $expiretype, @expire_options ] ) | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | Creates a new Cache object using the specified Store and Expire types. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||
| 57 | {# BEGIN PRIVATE CODE BLOCK | ||||||||||||||||||||
| 58 | 3 | my %cache; | |||||||||||||||||||
| 59 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||
| 60 | # Apache::XPP::Cache->new( 're4sidebar', 'games', { r => $r }, [ 'File', $content ], [ 'Duration', '2h' ] ); | ||||||||||||||||||||
| 61 | 0 | my $proto = shift; | |||||||||||||||||||
| 62 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 63 | 0 | my $name = shift; | |||||||||||||||||||
| 64 | 0 | my $group = shift; | |||||||||||||||||||
| 65 | 0 | my $instance = shift; | |||||||||||||||||||
| 66 | 0 | my $self; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | my $specifier = unpack("%32C*", $name . $group) % 65535; | |||||||||||||||||||
| 69 | 0 | ▶ | if ($cache{ $specifier }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | ▶ | warn "cache: using cached object (in new)" . ($debuglines ? '' : "\n") if ($debug); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 71 | 0 | $self = $cache{ $specifier }; | |||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||
| 73 | 0 | ▶ | warn "cache: creating new object (in new)" . ($debuglines ? '' : "\n") if ($debug); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 74 | 0 | my $store = shift; | |||||||||||||||||||
| 75 | 0 | my $expire = shift; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | $self = bless( { %{ ref($instance) ? $instance : {} } }, $class ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | foreach my $part ( {Store => $store}, {Expire => $expire} ) { | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | my ($label, $inputs) = %{$part}; | |||||||||||||||||||
| 82 | 0 | my $type = shift( @{ $inputs } ); | |||||||||||||||||||
| 83 | 0 | ▶ | if (my $thisclass = $class->install_module( (($label eq 'Expire') ? 'Expiry' : $label), $type )) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 84 | 0 | my $obj = $thisclass->new( $name, $group, { r => $self->r }, @{ $inputs } ); | |||||||||||||||||||
| 85 | 0 | ▶ | if (ref($obj)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | my $meth = $label . 'Type'; | |||||||||||||||||||
| 87 | 0 | $self->$meth( $type ); # StoreType/ExpireType | |||||||||||||||||||
| 88 | 0 | $meth = $label . 'Object'; | |||||||||||||||||||
| 89 | 0 | $self->$meth( $obj ); # StoreObject/ExpireObject | |||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||
| 91 | 0 | return undef; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||
| 94 | 0 | carp "Specified $label type ($type) is not registered as available!"; | |||||||||||||||||||
| 95 | 0 | return undef; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | $cache{ $specifier } = $self; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | } # END constructor new | ||||||||||||||||||||
| 103 | } # END private code block for %cache | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =item C<install_module> ( ('Store'|'Expiry'), $name ) | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | Installs the $name store or expiry module, and returns the associated class name. | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||
| 110 | 3 | ▶ | sub install_module { # shamelessly snagged from DBI | ||||||||||||||||||
|
Subroutine
install_module: not called CC=4 SCAR=28.7
Pod
documented
| |||||||||||||||||||||
| 111 | 0 | my $class = shift; | |||||||||||||||||||
| 112 | 0 | my $type = shift; | |||||||||||||||||||
| 113 | 0 | my $name = shift; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | $type = 'Expiry' unless ($type eq 'Store'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 0 | my $mod; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | # already installed | ||||||||||||||||||||
| 119 | 0 | ▶ | return $mod if ($mod = $Apache::XPP::installed{ $type }{ $name }); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | # --- load the code | ||||||||||||||||||||
| 122 | 0 | $mod = "Apache::XPP::Cache::${type}::${name}"; | |||||||||||||||||||
| 123 | 0 | eval "package Apache::XPP::Cache::_firesafe; require $mod"; | |||||||||||||||||||
| 124 | 0 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 0 | warn "require of ($mod) failed! $@"; | |||||||||||||||||||
| 126 | 0 | return undef; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | $Apache::XPP::installed{ $type }{ $name } = $mod; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | sub store { | ||||||||||||||||||
|
Subroutine
store: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||
| 134 | 0 | ▶ | return undef unless ref($self); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | 0 | return $self->{ 'StoreObject' }; | |||||||||||||||||||
| 136 | } # END method store | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | ▶ | sub expire { | ||||||||||||||||||
|
Subroutine
expire: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||
| 140 | 0 | ▶ | return undef unless ref($self); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | 0 | return $self->{ 'ExpireObject' }; | |||||||||||||||||||
| 142 | } # END method expire | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =item C<is_expired> ( ) | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | Returns a true value if the current cache has expired, otherwise returns false. | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||
| 150 | 0 | ▶ | sub is_expired { | ||||||||||||||||||
|
Subroutine
is_expired: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||
| 152 | 0 | ▶ | return undef unless ref($self); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | 0 | ▶ | if ($self->expire->is_expired( $self->store )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 0 | $self->store->is_expired; | |||||||||||||||||||
| 155 | 0 | return 1; | |||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||
| 157 | 0 | return 0; | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | } # END method is_expired | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =item C<content> ( ) | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | Returns the content of the current cache. | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||
| 166 | 0 | ▶ | sub content { | ||||||||||||||||||
|
Subroutine
content: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||
| 168 | 0 | ▶ | return ref($self) ? $self->store->content : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | } # END method content | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =item C<r> ( ) | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | Returns the Apache request object | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||
| 177 | 3 | *r = \&{ "Apache::XPP::r" }; | |||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =item C<AUTOLOAD> ( ) | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | Calling $obj->meth() returns $obj->{'meth'}. | ||||||||||||||||||||
| 182 | Calling $obj->meth($val) sets $obj->{'meth'} = $val. | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 3 | *AUTOLOAD = \&{ "Apache::XPP::AUTOLOAD" }; | |||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 3 | 1; | |||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||