Actually, while working on Exporter::VA I discovered that it does in fact work. Taking the reference early defines a place-holder for it, and later defining it fills in that place holder. Taking a reference to the thing after it's been defined properly gives the same reference as taking such a reference "too early".
What you can't do is call baz from the begin block. But you can certainly stash away a reference to it for later.BEGIN { print \&baz, "\n" } sub baz {} print \&baz;
I do exactly that in Exporter::VA. The import function can see a ref as a parameter, even though the implicit BEGIN block is causing this to run before the thing exists. To make this work well, at import() time it only remembers the reference, and does not try to update the contents (its changes will be clobbered by your initialization later) or rely on it being set-up just yet. Later, a function that import() put into my package is executed, and it can refer to that reference now.
So, you need to make your use statement just set-up, and "commit" the action later. In this case, sticking an END block into the calling package might do the trick.
—John
In reply to Re: Code references as use() parameters
by John M. Dlugosz
in thread Code references as use() parameters
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |