June 2004
Intermediate to advanced
304 pages
12h 19m
English
You can define
ordinary
subroutines within a class or role. They cannot be invoked on an
object with the $object.methodname syntax and will
never pass an implicit invocant argument. They
aren’t inherited but can be pulled in with role
composition. They’re mainly useful for utility code
internal to the class:
class Answer::Young;
has $.answer;
. . .
sub is_valid ($value) {
return 1 if 10 < $value < 42;
}
. . .
method set_answer ($new) {
$.answer = $new if is_valid($new);
}Subroutines may be exported if the class also functions as a module.
Read now
Unlock full access