Task

The goal is to get the properties of an object, as names, values or both.

Some languages support dynamic properties, which in general can only be inspected if a class' public API includes a way of listing them.

class Foo {
    has $!a = now;
    has Str $.b;
    has Int $.c is rw;
}
 
my $object = Foo.new: b => "Hello", c => 42;
 
for $object.^attributes {
    say join ", ", .name, .readonly, .container.^name, .get_value($object);
}