in reply to Why does Capture::Tiny require loading via BEGIN to successfully function?
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:
# perl -lwE "use Capture::Tiny (); say 'captured: ', Capture::Tiny::ca +pture { say 'foo' }" captured: foo
# perl -lwE "require Capture::Tiny; say 'captured: ', Capture::Tiny::c +apture { say 'foo' }" foo Can't call method "Capture::Tiny::capture" without a package or object + reference at -e line 1.
# perl -lwE "require Capture::Tiny; say 'captured: ', Capture::Tiny::c +apture(sub { say 'foo' })" captured: foo
Upshot: without the compile-time-added syntax sugar, you need to call this sub like capture($coderef);.
|
|---|