Begin::Declare - compile time lexical variables
version 0.06
don't you hate writing:
my ($foo, @bar); BEGIN { ($foo, @bar) = ('fooval', 1 .. 10); }
when you should be able to write:
MY ($foo, @bar) = ('fooval', 1 .. 10);
just use Begin::Declare; and you can.
use Begin::Declare;
is the same as:
use Begin::Declare qw (MY OUR); # and STATE if "use feature 'state';"
you can also write:
use Begin::Declare qw (My Our);
if you prefer those names.
works just like the keyword my except it lifts the assignment to compile time.
my
MY $x = 1; # my $x; BEGIN {$x = 1} MY ($y, $z) = (2, 3); # my ($y, $z); BEGIN {($y, $z) = (2, 3)}
works just like the keyword our except it lifts the assignment to compile time.
our
OUR ($x, @xs) = 1 .. 10; # our ($x, @xs); BEGIN {($x, @xs) = 1 .. 10}
works better than the keyword state (since it supports list assignment and is a proper lvalue (at least on it's rhs)) and it lifts the assignment to compile time.
state
STATE ($x, @xs) = 1 .. 10; # state ($x, @xs); BEGIN {($x, @xs) = 1 .. 10} for (1 .. 5) { print ++STATE $x = 'a'; # bcdef }
Eric Strom, <asg at cpan.org>
<asg at cpan.org>
please report any bugs or feature requests to bug-begin-declare at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Begin-Declare. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-begin-declare at rt.cpan.org
the authors of Devel::Declare
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 Begin::Declare, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Begin::Declare
CPAN shell
perl -MCPAN -e shell install Begin::Declare
For more information on module installation, please visit the detailed CPAN module installation guide.