| 1 | package VANAMBURG::Card; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 VANAMBURG::Card | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Represents a playing card, having a suit and a face value. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head2 suit | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Returns the instance of VANAMBURG::Suit that represents the suit | ||||||||||||||||||||||||||||
| 14 | of this card. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | has 'suit' => ( isa => 'VANAMBURG::Suit', is => 'ro', required => '1' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head2 value | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Returns an instance of VANAMBURG::FaceValue that represents the face | ||||||||||||||||||||||||||||
| 23 | value of this card. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 4 | has 'value' => | |||||||||||||||||||||||||||
| 28 | ( isa => 'VANAMBURG::FaceValue', is => 'ro', required => '1' ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 abbreviation | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Returns a string abbreviation for this card that is composed of the | ||||||||||||||||||||||||||||
| 33 | abbrevation of the value and suit of the card. For example, it | ||||||||||||||||||||||||||||
| 34 | returns 'AS' for the Ace of Spades, and 'JS' for the Jack of Spades. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | has 'abbreviation' => ( | ||||||||||||||||||||||||||||
| 39 | isa => 'Str', | ||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||||||||||
| 42 | 34 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 34 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 34 | return $self->value->abbreviation . $self->suit->abbreviation; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 4 | ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head2 unicode_abbreviation | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Returns an abbreviation for the card where the suit is | ||||||||||||||||||||||||||||
| 52 | the unicode character for the suit of the card. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | has 'unicode_abbreviation' => ( | ||||||||||||||||||||||||||||
| 57 | isa => 'Str', | ||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||
| 59 | lazy => 1, | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | return $self->value->abbreviation . $self->suit->unicode_char; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 4 | ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head2 equals | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Returns "true" (1) if the value and suit of the input card matches | ||||||||||||||||||||||||||||
| 69 | that of this card. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub equals { | ||||||||||||||||||||||||||
|
Subroutine
equals: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ( $self, $other ) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 0 if ( !defined $other ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( $self->suit->equals( $other->suit ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->suit->equals($other->suit) and $self->value->equals($other->value)
MC/DC0%0/2
$self->suit->equals($other->suit) and $self->value->equals($other->value)
$self->suit->equals($other->suit)
$self->value->equals($other->value)
Truth table0%0/3
A and B
A= $self->suit->equals($other->suit)B= $self->value->equals($other->value)
| |||||||||||||||||||||||||||||
| 77 | && $self->value->equals( $other->value ) ) | ||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 0 | return 1; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||
| 82 | 0 | return 0; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 display_name | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Returns an english name for this card, such as 'Ace of Spades'. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub display_name { | ||||||||||||||||||||||||||
|
Subroutine
display_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 0 | return $self->value->name . " of " . $self->suit->name; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | 1; | |||||||||||||||||||||||||||