Skip to content

Instantly share code, notes, and snippets.

@Ovid

Ovid/employee.p6 Secret

Created September 15, 2015 14:57
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 Ovid/97d7bea032c00a8ccd44 to your computer and use it in GitHub Desktop.
Save Ovid/97d7bea032c00a8ccd44 to your computer and use it in GitHub Desktop.
A better example?
class Employee {
# Rat is a rational number. No more floating point errors
subset Salary of Rat where * > 0;
subset NonEmptyString of Str where * ~~ /\S/; # at least one non-space character
has NonEmptyString $.name is rw;
has NonEmptyString $.surname is rw;
has Salary $.salary is rw;
method Str {
return qq:to[END];
Name: {$.name}
Surname: {$.surname}
Salary: {$.salary}
END
}
}
my $employee = Employee.new();
given $employee {
.name = 'Sally';
.surname = 'Ride';
.salary = 200.0;
}
say "$employee";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment