| 1 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: CacheTester.pm,v 1.20 2002/04/07 17:04:46 dclinton Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2001-2003 DeWitt Clinton All Rights Reserved | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Software distributed under the License is distributed on an "AS | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # implied. See the License for the specific language governing | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # rights and limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Cache::CacheTester; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Cache::BaseCacheTester; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Cache::Cache; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Error qw( :try ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use vars qw( @ISA $EXPIRES_DELAY ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | @ISA = qw ( Cache::BaseCacheTester ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | $EXPIRES_DELAY = 2; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | $Error::Debug = 1; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub test | ||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | try | ||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | $cache->Clear( ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | $self->_test_one( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | $self->_test_two( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | $self->_test_three( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | $self->_test_four( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | $self->_test_five( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | $self->_test_six( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | $self->_test_seven( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | $self->_test_eight( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | $self->_test_nine( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | $self->_test_ten( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | $self->_test_eleven( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | $self->_test_twelve( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | $self->_test_thirteen( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | $self->_test_fourteen( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | $self->_test_fifteen( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | $self->_test_sixteen( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | $self->_test_seventeen( $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | catch Error with | ||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $error = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | print STDERR "\nError:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | print STDERR $error->stringify( ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | print STDERR $error->stacktrace( ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | } | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # Test the getting, setting, and removal of a scalar | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _test_one | ||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_one: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | $cache->remove( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my $fetched_removed_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | ( not defined $fetched_removed_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | $self->ok( ) : $self->not_ok( 'not defined $fetched_removed_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Test the getting, setting, and removal of a list | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub _test_two | ||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_two: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | my @value_list = ( 'One', 'Two', 'Three' ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | $cache->set( $key, \@value_list ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my $fetched_value_list_ref = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | ▶ | if ( ( $fetched_value_list_ref->[0] eq 'One' ) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two" and $fetched_value_list_ref->[2] eq "Three"
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two"
MC/DC0%0/3
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two" and $fetched_value_list_ref->[2] eq "Three"
$fetched_value_list_ref->[0] eq "One"
$fetched_value_list_ref->[1] eq "Two"
$fetched_value_list_ref->[2] eq "Three"
Truth table25%1/4
A and B and C
A= $fetched_value_list_ref->[0] eq "One"B= $fetched_value_list_ref->[1] eq "Two"C= $fetched_value_list_ref->[2] eq "Three"
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | ( $fetched_value_list_ref->[1] eq 'Two' ) and | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ( $fetched_value_list_ref->[2] eq 'Three' ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | $self->ok( ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | else | ||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->not_ok( 'fetched list does not match set list' ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | $cache->remove( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | my $fetched_removed_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | ( not defined $fetched_removed_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | $self->ok( ) : $self->not_ok( 'not defined $fetched_removed_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # Test the getting, setting, and removal of a blessed object | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | sub _test_three | ||||||||||||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_three: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | my $cache_key = 'Cache Key'; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | $cache->set( $cache_key, $cache ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | my $fetched_cache = $cache->get( $cache_key ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | ( defined $fetched_cache ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | $self->ok( ) : $self->not_ok( 'defined $fetched_cache' ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | my $fetched_value = $fetched_cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | # Test the expiration of an object | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | sub _test_four | ||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_four: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | my $fetched_expired_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | ( not defined $fetched_expired_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # Test that caches make deep copies of values | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | sub _test_five | ||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_five: called CC=5 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | my @value_list = ( 'One', 'Two', 'Three' ); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | $cache->set( $key, \@value_list ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | @value_list = ( ); | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | my $fetched_value_list_ref = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | ▶ | if ( ( $fetched_value_list_ref->[0] eq 'One' ) and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two" and $fetched_value_list_ref->[2] eq "Three"
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two"
MC/DC0%0/3
$fetched_value_list_ref->[0] eq "One" and $fetched_value_list_ref->[1] eq "Two" and $fetched_value_list_ref->[2] eq "Three"
$fetched_value_list_ref->[0] eq "One"
$fetched_value_list_ref->[1] eq "Two"
$fetched_value_list_ref->[2] eq "Three"
Truth table25%1/4
A and B and C
A= $fetched_value_list_ref->[0] eq "One"B= $fetched_value_list_ref->[1] eq "Two"C= $fetched_value_list_ref->[2] eq "Three"
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | ( $fetched_value_list_ref->[1] eq 'Two' ) and | ||||||||||||||||||||||||||||||||||||||||||
| 209 | ( $fetched_value_list_ref->[2] eq 'Three' ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 210 | { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $self->ok( ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | else | ||||||||||||||||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->not_ok( 'fetched deep list does not match set deep list' ); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # Test clearing a cache | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | sub _test_six | ||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_six: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | $cache->clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | my $fetched_cleared_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | ( not defined $fetched_cleared_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | $self->ok( ) : $self->not_ok( 'not defined $fetched_cleared_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Test sizing of the cache | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | sub _test_seven | ||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_seven: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | my $empty_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | my $first_key = 'First Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | $cache->set( $first_key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | my $first_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | ▶ | ( $first_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | $self->ok( ) : $self->not_ok( '$first_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | my $second_key = 'Second Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | $cache->set( $second_key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 4 | my $second_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | ( $second_size > $first_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | $self->ok( ) : $self->not_ok( '$second_size > $first_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # Test purging the cache | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | sub _test_eight | ||||||||||||||||||||||||||||||||||||||||||
| 281 | { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_eight: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | $cache->clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | my $empty_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | my $pre_purge_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | $cache->purge( ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | my $post_purge_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | ▶ | ( $post_purge_size == $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | $self->ok( ) : $self->not_ok( '$post_purge_size == $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | # Test the getting, setting, and removal of a scalar across cache instances | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | sub _test_nine | ||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | ▶ | my ( $self, $cache1 ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_nine: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 4 | ▶ | $cache1 or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | ▶ | my $cache2 = $cache1->new( ) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | croak( "Couldn't construct new cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 4 | $cache1->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | my $fetched_value = $cache2->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # Test Clear() and Size() as instance methods | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | sub _test_ten | ||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_ten: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | my $full_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | ▶ | ( $full_size > 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | $self->ok( ) : $self->not_ok( '$full_size > 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | # Test Purge(), Clear(), and Size() as instance methods | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | sub _test_eleven | ||||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_eleven: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 4 | my $pre_purge_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 4 | $cache->Purge( ); | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 4 | my $purged_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | ▶ | ( not defined $purged_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | $self->ok( ) : $self->not_ok( 'not defined $purged_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | # Test Purge(), Clear(), and Size() as static methods | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | sub _test_twelve | ||||||||||||||||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_twelve: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 4 | ▶ | my $class = ref $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | croak( "Couldn't get ref \$cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 4 | &{"${class}::Clear"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | my $empty_size = &{"${class}::Size"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | my $pre_purge_size = &{"${class}::Size"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 4 | &{"${class}::Purge"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 4 | my $purged_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 4 | ▶ | ( not defined $purged_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | $self->ok( ) : $self->not_ok( 'not defined $purged_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | # Test the expiration of an object with extended syntax | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | sub _test_thirteen | ||||||||||||||||||||||||||||||||||||||||||
| 454 | { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_thirteen: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | my $fetched_expired_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | ▶ | ( not defined $fetched_expired_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | # test the get_keys method | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | sub _test_fourteen | ||||||||||||||||||||||||||||||||||||||||||
| 482 | { | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_fourteen: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | my @keys = sort ( 'John', 'Paul', 'Ringo', 'George' ); | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | foreach my $key ( @keys ) | |||||||||||||||||||||||||||||||||||||||||
| 497 | { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 16 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | my @cached_keys = sort $cache->get_keys( ); | |||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | my $arrays_equal = Arrays_Are_Equal( \@keys, \@cached_keys ); | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 4 | ▶ | ( $arrays_equal == 1 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | $self->ok( ) : $self->not_ok( '$arrays_equal == 1' ); | ||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | # test the auto_purge on set functionality | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | sub _test_fifteen | ||||||||||||||||||||||||||||||||||||||||||
| 513 | { | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_fifteen: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | $cache->set_auto_purge_interval( $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 4 | $cache->set_auto_purge_on_set( 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | 4 | $cache->set( "Trigger auto_purge", "Empty" ); | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 4 | my $fetched_expired_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 4 | ▶ | ( not defined $fetched_expired_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | # test the auto_purge_interval functionality | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | sub _test_sixteen | ||||||||||||||||||||||||||||||||||||||||||
| 552 | { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_sixteen: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 558 | 4 | $cache = $cache->new( { 'auto_purge_interval' => $expires_in } ); | |||||||||||||||||||||||||||||||||||||||||
| 559 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 560 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | ▶ | $ok ? $self->ok( ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | : $self->not_ok( "couldn't create autopurge cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | # test the get_namespaces method | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | sub _test_seventeen | ||||||||||||||||||||||||||||||||||||||||||
| 570 | { | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | ▶ | my ( $self, $cache ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_seventeen: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 4 | $cache->set( 'a', '1' ); | |||||||||||||||||||||||||||||||||||||||||
| 574 | 4 | $cache->set_namespace( 'namespace' ); | |||||||||||||||||||||||||||||||||||||||||
| 575 | 4 | $cache->set( 'b', '2' ); | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 4 | ▶ | if ( Arrays_Are_Equal( [ sort( $cache->get_namespaces( ) ) ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | [ sort( 'Default', 'namespace' ) ] ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 579 | { | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 4 | $self->ok( ); | |||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | else | ||||||||||||||||||||||||||||||||||||||||||
| 583 | { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->not_ok( "get_namespaces returned the wrong namespaces" ); | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | sub Arrays_Are_Equal | ||||||||||||||||||||||||||||||||||||||||||
| 593 | { | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 8 | ▶ | my ( $first_array_ref, $second_array_ref ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Arrays_Are_Equal: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 8 | local $^W = 0; # silence spurious -w undef complaints | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 8 | ▶ | return 0 unless @$first_array_ref == @$second_array_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 8 | ▶ | for (my $i = 0; $i < @$first_array_ref; $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 24 | ▶ | return 0 if $first_array_ref->[$i] ne $second_array_ref->[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | __END__ | ||||||||||||||||||||||||||||||||||||||||||