Object::Lazy is a Perl module that implements lazy evaluation. It is also able to create lazy objects from any class.
SYNOPSIS
use Foo 123; # because the class of the real object is Foo, version could be 123
use Object::Lazy;
my $foo = Object::Lazy->new(
sub {
return Foo->new;
},
);
bar($foo);
sub bar {
my $foo = shift;
if ($condition) {
# a foo object will be created
print $foo->output;
}
else {
# foo object is not created
}
return;
}
To combine it write somthing like:
use Object::Lazy;
my $foo = Object::Lazy->new(
sub {
# 3 lines instead of "use Foo 123"
require Foo;
Foo->import;
Foo->VERSION('123');
return Foo->new;
},
);
# and so on
After that the object will be updated too:
$object->method;
^^^^^^^-------------- will update this scalar after a build
Product's homepage
Requirements:
· Perl