XPP/Cache.pm

filter: Statementstmt 25.6% 20 / 78 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 4 / 10 Podpod 66.6% 4 / 6 totaltotal 21.0% 28 / 133 CC 20 SCAR 42.4
CC
20
Cov
17%
new
156.0
install_module
17.6
is_expired
12.0
CRAP 69.6
« XPP.pm ↑ Summary XPP/Cache/Store/File.pm »
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
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($cache{$specifier}) { } 0 0 0
70 0 ▶ warn "cache: using cached object (in new)" . ($debuglines ? '' : "\n") if ($debug);
Branch: 2 branches
BranchTrueFalseTotal
if $Apache::XPP::Cache::debug 0 0 0
$Apache::XPP::Cache::debuglines ? : 0 0 0
71 0 $self = $cache{ $specifier };
72 } else {
73 0 ▶ warn "cache: creating new object (in new)" . ($debuglines ? '' : "\n") if ($debug);
Branch: 2 branches
BranchTrueFalseTotal
if $Apache::XPP::Cache::debug 0 0 0
$Apache::XPP::Cache::debuglines ? : 0 0 0
74 0 my $store = shift;
75 0 my $expire = shift;
76  
77 0 ▶ $self = bless( { %{ ref($instance) ? $instance : {} } }, $class );
Branch: 1 branch
BranchTrueFalseTotal
ref $instance ? : 0 0 0
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
BranchTrueFalseTotal
if (my $thisclass = $class->install_module($label eq 'Expire' ? 'Expiry' : $label, $type)) { } 0 0 0
$label eq 'Expire' ? : 0 0 0
84 0 my $obj = $thisclass->new( $name, $group, { r => $self->r }, @{ $inputs } );
85 0 ▶ if (ref($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj) { } 0 0 0
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
BranchTrueFalseTotal
unless $type eq "Store" 0 0 0
116 0 my $mod;
117
118 # already installed
119 0 ▶ return $mod if ($mod = $Apache::XPP::installed{ $type }{ $name });
Branch: 1 branch
BranchTrueFalseTotal
if $mod = $Apache::XPP::installed{$type}{$name} 0 0 0
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
BranchTrueFalseTotal
if ($@) 0 0 0
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
BranchTrueFalseTotal
unless ref $self 0 0 0
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
BranchTrueFalseTotal
unless ref $self 0 0 0
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
BranchTrueFalseTotal
unless ref $self 0 0 0
153 0 ▶ if ($self->expire->is_expired( $self->store )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expire->is_expired($self->store)) { } 0 0 0
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
BranchTrueFalseTotal
ref $self ? : 0 0 0
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__
« XPP.pm ↑ Summary XPP/Cache/Store/File.pm »