Can you hook the opening of the DATA handle for a module while Perl is still compiling? And by that I mean is there a way that I can insert code that will run after Perl has opened the DATA glob for reading but before the compilation phase has ceased.
Failing that, can you at least see the raw text after __DATA__ before the compiler opens it up?
In response to Ikegami, on recent scripts that I have been working on, I have been using __DATA__ section + YAML syntax to configure the script. I’ve also been building up a vocabulary of YAML configuration handlers where the behavior is requested by use-ing the modules. And in some scripts that are quick-n-dirty, but not quite enough to forgo strict, I wanted to see if I could expose variables from the YAML specification.
It’s been slightly annoying though just saving data in the import subs and then waiting for an INIT block to process the YAML. But it’s been doable.
I found out that
::STDINactually gives me access to the stream'-'. And that I can save the current location, throughtell( $inh )and thenseek()it when I’m done.By using that method, I could read the
__DATA__section in theimportsub!This worked on Strawberry Perl 5.16.2, so I don’t know how portable this is. But right now, to me, this is working.
Just a background. I used to do a bit of programming with Windows Script Files. One thing I liked about the wsf format was that you could specify globally useful objects outside of the code.
<object id="xl" progid="Application.Excel" />. I have always liked the look of programming by specification and letting some modular handler sort the data out. Now I can get a similar behavior through a YAML handler:excel: !ActiveX: Excel.Application.This works for me.
The test is here, in case you’re interested: