Skip to content

Instantly share code, notes, and snippets.

@tene
Created July 15, 2011 18:09
Show Gist options
  • Save tene/1085195 to your computer and use it in GitHub Desktop.
Save tene/1085195 to your computer and use it in GitHub Desktop.
Tiny moose example
package Player;
use Moose;
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');
sub position {
my ($self, $x, $y) = @_;
if ( defined($x) and defined($y) ) {
$self->x($x); $self->y($y);
}
return ($self->x, $self->y);
}
1;
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use feature ':5.10';
use lib qw/./;
use Player;
my $p = Player->new(x=>1, y=>5);
say $p->x;
$p->x(23);
say $p->x;
$p->position(5,9);
say for $p->position;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment