Is there a way to bundle wallets in Perl?

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.

+8
perl tie perl-stash
source share
2 answers

You get into an internal compile-time error ("Bad symbol for scalar"), this happens when Perl tries to determine what should be "$ Target :: x", which you can check by running Perl debugging with:

 perl -DT foo.pl ... ### 14:LEX_NORMAL/XOPERATOR ";\n" ### Pending identifier '$Target::x' Bad symbol for scalar at foo.pl line 14. 

I think the GV for ':: Target' is replaced by something else when you bind () it so that everything that ultimately tries to get to its internal hash cannot. Given that tie () is a bit of a mess, I suspect what you are trying to do will not work, which is also suggested by this (old) set of exchanges for p5p:

https://groups.google.com/group/perl.perl5.porters/browse_thread/thread/f93da6bde02a91c0/ba43854e3c59a744?hl=en&ie= UTF-8 & d = Perl + tie + cache # ba43854e3c59a744

+4
source share

A little late to the question, but although it is impossible to use to do this, Variable :: Magic allows you to apply magic to your wallet and thereby achieve something similar.

+1
source share

All Articles