Skip to content

Instantly share code, notes, and snippets.

@0branch
Created April 2, 2011 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0branch/899646 to your computer and use it in GitHub Desktop.
Save 0branch/899646 to your computer and use it in GitHub Desktop.
Player.pm, first draft.
package Player;
use Moose;
has 'inventory' => (
default => sub { [] },
is => 'ro',
);
sub list_inventory {
my $self = shift;
my @inv = @{ $self->inventory };
return "You are carrying nothing." unless @inv;
my $output = "You are currently carrying:\n";
$output .= ("* " . $_->name . "\n") foreach(@inv);
return $output;
}
sub obtain {
my ($self, $object) = @_;
push @{ $self->inventory }, $object;
}
no Moose;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment