NAME

Begin::Declare - compile time lexical variables

VERSION

version 0.06

SYNOPSIS

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.

EXPORT

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.

DECLARATIONS

MY ... = ...;

    works just like the keyword my except it lifts the assignment to compile time.

    MY $x = 1;            # my $x; BEGIN {$x = 1}
    MY ($y, $z) = (2, 3); # my ($y, $z); BEGIN {($y, $z) = (2, 3)}

OUR ... = ...;

    works just like the keyword our except it lifts the assignment to compile time.

    OUR ($x, @xs) = 1 .. 10;  # our ($x, @xs); BEGIN {($x, @xs) = 1 .. 10}

STATE ... = ...;

    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 ($x, @xs) = 1 .. 10;  # state ($x, @xs); BEGIN {($x, @xs) = 1 .. 10}
    
    for (1 .. 5) {
        print ++STATE $x = 'a';  # bcdef
    }

AUTHOR

Eric Strom, <asg at cpan.org>

BUGS

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.

ACKNOWLEDGEMENTS

the authors of Devel::Declare

LICENSE AND COPYRIGHT

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.