sub deep_exists { my ($key, $data) = @_; warn " Cache miss on exist key ($key) for ". $data->{container}{type} ." object\n"; return undef; } #### sub EXISTS { my ($a,$key) = (shift, shift); # STEP 1 return 1 if exists $a->[0]{$key}; # Have data # STEP 2 my $cache = $a->[1]{$key}; return $cache if defined $cache; # Existence cache # STEP 3 my @res = $a->[3]($key,$a->[4]); $_[0][1]{$key} = 0, return unless @res; # Cache non-existence # STEP 4 # Now we know it exists return ($_[0][1]{$key} = 1) if $a->[5]; # Only existence reported # STEP 5 # Now know the value $_[0][0]{$key} = $res[0]; # Store data return 1 } #### The structure of the tied() data is an array reference with elements 0: cache of known values 1: cache of known existence of keys 2: FETCH function 3: EXISTS function 4: $data #### my @res = $a->[3]($key,$a->[4]); $_[0][1]{$key} = 0, return unless @res;