[Chicago-talk] Tie::StdHash, db and FETCH

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Fri May 12 13:49:39 PDT 2006


Okay,  I'm looking at some code here and, they tie a global hash to Site 
object.  The Site.pm 
package Site;
use strict;
use Tie::Hash;
use vars qw(@ISA);
@ISA = qw(Tie::StdHash);

defines 6 routines:
  STORE
  FETCH
  EXISTS
  DEFINED
  GetSiteValue
  InitDbKeyRefs

Fetch does:
sub FETCH {
  my ($self, $key) = @_;
  if($self->{$key} eq "") {
    GetSiteValue($self,$key);
  }
  return $self->{$key};
}

GetSite:
sub GetSiteValue
{
  my ($self, $key) = @_;
  if($self->{DbKeyRefs} eq "") {
    InitDbKeyRefs($self);
  }
... [ fetch $key from db if its in DbKeyRefs ]

InitDbKeyRefs installs an entry DbKeyRefs
    $self->{DbKeyRefs} =  main::unload("site_code","site","");

w/ all the site table key fields.  So, each cgi script starts by tie the 
global hash to Site:
our %Global_Site;
tie %Global_Site, 'Site';

and then can use
$Global_Site{BG_Color}  etc. to ref site table entry data.

But it seems like we end up calling that InitDbKeyRefs an awful lot and 
I'm not sure there's not some sort of recursiveness sneaking in there. 
Both DEFINED/EXISTS are just:
sub EXISTS {
  my ($self, $key) = @_;
  return exists $self->{$key};
}

sub DEFINED {
  my ($self, $key) = @_;
  return defined $self->{$key};
}

but the line:
  if($self->{DbKeyRefs} eq "") {

fails a lot.  Now this is a working prog and little hard to test, so I'm 
asking if this seems wrong.  I'm also wondering if adding a TIEHASH method 
that initialized that 'DbKeyRefs' element might be an improvement.

Thanks for any hints.  As usual, sorry its so scattershot.

a

Andy Bach, Sys. Mangler
Internet: andy_bach at wiwb.uscourts.gov 
VOICE: (608) 261-5738  FAX 264-5932

It was really tempting to name the program "sex" (for either "Smart  EXec" 
 or
"Send-EXpect"), but good sense (or perhaps just Puritanism) prevailed.
Don Libes - on naming "Expect"


More information about the Chicago-talk mailing list