sub remove_card {
# usage: $caller->remove_card()
# removes top card of pile, returning its value
my $self = shift;
if($self->num() > 1) {
# I've worked with many alterations of this, and this
# seems (I repeat *seems*) to be what I want
$self->cards( $self->cards()->[1..$self->num()-1] );
} else { $self->cards([]) }
}
####
sub cards {
# usage: $caller->cards([$cards])
# $cards is an anonymous array of Card types
# return: cards in pile
my $self = shift;
if (@_) {
$self->{cards} = shift;
$self->num(int @{$self->{cards}});
# From data dumping, it seems that I need this line
for(@{$self->cards()}) { $_->where($self) }
}
return $self->{cards};
}
####
$self->cards() returns
$VAR1 = [
bless( {
'state' => 'down',
'where' => bless( {
'next' => 0,
'num' => 56,
'max' => 52,
'cards' => $VAR1
}, 'Pile' ),
'value' => 1,
'suit' => 'h'
}, 'Card' ),
...
bless( {
'state' => 'down',
'where' => $VAR1->[0]{'where'},
'value' => 'k',
'suit' => 'd'
}, 'Card' )
];
@{$self->cards()}->[1..$self->num()-1] returns
$VAR1 = bless( {
'state' => 'down',
'where' => bless( {
'next' => 0,
'num' => 56,
'max' => 52,
'cards' => [
$VAR1,
bless( {
'state' => 'down',
'where' => $VAR1->{'where'},
'value' => 8,
'suit' => 'c'
}, 'Card' ),
...
bless( {
'state' => 'down',
'where' => $VAR1->{'where'},
'value' => 'k',
'suit' => 'd'
}, 'Card' )
]
}, 'Pile' ),
'value' => 1,
'suit' => 'h'
}, 'Card' );