Introducing here

I've just published the first release of the here module, a mechanism for safely inserting generated code into a compiling program. this can be used to write macros, cut down on boiler plate, and to implement new declarations, all without ever having to parse any perl source code.

you operate on code as data, as you normally would when metaprogramming. then a call to use here $generated_code; injects that code into the compiling source

sub my_0 {map "my \$$_ = 0", @_} # a simple macro

use here my_0 qw(x y z);

Introducing Begin::Declare

While working on a module for source code injection, one of my example "macros" was one that allows you to declare and assign to a lexical variable at compile time, without having to write the variable names twice. That concept more or less hijacked the conversation, and after some prodding from p5p to make the interface better, I've used Devel::Declare to add two new keywords to Perl, MY and OUR.

Here is the synopsis from the module:

don't you hate writing:
my ($foo, @bar);
    ($foo, @bar) = ('fooval', 1 .. 10);
when you should be a…

About Eric Strom (ASG)