Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created March 21, 2015 17:38
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 j1n3l0/9fb24a4e8e15c26cf25a to your computer and use it in GitHub Desktop.
Save j1n3l0/9fb24a4e8e15c26cf25a to your computer and use it in GitHub Desktop.
use v6;
use Test;
use MONKEY_TYPING;
class Job {
has Str $.title = 'unemployed';
}
class Person {
has Int $.age = die '$.age must be provided';
has Str $.name = die '$.name must be provided';
has Job $.job;
}
role Generative {
method sample () {
$?CLASS.new(|%(
$?CLASS.^attributes.map({
$_.name.split(/'!'/).[*-1] => $_.type.sample })));
}
}
augment class Int does Generative {
method sample () { ( 1 .. 1000 ).pick }
}
augment class Str does Generative {
method sample () { <foo bar baz joe quux>.pick }
}
augment class Job does Generative {}
augment class Person does Generative {}
lives_ok { isa_ok Person.sample, Person }, 'Generate a sample Person';
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment