Scalar-Lazy

 view release on metacpan or  search on metacpan

lib/Scalar/Lazy.pm  view on Meta::CPAN


sub new($&;$) { 
    my ($pkg, $code, $init) = @_;
    if ($init){
	my $val = $code->();
	$code = sub { $val };
    }
    bless $code, $pkg;
}

sub lazy(&;$) { __PACKAGE__->new(@_) }
*delay = \&lazy;

sub force($){
    my $pkg = ref $_[0];
    bless $_[0], $pkg . '::FORCE';
    my $val = $_[0]->();
    bless $_[0], $pkg;
    $val;
}



( run in 2.285 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )