abaxaba has asked for the wisdom of the Perl Monks concerning the following question:

How would I go about (either via tie or straight object instantiation) creating a BerekelyDB::Hash variable during PerlChildInitHandler, and then access it during PerlTransHandler? To Wit, my latest attempt:
in httpd.conf PerlSetVar streamDB "/adconfig/config" PerlSetVar clickDB "/adconfig/click" PerlChildInitHandler Config PerlTransHandler Serve
in Config.pm sub handler { my $r=shift; my $config=$r->dir_config('streamDB'); my $click=$r->dir_config('clickDB'); %CORE::GLOBAL::config = new BerkeleyDB::Hash -Filename => $config, -Flags => "DB_RDONLY" or die "Cannot open file $config: $!$BerkleleyDB::Error\n"; }
In Serve.pm sub handler { my $r=shift; unless (scalar(keys %CORE::GLOBAL::config)) { die ("no config data loaded"); } # Code Always dies }
I've got the requisite use statments and such in Config.pm, and have tried tied hashes, stashing hashrefs in pnotes and untied hashes, and am now at the end of my rope. Any thoughts?

ÅßÅ×ÅßÅ
"It is a very mixed blessing to be brought back from the dead." -- Kurt Vonnegut

Replies are listed 'Best First'.
Re: Berkeley Access through Apache request phases
by bageler (Hermit) on Aug 03, 2004 at 05:51 UTC
    I did this successfully between a content handler and a cleanup handler, the major difference is that I have both handlers in the same package thusly:
    sub conthandler { $r = shift; tie %CORE::GLOBAL::testdb, 'BerkeleyDB::Hash', -Filename => 'testdb', -Flags => 'DB_RDONLY' or die "cannot open bdb $!$BerkleleyDB::Error"; print join ',',keys %CORE::GLOBAL::testdb; $r->register_cleanup(\&cleanuphandler); } sub cleanuphandler { my $r = shift; die unless scalar keys %CORE::GLOBAL::testdb; # doesn't die }
Re: Berkeley Access through Apache request phases
by perrin (Chancellor) on Aug 03, 2004 at 15:39 UTC
    Putting it in CORE::GLOBAL:: isn't a very good idea. What was wrong with pnotes? That should work fine for this.
      post a working example for the OP? Obviously he couldn't get it to work.