Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Point;
- use Moose; # automatically turns on strict and warnings
- has 'x' => (is => 'rw', isa => 'Int');
- has 'y' => (is => 'rw', isa => 'Int');
- sub clear {
- my $self = shift;
- $self->x(0);
- $self->y(0);
- }
- my $p = Point->new({x=>10 , y=>20}); # Free constructor
- $p->x(15); # Free setter
- print $p->x(); # Free getter
- $p->clear();
- $p->x(15.5); # FAILS! Free type check.
- package Person;
- use Moose;
- has age => ( isa => Int, is => 'rw');
- has name => ( isa => Str, is => 'rw');
- 1;
- my $person = Person->new();
- $person->age(34);
- $person->name('Mike');
- print $person->name, "n";
Add Comment
Please, Sign In to add comment