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
use here LIST;
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 :
$y
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:
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:
here::install
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.
here
Eric Strom, <asg at cpan.org>
<asg at cpan.org>
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 ...;
use here
$first->() use here '$second->()'; # comments are fine $third->(); $first->(); use here '$third->()'; $second->(); # but this is out of order $fourth->(); 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.
Filter::Util::Call
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.
use here::debug;
please report any bugs or feature requests to bug-here at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=here. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-here at rt.cpan.org
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 http://dev.perl.org/licenses/ for more information.
To install here, copy and paste the appropriate command in to your terminal.
cpanm
cpanm here
CPAN shell
perl -MCPAN -e shell install here
For more information on module installation, please visit the detailed CPAN module installation guide.