Skip to content

Instantly share code, notes, and snippets.

@kanatohodets
Created September 20, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanatohodets/f193d552caa755e32d23 to your computer and use it in GitHub Desktop.
Save kanatohodets/f193d552caa755e32d23 to your computer and use it in GitHub Desktop.
use v6;
class Foo { }
my $attr = Attribute.new(
name => 'bar',
has-accessor => True,
package => Foo,
type => Str
);
Foo.^add_attribute($attr);
Foo.^add_method('bar', method () {
my @attrs = self.^attributes;
say @attrs; # [Str bar]
my $matching-attr = @attrs.grep({ $_.name eq 'bar' })[0];
my $val = $matching-attr.get_value(self); # dies: P6opaque: 'no such attribute "bar"';
return $val;
});
my $foo = Foo.new(bar => 'baz');
say $foo.bar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment