a small role to enable 'has' when inheriting from core classes
Switch branches/tags
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/Class Add unit declarator to role declarations May 22, 2015
t added 'does Has' Aug 21, 2012
.gitignore added gitignore Aug 21, 2012
LICENSE added license and meta.info Aug 21, 2012
META6.json Merge branch 'SPDX-license' of git://github.com/samcv/Class-Utils int… Jun 24, 2017
README.md Added content to the readme Aug 21, 2012



role Has

Some of the core classes don't run through bless during object creation (apparently for efficiency reasons). This means that if you define a class that inherits from Array, for example, you can't define properties for the class using the normal has route.

The Has role addresses this by importing a new new that takes advantage of bless.


The following code breaks. If you try to access $.foo below, you get an undefined Any value instead of 'bar'.

class MySet is Array {
  has $.foo = 'bar';

say MySet.new.foo;    # Any()

Fix this with does Has from Class::Utils:

use Class::Utils;

class MySet is Array does Has {
  has $.foo = 'bar';

say MySet.new.foo;    # bar