lib/VANAMBURG/SuitSingletonSHoCkeD.pm

filter: Statementstmt 100% 56 / 56 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 100% 72 / 72 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/VANAMBURG/StackCard.pm ↑ Summary
1 package VANAMBURG::SuitSingletonSHoCkeD;
2 5 ▶use MooseX::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use VANAMBURG::OrderedSuit;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 VANAMBURG::SuitSingletonSHoCkeD
9  
10 Provides access to instances of VANAMBURG::OrderedSuit to
11 efficiently represent the suits in a SHoCkeD style deck stack.
12  
13 =cut
14  
15 =head2 spade
16  
17 An instance of VANAMBURG::OrderedSuit to efficiently represent
18 the Spades suit in a SHoCkeD stack.
19  
20 =cut
21  
22 has 'spade' => (
23 isa => 'VANAMBURG::OrderedSuit',
24 is => 'ro',
25 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 4 return VANAMBURG::OrderedSuit->new(
27 name => "Spades",
28 value => 1,
29 unicode_char => "\x{2660}",
30 abbreviation => 'S'
31 );
32 }
33 5 );
34  
35 =head2 heart
36  
37 An instance of VANAMBURG::OrderedSuit to efficiently represent
38 the Hearts suit in a SHoCkeD stack.
39  
40 =cut
41  
42 has 'heart' => (
43 isa => 'VANAMBURG::OrderedSuit',
44 is => 'ro',
45 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 4 VANAMBURG::OrderedSuit->new(
47 name => "Hearts",
48 value => 2,
49 unicode_char => "\x{2661}",
50 abbreviation => 'H'
51 );
52 }
53 5 );
54  
55 =head2 club
56  
57 An instance of VANAMBURG::OrderedSuit to efficiently represent
58 the Clubs suit in a SHoCkeD stack.
59  
60 =cut
61  
62 has 'club' => (
63 isa => 'VANAMBURG::OrderedSuit',
64 is => 'ro',
65 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 4 VANAMBURG::OrderedSuit->new(
67 name => "Clubs",
68 value => 3,
69 unicode_char => "\x{2663}",
70 abbreviation => 'C'
71 );
72 }
73 5 );
74  
75 =head2 diamond
76  
77 An instance of VANAMBURG::OrderedSuit to efficiently represent
78 the Diamonds suit in a SHoCkeD stack.
79  
80 =cut
81  
82 has 'diamond' => (
83 isa => 'VANAMBURG::OrderedSuit',
84 is => 'ro',
85 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 4 VANAMBURG::OrderedSuit->new(
87 name => "Diamonds",
88 value => 4,
89 unicode_char => "\x{2662}",
90 abbreviation => 'D'
91 );
92 }
93 5 );
94  
95 =head2 suit_cycle
96  
97 An array reference holding each of the suit instances in an ordered in SHoCkeD order.
98  
99 =cut
100  
101  
102 has 'suit_cycle' => (
103 is => 'ro',
104 lazy => 1,
105 isa => 'ArrayRef[VANAMBURG::OrderedSuit]',
106 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
107 3 my $self = shift;
108 3 [ $self->spade, $self->heart, $self->club, $self->diamond ];
109 }
110 5 );
111  
112 =head2 opposite_suit
113  
114 Returns the mate of the card passed as input.
115  
116 my $heart = $self->opposite_suit($self->diamond);
117  
118 =cut
119  
120 24 ▶sub opposite_suit {
Subroutine opposite_suit: called CC=1 SCAR=0.0
Pod documented
121 24 my ( $self, $suit ) = @_;
122 24 given ( $suit->name ) {
123 24 when ( $_ eq $self->spade->name ) { return $self->club; }
124 18 when ( $_ eq $self->heart->name ) { return $self->diamond; }
125 12 when ( $_ eq $self->club->name ) { return $self->spade; }
126 6 when ( $_ eq $self->diamond->name ) { return $self->heart; }
127 }
128 }
129  
130 =head2 next_suit
131  
132 Returns the suit following the input suit for a SHoCkeD packet.
133  
134 my $heart = $self->next_suit($self->spade);
135 my $spade = $self->next_suit($self->diamond);
136
137 =cut
138  
139 240 ▶sub next_suit {
Subroutine next_suit: called CC=1 SCAR=0.0
Pod documented
140 240 my ( $self, $suit ) = @_;
141 240 given ( $suit->name ) {
142 240 when ( $_ eq $self->spade->name ) { return $self->heart; }
143 179 when ( $_ eq $self->heart->name ) { return $self->club; }
144 118 when ( $_ eq $self->club->name ) { return $self->diamond; }
145 57 when ( $_ eq $self->diamond->name ) { return $self->spade; }
146 }
147 }
148  
149 =head2 previous_suit
150  
151 Returns the suit preceding the input suit for a SHoCkeD packet.
152  
153 my $heart = $self->previous_suit($self->club);
154 my $diamond = $self->previous_suit($self->spade);
155
156 =cut
157  
158 24 ▶sub previous_suit {
Subroutine previous_suit: called CC=1 SCAR=0.0
Pod documented
159 24 my ( $self, $suit ) = @_;
160 24 given ( $suit->name ) {
161 24 when ( $_ eq $self->spade->name ) { return $self->diamond; }
162 18 when ( $_ eq $self->heart->name ) { return $self->spade; }
163 12 when ( $_ eq $self->club->name ) { return $self->heart; }
164 6 when ( $_ eq $self->diamond->name ) { return $self->club; }
165 }
166 }
167  
168 5 1;
« lib/VANAMBURG/StackCard.pm ↑ Summary