Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View lexical-accessors-and-methods.pl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
use Moops 0.029;
 
class Person 0.001
{
lexical_has name => (
isa => Str,
reader => \(my $_get_name),
writer => \(my $_set_name),
);
method assume_name (Str $name)
{
$self->$_set_name($name);
say "OK, that's my new name.";
}
method my $_introduction (Str $template = "Hello, I am %s.")
{
return sprintf($template, $self->$_get_name);
}
method introduce_yourself ()
{
say $self->$_introduction();
}
}
 
my $bob = Person->new;
$bob->assume_name("Robert");
$bob->introduce_yourself();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.