Similar to the AUTOLOAD method, which can be used to define routines on demand, I am wondering if there is a way to bundle a batch stamp so that I can intercept access to the variables in this batch.
I tried various permutations of the following idea, but no one works:
{package Tie::Stash; use Tie::Hash; BEGIN {our @ISA = 'Tie::StdHash'} sub FETCH { print "calling fetch\n"; } } {package Target} BEGIN {tie %Target::, 'Tie::Stash'} say $Target::x;
This dies with Bad symbol for scalar ... on the last line, without printing "calling fetch" . If the string say $Target::x; removed, the program starts and exits correctly.
My hunch is that the failure is related to stashes like, but not the same as hashes, so the standard binding mechanism does not work correctly (or it just might be that searching in stash never causes magic binding).
Does anyone know if this is possible? Pure Perl would be better, but XS solutions are fine.
perl tie perl-stash
Eric Strom
source share