Skip to content

Instantly share code, notes, and snippets.

@stevan
Created October 21, 2011 15:54
Show Gist options
  • Save stevan/1304188 to your computer and use it in GitHub Desktop.
Save stevan/1304188 to your computer and use it in GitHub Desktop.
::Class.meta.add_method('CREATE' => method (%params) {
# this just gathers all the
# attributes that were defined
# for the instances.
my %attrs;
my Dispatcher $dispatcher = $class.dispatcher(:descendant);
for WALKCLASS($dispatcher) -> Class $c {
for $c.get_attribute_list() -> $attr {
my $attr_obj = $c.get_attribute($attr);
%attrs{$attr} = instantiate_attribute_container($attr_obj);
}
}
# this is our P6opaque data structure
# it's nothing special, but it works :)
my OpaqueInstance $self = create_opaque_instance(\$class, %attrs);
# and now return it ...
return $self;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment