DISCUSSION

The classical way to implement lazy evaluation in an eager-evaluating languages (including perl, of course) is to wrap the value with a closure:

sub delay{
my $value = shift;
sub { $value }
}
my $l = delay(42);

Then evaluate the closure whenever you need it.

my $v = $l->();

Marking the variable lazy can be easier with prototypes:

sub delay(&){ $_[0] }
my $l = delay { 42 }

But forcing the value is pain in the neck.

This module makes it easier by making the value auto-forcing.

HOW IT WORKS

Check the source. That's what the source is for.

There are various CPAN modules that does what this does. But I found others too complicated. Hey, the whole code is only 25 lines long! (Well, was until 0.03) Nicely fits in a good-old terminal screen.

The closest module is Scalar::Defer, a brainchild of Audrey Tang. But I didn't like the way it (ab)?uses namespace.