File Coverage

blib/lib/Game/Cribbage/Deck/Card.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Game::Cribbage::Deck::Card;
2              
3 9     9   101951 use strict;
  9         26  
  9         455  
4 9     9   57 use warnings;
  9         17  
  9         624  
5              
6 9     9   719 use Rope;
  9         13394  
  9         91  
7 9     9   4450 use Rope::Autoload;
  9         3616  
  9         60  
8              
9             our (%card_to_value_map, %card_run_to_value_map, %card_suit_to_symbol);
10             BEGIN {
11             %card_to_value_map = (
12             A => 1,
13 9     9   1682 (map {$_ => 10} qw/J Q K/),
  27         102  
14             );
15 9         43 %card_run_to_value_map = (
16             A => 1,
17             J => 11,
18             Q => 12,
19             K => 13
20             );
21 9         4622 %card_suit_to_symbol = (
22             H => '♥️',
23             S => '♠️',
24             D => '♦️',
25             C => '♣️'
26             );
27             }
28              
29             property [qw/id used/] => (
30             initable => 1,
31             writeable => 1,
32             configurable => 0,
33             enumerable => 1,
34             value => 0
35             );
36              
37             property [qw/suit symbol/] => (
38             initable => 1,
39             writeable => 0,
40             configurable => 0,
41             enumerable => 1
42             );
43              
44             function value => sub {
45             my ($self) = @_;
46             return $card_to_value_map{$self->{symbol}} || $self->{symbol};
47             };
48              
49             function run_value => sub {
50             my ($self) = @_;
51             return $card_run_to_value_map{$self->{symbol}} || $self->{symbol};
52             };
53              
54             function suit_symbol => sub {
55             my ($self) = @_;
56             return $card_suit_to_symbol{$self->{suit}};
57             };
58              
59             function ui_stringify => sub {
60             my ($self) = @_;
61             return sprintf "%s %s", $card_suit_to_symbol{$self->{suit}}, $self->{symbol};
62             };
63              
64             function stringify => sub {
65             my ($self) = @_;
66             return sprintf "%s%s", $self->{symbol}, $card_suit_to_symbol{$self->{suit}};
67             };
68              
69             function match => sub {
70             my ($self, $card) = @_;
71             if ($self->suit eq $card->{suit} && $self->symbol =~ m/^($card->{symbol})$/) {
72             return 1;
73             }
74             return 0;
75             };
76              
77             1;
78              
79             __END__