Lazy

NAME

Attribute::Lazy - lazy attribute initialisation

SYNOPSIS


use Attribute::Lazy;

class Foo {
    has $.foo will lazy { "zub" };
    has $.booble will lazy { $_.bungle };
    method bungle() {
        'beep';
    }

}

DESCRIPTION

This is based on an experimental trait that was briefly in the Rakudo core.

Attribute::Lazy provides a single trait will lazy that will allow an attribute with a public accessor (that is one defined with the . twigil,) to be initialised the first time it is accessed by the result of the supplied block. This might be useful if the value may not be used and may be expensive to calculate (or various other reasons that haven't been thought of.)

The supplied block will have the object instance passed to it as an argument, which can be used to call other methods or public accessors on the object, you probably want to avoid calling anything that may depend on the value of the attribute for obvious reasons.

Attribute::Lazy v0.0.6

Trait to provide lazy initialisation of attributes

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Attribute::Lazy

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.