Hi all,
Any ideas for a better name for this module?
NAME
Defer - Defer execution of code until it is accessed
SYNOPSIS
use Defer;
# Attribute::Handlers interface
my Defer $dbh : Defer = sub { DBI->connect(...) };
# traditional tie interface
tie $dbh, Defer => \$dbh, sub { DBI->connect(...) };
# inline interface - this uses overload
my $structure = { this => "that",
Foo => defer { do_this() }, };
# the first time $dbh is accessed, the sub will be called and the
# value replaced.
DESCRIPTION
This module implements `magic variables' that are only
calculated when they are accessed. This can be extremely
useful for defering things like connecting to a database,
or performing computationally expensive operations.
So, the code that you are passing the variables does not
*need* to know (but, unfortunately, *can* find out, lead�
ing to other problems, see below) that the data isn't
immediately available; the closure that you pass is called
when you access it for the first time, and the result
placed in the most efficient place for future reference.
This concept is used by the Tangram internals to perform
on-demand loading of data from the database, for instance.
Available at http://vilain.net/pm/Defer-0.01.tar.gz
--
Sam Vilain, [EMAIL PROTECTED]
Sometimes I think we're alone. Sometimes I think we're not. In either
case, the thought is staggering.
-- R. Buckminster Fuller