Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created January 25, 2015 20:09
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 rightfold/9d119b8ef0aa5e284b54 to your computer and use it in GitHub Desktop.
Save rightfold/9d119b8ef0aa5e284b54 to your computer and use it in GitHub Desktop.
sub record($class) {
my @attributes = $class.^attributes;
$class.^add_method('perl', anon method perl {
my $result = $class.^name;
$result ~= '.new(';
$result ~= @attributes.map({ .get-value(self).perl }).join(', ');
$result ~= ')';
$result;
});
}
class Person {
has $.name;
has $.age;
has @.pets;
record(Person);
}
my $person = Person.new(:name<Kristien>, :age(20), :pets<Goldfish Cat>);
say $person.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment