develooper Front page | perl.module-authors | Postings from November 2011

Naming a module that injects new code into a file's source at compile time

Thread Next
From:
Eric Strom
Date:
November 1, 2011 14:28
Subject:
Naming a module that injects new code into a file's source at compile time
Message ID:
CAL-uHDniUPQyn+oo+RgUZqPmKcv7MyAsgds1OcXMRzt3XVCGEw@mail.gmail.com
I am working on a module and set of tools for injecting source into
another 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.

I have tentatively named this module `eval.pm`

   use eval 'my $x = 1';

   use eval some_sub(...);

since `use` implies compile time and it is injecting the source into
the currently compiling `eval`.

but I am considering any of the following names:

   eval         (my preference)
   insert
   inject
   inline
   compile
   here

Since all of these names are single word/lowercase names, I wanted to
put the name up for the Perl community to comment on.

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 eval my_0 qw(x y z);

And have the compiler see `my $x = 0; my $y = 0; my $z = 0;`

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.

I have a fully written module with a decent test suite ready to upload
once the name is finalized.

This question was first posted to modules@perl.org, and Steffen
Mueller pointed me here.  This was the first posting:

    http://www.nntp.perl.org/group/perl.modules/2011/10/msg78203.html

Thanks for your time,

Eric Strom
ASG@cpan.org
https://metacpan.org/author/ASG

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About