Eric Strom > here-0.03 > here



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.03   Source  


here - insert generated source here


version 0.03


this module replaces a call to use here LIST; with the contents of LIST at compile time. perl then compiles LIST and the remaining code. there is not an implicit block around LIST

an example is probably best:

    my $x;
    use here 'my $y';
    my $z;

is exactly equivalent to:

    my $x;
    my $y;
    my $z;

the important thing here is that $y is still in scope, which would not be the case with a runtime eval :

    my $x;
    eval 'my $y';
    my $z; # $y is not in scope here!


this module does not export anything, and must always be invoked at compile time as:

    use here LIST;

it is intended to be used with a transformation function to allow new syntactic sugar:

    sub my_0 {map {"my \$$_ = 0"} @_}

    use here my_0 qw(x y z);

which results in perl compiling:

    my $x = 0; my $y = 0; my $z = 0;

note the inserted semicolons (between every element of LIST and at the end).

you can utilize the here::install mechanism to make the code even shorter:

    use here::install my_0 => sub {map {"my \$$_ = 0"} @_};

    use my_0 qw(x y z);

here::install has dynamic lexical scope if B::Hooks::EndOfScope is available. otherwise it is global and you can call:

    no here::install 'my_0';

when you are done with the macro if you want to clean up.


see here::install and here::declare for additional examples.

see here::debug to view what here is doing.


Eric Strom, <asg at>


code following a use here ...; line must be placed on a new line if that code needs to be in the scope of the use here

    use here '$second->()'; # comments are fine

    use here '$third->()'; $second->(); # but this is out of order

    use here 'my $x = 1'; # $x not in scope
    # $x in scope

as far as i can tell, this is a limitation of perl / Filter::Util::Call and not of this module. patches welcome if this is not the case.

please don't fear that i've mentioned that this module uses Filter::Util::Call, since this module filters naught. all it does is insert LIST at the top of perl's queue of lines to compile. the filter is removed at the same time, never to be called again. so fear not a filter that filters not not a filter be.

write use here::debug; before a use here LIST; line to carp the contents of LIST when it is inserted into the source.

please report any bugs or feature requests to bug-here at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


copyright 2011 Eric Strom.

this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: