lib/VANAMBURG/SuitSingletonCHaSeD.pm

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