| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | try | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_one: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_two: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_three: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_four: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | ▶ | if (time - $start < $expires_in) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->skip( '$fetched_value eq $value (not finished in ' . | |||||||||||||||||||||||||||||||||||||||||
| 181 | $expires_in . ' s)' ); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | my $fetched_expired_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | ▶ | ( not defined $fetched_expired_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # Test that caches make deep copies of values | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub _test_five | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_five: called CC=5 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | my @value_list = ( 'One', 'Two', 'Three' ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | $cache->set( $key, \@value_list ); | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | @value_list = ( ); | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | my $fetched_value_list_ref = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 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"
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | ( $fetched_value_list_ref->[1] eq 'Two' ) and | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ( $fetched_value_list_ref->[2] eq 'Three' ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | $self->ok( ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | else | ||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->not_ok( 'fetched deep list does not match set deep list' ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # Test clearing a cache | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | sub _test_six | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_six: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | $cache->clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my $fetched_cleared_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | ▶ | ( not defined $fetched_cleared_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | $self->ok( ) : $self->not_ok( 'not defined $fetched_cleared_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | # Test sizing of the cache | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | sub _test_seven | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_seven: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | my $empty_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | my $first_key = 'First Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | $cache->set( $first_key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 4 | my $first_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 4 | ▶ | ( $first_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | $self->ok( ) : $self->not_ok( '$first_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | my $second_key = 'Second Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | $cache->set( $second_key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | my $second_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | ( $second_size > $first_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | $self->ok( ) : $self->not_ok( '$second_size > $first_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | # Test purging the cache | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | sub _test_eight | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_eight: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | $cache->clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | my $empty_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | my $pre_purge_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | $cache->purge( ); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 4 | my $post_purge_size = $cache->size( ); | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | ▶ | ( $post_purge_size == $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | $self->ok( ) : $self->not_ok( '$post_purge_size == $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # Test the getting, setting, and removal of a scalar across cache instances | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | sub _test_nine | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_nine: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 4 | my ( $self, $cache1 ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 4 | ▶ | $cache1 or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 4 | ▶ | my $cache2 = $cache1->new( ) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | croak( "Couldn't construct new cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 4 | $cache1->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | my $fetched_value = $cache2->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | # Test Clear() and Size() as instance methods | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | sub _test_ten | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_ten: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 4 | ▶ | $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | croak( "cache required" ); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | my $full_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | ▶ | ( $full_size > 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | $self->ok( ) : $self->not_ok( '$full_size > 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | # Test Purge(), Clear(), and Size() as instance methods | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | sub _test_eleven | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_eleven: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | my $pre_purge_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | $cache->Purge( ); | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 4 | my $purged_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 4 | ▶ | ( not defined $purged_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | $self->ok( ) : $self->not_ok( 'not defined $purged_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | # Test Purge(), Clear(), and Size() as static methods | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | sub _test_twelve | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_twelve: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 4 | ▶ | my $class = ref $cache or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | croak( "Couldn't get ref \$cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 4 | &{"${class}::Clear"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 4 | my $empty_size = &{"${class}::Size"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | my $pre_purge_size = &{"${class}::Size"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 4 | ▶ | ( $pre_purge_size > $empty_size ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | $self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | &{"${class}::Purge"}( ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 4 | my $purged_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 4 | ▶ | ( not defined $purged_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | $self->ok( ) : $self->not_ok( 'not defined $purged_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | # Test the expiration of an object with extended syntax | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | sub _test_thirteen | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_thirteen: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | ▶ | if (time - $start < $expires_in) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $self->skip( '$fetched_value eq $value (not finished in ' . | |||||||||||||||||||||||||||||||||||||||||
| 479 | $expires_in . ' s)' ); | ||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | my $fetched_expired_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | ▶ | ( not defined $fetched_expired_value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # test the get_keys method | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | sub _test_fourteen | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_fourteen: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | my $empty_size = $cache->Size( ); | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | ▶ | ( $empty_size == 0 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | $self->ok( ) : $self->not_ok( '$empty_size == 0' ); | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 4 | my @keys = sort ( 'John', 'Paul', 'Ringo', 'George' ); | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | foreach my $key ( @keys ) | |||||||||||||||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 16 | $cache->set( $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 4 | my @cached_keys = sort $cache->get_keys( ); | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 4 | my $arrays_equal = Arrays_Are_Equal( \@keys, \@cached_keys ); | |||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | ▶ | ( $arrays_equal == 1 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | $self->ok( ) : $self->not_ok( '$arrays_equal == 1' ); | ||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | # test the auto_purge on set functionality | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | sub _test_fifteen | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_fifteen: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 4 | $cache->set_auto_purge_interval( $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 4 | $cache->set_auto_purge_on_set( 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 4 | my $key = 'Test Key'; | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 4 | my $value = 'Test Value'; | |||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 4 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 4 | $cache->set( $key, $value, $expires_in ); | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 4 | my $fetched_value = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 4 | ▶ | if (time - $start < $expires_in) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 4 | ▶ | ( $fetched_value eq $value ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | $self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); | ||||||||||||||||||||||||||||||||||||||||||
| 548 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $self->skip( '$fetched_value eq $value (not finished in ' . | |||||||||||||||||||||||||||||||||||||||||
| 550 | $expires_in . ' s)' ); | ||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 4 | sleep( $EXPIRES_DELAY + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | $cache->set( "Trigger auto_purge", "Empty" ); | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | my $fetched_expired_object = $cache->get_object( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 4 | ▶ | ( not defined $fetched_expired_object ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | $self->ok( ) : $self->not_ok( 'not defined $fetched_expired_object' ); | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | # test the auto_purge_interval functionality | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | sub _test_sixteen | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_sixteen: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 4 | my $expires_in = $EXPIRES_DELAY; | |||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 4 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 576 | 4 | $cache = $cache->new( { 'auto_purge_interval' => $expires_in } ); | |||||||||||||||||||||||||||||||||||||||||
| 577 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 578 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 4 | ▶ | $ok ? $self->ok( ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | : $self->not_ok( "couldn't create autopurge cache" ); | ||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | # test the get_namespaces method | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | sub _test_seventeen | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_seventeen: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 4 | my ( $self, $cache ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 4 | $cache->set( 'a', '1' ); | |||||||||||||||||||||||||||||||||||||||||
| 592 | 4 | $cache->set_namespace( 'namespace' ); | |||||||||||||||||||||||||||||||||||||||||
| 593 | 4 | $cache->set( 'b', '2' ); | |||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | ▶ | if ( Arrays_Are_Equal( [ sort( $cache->get_namespaces( ) ) ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | [ sort( 'Default', 'namespace' ) ] ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 597 | { | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | $self->ok( ); | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | else | ||||||||||||||||||||||||||||||||||||||||||
| 601 | { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $self->not_ok( "get_namespaces returned the wrong namespaces" ); | |||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 4 | $cache->Clear( ); | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | sub Arrays_Are_Equal | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Arrays_Are_Equal: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 8 | my ( $first_array_ref, $second_array_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 8 | local $^W = 0; # silence spurious -w undef complaints | |||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 8 | ▶ | return 0 unless @$first_array_ref == @$second_array_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 8 | ▶ | for (my $i = 0; $i < @$first_array_ref; $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | { | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 24 | ▶ | return 0 if $first_array_ref->[$i] ne $second_array_ref->[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | __END__ | ||||||||||||||||||||||||||||||||||||||||||