Skip to content

@tobyink /lexical-accessors-and-methods.pl
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.