Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Why does Capture::Tiny require loading via BEGIN to successfully function?by Anonymous Monk |
on Nov 10, 2010 at 00:44 UTC ( [id://870447]=note: print w/replies, xml ) | Need Help?? |
I disagree that this module's code is straightforward. I couldn't actually find the capture sub in that module at a glance -- the author redefines *_debug at run time, for instance, which hints at the possibility for obfuscation-like complexity).
However, what appears to be happening is that it's doing something to change parsing rules at compile time. This can be done with a function prototype, like sub foo (&) {}, which is how you create functions that act like builtins such as map and grep. What this means is that when you require it at run time, that compile-time code isn't executed, so the magic of capture BLOCK isn't applied. Instead, you need to use capture( CODEREF ). Look at this:
Upshot: without the compile-time-added syntax sugar, you need to call this sub like capture($coderef);.
In Section
Seekers of Perl Wisdom
|
|