No such thing as a small change | |
PerlMonks |
Using delete package::{subroutine} to change resolution of subroutinesby pjf (Curate) |
on Jun 22, 2008 at 05:09 UTC ( [id://693338]=perlquestion: print w/replies, xml ) | Need Help?? |
pjf has asked for the wisdom of the Perl Monks concerning the following question: Most learned monks, I'm currently working on my port of autodie (a lexical pragma for do-or-die semantics) to Perl 5.8. I've got a rather clever trick that allows me to change how perl resolves subroutines, but I'm starting to hit problems with its scalability. The trick looks like this:
The code above works wonderfully, and maps very well to what I'm doing in autodie when I'm either inserting a subroutine, or deleting a subroutine. Where it fails is when I'm trying to replace a subroutine that's already there. The reason is that each use of autodie maps to a single BEGIN block, and merging the two middle BEGIN blocks causes the trick to fail:
Unfortunately for me, this means that any operation that needs to replace a subroutine fails, since that involves a delete and an insert. Note that just trying to replace the sub without the magic delete trick doesn't help (Perl never resolves to the first sub declared). Nesting the BEGIN blocks works fine, but isn't useful for my purposes, since I'm playing with subroutine resolution at every import(), and a BEGIN inside my import() will only run once. So, does anyone have a trick, that works on Perl 5.8, which allows a subroutine to be replaced with limited scope (as per my first example), but involves only a single BEGIN to do that replacement? This isn't something which comes up every day. ;) For those interested in learning more about autodie, I've been blogging about it, as well as having made a lightning talk about the idea. The code on CPAN currently works for all my core criteria, but it's the edges cases that are giving me the biggest headaches. Many many thanks in advance for all your help,
Paul Fenwick Perl Training Australia
Back to
Seekers of Perl Wisdom
|
|