Ordeal::Model::Deck - Class for representing decks of cards
use Ordeal::Model::Deck; my $card = Ordeal::Model::Deck->new( group => 'whatever', id => 'AAA-bb-1235', name => 'three of clubs', cards => \@cards, );
This class represents a deck of cards. The representation is considered ordered, see Ordeal::Model::Shuffle for a wrapper object for shuffling the cards.
"id" should be a unique identifier for the deck. "cards" is the low-level accessor to the cards, although you shoud probably stick to the higher level interface provided by "card_at" and "n_cards".
"group" can be used to group decks together, e.g. for assigning them to owners. All in all it is opaque data that you can use.
"name" is a name you can associate to the deck. Again, it's treated as opaque data, so you can abuse it.
my $card = $deck->card_at($i);
get the card in position $i. Positions are assumed to start from 0 and arrive up to "n_cards" minus one. Invalid indexes $i trigger an exception.
$i
my @cards = $deck->cards; $deck->cards(@cards);
accessor for the list of cards. Note that it accepts and returns a list not an array reference.
my $group = $deck->group; $deck->group($group);
accessor for some c<group> metadata you might want to associate to the deck. Treated as opaque data.
my $id = $deck->id; $deck->id($id);
accessor for a unique identifer associated to the deck.
my $name = $deck->name; $deck->name($name);
accessor for a name associated to the deck.
my $n = $deck->n_cards;
returns the number of cards in the deck.
The code leverages some experimental Perl features like signatures and postderef; for this reason, at least perl 5.20 will be needed.
Report bugs through GitHub (patches welcome) at https://github.com/polettix/Ordeal-Model.
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2018 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Ordeal::Model, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ordeal::Model
CPAN shell
perl -MCPAN -e shell install Ordeal::Model
For more information on module installation, please visit the detailed CPAN module installation guide.