I am working on a module and set of tools for injecting run-time generated source into a file at compile time. It currently does this by using Filter::Util::Call to hook into the compilation process, inject the new code before the next line that perl will compile, and then remove itself handing control back to the compiler. It never attempts to parse or filter Perl source code at all.
I have decided to name this module `here.pm` after receiving feedback from module-authors. [1]
use here 'my $x = 1';
use here return_value_of_some_sub(...);
Since `use here ...;` forms a decent English sentence describing the what perl will do with the new source.
While not a pragmatic module in and of itself, the primary usage is to insert declarations and other code elements that are otherwise impossible to import (package declarations, my/our lexical declarations, ...). So due to this behavior, a lowercase name seems appropriate.
The overall goal of the module is to allow people to write a macro function:
sub my_0 {map "my \$$_ = 0", @_}
And then be able to write:
use here my_0 qw(x y z);
And have the compiler see `my $x = 0; my $y = 0; my $z = 0;` without a block or anything else implicitly surrounding the code.
These macro functions can of course be of any complexity, but their scope is limited to the supplied arguments, and not to the source file at large, as would be the case with a normal source filter.
One of the example macros that will ship with the module will allow you to write the following without repeating the variable names:
my ($one, $two);
BEGIN {
($one, $two) = qw(one two);
}
use here MY [qw($one $two)] => [qw(one two)];
or
use here MY qw($one one $two two);
I have a fully written module with a decent test suite ready to upload
once the name is approved.
Thanks for your time,
Eric Strom
asg@cpan.org
https://metacpan.org/author/ASG
[1] http://www.nntp.perl.org/group/perl.module-authors/2011/11/msg9417.html
Thread Next