Lazy initialization for Perl 6 attributes
Switch branches/tags
Nothing to show
Clone or download
Latest commit e27794a Nov 4, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/Attribute Check for defined rather than once Jan 23, 2016
t Add test that we still only get it once Jan 23, 2016
.gitignore Basically working Jan 23, 2016
.travis.yml Add travis Jan 23, 2016
Changes Add changes Nov 4, 2017
LICENCE rename LICENCE as en_GB May 30, 2016
META6.json Fix licence Apr 22, 2017 No panda Aug 22, 2017


Lazy attribute initialisation for Perl 6 classes

Build Status


use Attribute::Lazy;

class Foo {
    has $.foo will lazy { "zub" };


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.)


Assuming you have a working Rakudo Perl 6 installation you should be able to install this with zef :

# From the source directory

zef install .

# Remote installation

zef install Attribute::Lazy

Other install mechanisms may be become available in the future.


Suggestions/patches are welcomed via github at


Please see the LICENCE file in the distribution

© Rakudo Contributors 2015 © Jonathan Stowe 2016, 2017