Created
July 15, 2011 18:09
-
-
Save tene/1085195 to your computer and use it in GitHub Desktop.
Tiny moose example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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