| 1 | package VANAMBURG::FaceValueSingleton; | ||||||||||
| 2 | 5 | ▶ | use MooseX::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use VANAMBURG::FaceValue; | ||||||||
|
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 Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head2 VANAMBURG::FaceValueSingleton | ||||||||||
| 10 | |||||||||||
| 11 | Provides efficient access to instances of VANAMBURG::FaceValue objects that can | ||||||||||
| 12 | be reused to create cards. Attempts to provide memory and processor efficiency by | ||||||||||
| 13 | allowing reuse of FaceValue object rather than creating new ones everytime they are needed. | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | =head2 ace | ||||||||||
| 18 | |||||||||||
| 19 | Returns the instance of VANAMBURG::FaceValue that represents an Ace. | ||||||||||
| 20 | name => "Ace", | ||||||||||
| 21 | value => 1, | ||||||||||
| 22 | abbreviation => 'A' | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | has 'ace' => ( | ||||||||||
| 27 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 28 | is => 'ro', | ||||||||||
| 29 | lazy => 0, | ||||||||||
| 30 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | return VANAMBURG::FaceValue->new( | |||||||||
| 32 | name => "Ace", | ||||||||||
| 33 | value => 1, | ||||||||||
| 34 | abbreviation => 'A' | ||||||||||
| 35 | ); | ||||||||||
| 36 | } | ||||||||||
| 37 | 5 | ); | |||||||||
| 38 | |||||||||||
| 39 | =head2 two | ||||||||||
| 40 | |||||||||||
| 41 | Returns the instance of VANAMBURG::FaceValue that represents a Two. | ||||||||||
| 42 | name => "Two", | ||||||||||
| 43 | value => 2, | ||||||||||
| 44 | abbreviation => '2' | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | has 'two' => ( | ||||||||||
| 49 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 50 | is => 'ro', | ||||||||||
| 51 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 53 | name => "Two", | ||||||||||
| 54 | value => 2, | ||||||||||
| 55 | abbreviation => '2' | ||||||||||
| 56 | ); | ||||||||||
| 57 | } | ||||||||||
| 58 | 5 | ); | |||||||||
| 59 | |||||||||||
| 60 | =head2 two | ||||||||||
| 61 | |||||||||||
| 62 | Returns the instance of VANAMBURG::FaceValue that represents a Three. | ||||||||||
| 63 | name => "Three", | ||||||||||
| 64 | value => 3, | ||||||||||
| 65 | abbreviation => '3' | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | has 'three' => ( | ||||||||||
| 70 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 71 | is => 'ro', | ||||||||||
| 72 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 74 | name => "Three", | ||||||||||
| 75 | value => 3, | ||||||||||
| 76 | abbreviation => '3' | ||||||||||
| 77 | ); | ||||||||||
| 78 | } | ||||||||||
| 79 | 5 | ); | |||||||||
| 80 | |||||||||||
| 81 | =head2 two | ||||||||||
| 82 | |||||||||||
| 83 | Returns the instance of VANAMBURG::FaceValue that represents a Four. | ||||||||||
| 84 | name => "Four", | ||||||||||
| 85 | value => 4, | ||||||||||
| 86 | abbreviation => '4' | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | has 'four' => ( | ||||||||||
| 91 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 92 | is => 'ro', | ||||||||||
| 93 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 94 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 95 | name => "Four", | ||||||||||
| 96 | value => 4, | ||||||||||
| 97 | abbreviation => '4' | ||||||||||
| 98 | ); | ||||||||||
| 99 | } | ||||||||||
| 100 | 5 | ); | |||||||||
| 101 | |||||||||||
| 102 | =head2 two | ||||||||||
| 103 | |||||||||||
| 104 | Returns the instance of VANAMBURG::FaceValue that represents a Five. | ||||||||||
| 105 | name => "Five", | ||||||||||
| 106 | value => 5, | ||||||||||
| 107 | abbreviation => '5' | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | has 'five' => ( | ||||||||||
| 112 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 113 | is => 'ro', | ||||||||||
| 114 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 115 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 116 | name => "Five", | ||||||||||
| 117 | value => 5, | ||||||||||
| 118 | abbreviation => '5' | ||||||||||
| 119 | ); | ||||||||||
| 120 | } | ||||||||||
| 121 | 5 | ); | |||||||||
| 122 | |||||||||||
| 123 | =head2 six | ||||||||||
| 124 | |||||||||||
| 125 | Returns the instance of VANAMBURG::FaceValue that represents a Six. | ||||||||||
| 126 | name => "Six", | ||||||||||
| 127 | value => 6, | ||||||||||
| 128 | abbreviation => '6' | ||||||||||
| 129 | |||||||||||
| 130 | =cut | ||||||||||
| 131 | |||||||||||
| 132 | has 'six' => ( | ||||||||||
| 133 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 134 | is => 'ro', | ||||||||||
| 135 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 136 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 137 | name => "Six", | ||||||||||
| 138 | value => 6, | ||||||||||
| 139 | abbreviation => '6' | ||||||||||
| 140 | ); | ||||||||||
| 141 | } | ||||||||||
| 142 | 5 | ); | |||||||||
| 143 | |||||||||||
| 144 | =head2 seven | ||||||||||
| 145 | |||||||||||
| 146 | Returns the instance of VANAMBURG::FaceValue that represents a Seven. | ||||||||||
| 147 | name => "Seven", | ||||||||||
| 148 | value => 7, | ||||||||||
| 149 | abbreviation => '7' | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | |||||||||||
| 153 | has 'seven' => ( | ||||||||||
| 154 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 155 | is => 'ro', | ||||||||||
| 156 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 157 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 158 | name => "Seven", | ||||||||||
| 159 | value => 7, | ||||||||||
| 160 | abbreviation => '7' | ||||||||||
| 161 | ); | ||||||||||
| 162 | } | ||||||||||
| 163 | 5 | ); | |||||||||
| 164 | |||||||||||
| 165 | =head2 eight | ||||||||||
| 166 | |||||||||||
| 167 | Returns the instance of VANAMBURG::FaceValue that represents a Eight. | ||||||||||
| 168 | name => "Eight", | ||||||||||
| 169 | value => 8, | ||||||||||
| 170 | abbreviation => '8' | ||||||||||
| 171 | |||||||||||
| 172 | =cut | ||||||||||
| 173 | |||||||||||
| 174 | has 'eight' => ( | ||||||||||
| 175 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 176 | is => 'ro', | ||||||||||
| 177 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 178 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 179 | name => "Eight", | ||||||||||
| 180 | value => 8, | ||||||||||
| 181 | abbreviation => '8' | ||||||||||
| 182 | ); | ||||||||||
| 183 | } | ||||||||||
| 184 | 5 | ); | |||||||||
| 185 | |||||||||||
| 186 | =head2 nine | ||||||||||
| 187 | |||||||||||
| 188 | Returns the instance of VANAMBURG::FaceValue that represents a Nine. | ||||||||||
| 189 | name => "Nine", | ||||||||||
| 190 | value => 9, | ||||||||||
| 191 | abbreviation => '9' | ||||||||||
| 192 | |||||||||||
| 193 | =cut | ||||||||||
| 194 | |||||||||||
| 195 | has 'nine' => ( | ||||||||||
| 196 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 197 | is => 'ro', | ||||||||||
| 198 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 199 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 200 | name => "Nine", | ||||||||||
| 201 | value => 9, | ||||||||||
| 202 | abbreviation => '9' | ||||||||||
| 203 | ); | ||||||||||
| 204 | } | ||||||||||
| 205 | 5 | ); | |||||||||
| 206 | |||||||||||
| 207 | =head2 ten | ||||||||||
| 208 | |||||||||||
| 209 | Returns the instance of VANAMBURG::FaceValue that represents a Ten. | ||||||||||
| 210 | name => "Ten", | ||||||||||
| 211 | value => 10, | ||||||||||
| 212 | abbreviation => '10' | ||||||||||
| 213 | |||||||||||
| 214 | =cut | ||||||||||
| 215 | |||||||||||
| 216 | has 'ten' => ( | ||||||||||
| 217 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 218 | is => 'ro', | ||||||||||
| 219 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 220 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 221 | name => "Ten", | ||||||||||
| 222 | value => 10, | ||||||||||
| 223 | abbreviation => '10' | ||||||||||
| 224 | ); | ||||||||||
| 225 | } | ||||||||||
| 226 | 5 | ); | |||||||||
| 227 | |||||||||||
| 228 | =head2 jack | ||||||||||
| 229 | |||||||||||
| 230 | Returns the instance of VANAMBURG::FaceValue that represents a Jack. | ||||||||||
| 231 | name => "Jack", | ||||||||||
| 232 | value => 11, | ||||||||||
| 233 | abbreviation => 'J' | ||||||||||
| 234 | |||||||||||
| 235 | =cut | ||||||||||
| 236 | |||||||||||
| 237 | has 'jack' => ( | ||||||||||
| 238 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 239 | is => 'ro', | ||||||||||
| 240 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 241 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 242 | name => "Jack", | ||||||||||
| 243 | value => 11, | ||||||||||
| 244 | abbreviation => 'J' | ||||||||||
| 245 | ); | ||||||||||
| 246 | } | ||||||||||
| 247 | 5 | ); | |||||||||
| 248 | |||||||||||
| 249 | =head2 queen | ||||||||||
| 250 | |||||||||||
| 251 | Returns the instance of VANAMBURG::FaceValue that represents a Queen. | ||||||||||
| 252 | name => "Queen", | ||||||||||
| 253 | value => 12, | ||||||||||
| 254 | abbreviation => 'Q' | ||||||||||
| 255 | |||||||||||
| 256 | =cut | ||||||||||
| 257 | |||||||||||
| 258 | has 'queen' => ( | ||||||||||
| 259 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 260 | is => 'ro', | ||||||||||
| 261 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 262 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 263 | name => "Queen", | ||||||||||
| 264 | value => 12, | ||||||||||
| 265 | abbreviation => 'Q' | ||||||||||
| 266 | ); | ||||||||||
| 267 | } | ||||||||||
| 268 | 5 | ); | |||||||||
| 269 | |||||||||||
| 270 | =head2 king | ||||||||||
| 271 | |||||||||||
| 272 | Returns the instance of VANAMBURG::FaceValue that represents a King. | ||||||||||
| 273 | name => "King", | ||||||||||
| 274 | value => 13, | ||||||||||
| 275 | abbreviation => 'K' | ||||||||||
| 276 | |||||||||||
| 277 | =cut | ||||||||||
| 278 | |||||||||||
| 279 | has 'king' => ( | ||||||||||
| 280 | isa => 'VANAMBURG::FaceValue', | ||||||||||
| 281 | is => 'ro', | ||||||||||
| 282 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 283 | 4 | VANAMBURG::FaceValue->new( | |||||||||
| 284 | name => "King", | ||||||||||
| 285 | value => 13, | ||||||||||
| 286 | abbreviation => 'K' | ||||||||||
| 287 | ); | ||||||||||
| 288 | } | ||||||||||
| 289 | 5 | ); | |||||||||
| 290 | |||||||||||
| 291 | =head2 default_value_cycle | ||||||||||
| 292 | |||||||||||
| 293 | Returns an array reference containing all the FaceValue instances in order A - K. | ||||||||||
| 294 | |||||||||||
| 295 | =cut | ||||||||||
| 296 | |||||||||||
| 297 | has 'default_value_cycle' => ( | ||||||||||
| 298 | is => 'rw', | ||||||||||
| 299 | lazy => 1, | ||||||||||
| 300 | isa => 'ArrayRef[VANAMBURG::FaceValue]', | ||||||||||
| 301 | 4 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 302 | 4 | my $self = shift; | |||||||||
| 303 | |||||||||||
| 304 | 4 | my @result = ( | |||||||||
| 305 | $self->ace, $self->two, $self->three, $self->four, | ||||||||||
| 306 | $self->five, $self->six, $self->seven, $self->eight, | ||||||||||
| 307 | $self->nine, $self->ten, $self->jack, $self->queen, | ||||||||||
| 308 | $self->king | ||||||||||
| 309 | ); | ||||||||||
| 310 | 4 | return \@result; | |||||||||
| 311 | } | ||||||||||
| 312 | 5 | ); | |||||||||
| 313 | |||||||||||
| 314 | =head2 facevalue_by_abbreviation | ||||||||||
| 315 | |||||||||||
| 316 | Given a face value abbreviation ("A","2", "J", etc.) this method returns the appropriate singleton for the FaceValue. | ||||||||||
| 317 | |||||||||||
| 318 | =cut | ||||||||||
| 319 | |||||||||||
| 320 | 229 | ▶ | sub facevalue_by_abbreviation { | ||||||||
|
Subroutine
facevalue_by_abbreviation: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 321 | 229 | my ( $self, $abbrev ) = @_; | |||||||||
| 322 | 229 | $abbrev = uc $abbrev; | |||||||||
| 323 | 229 | ▶ | croak "Invalid suit abbreviation: $abbrev" if ( $abbrev !~ /(A|2|3|4|5|6|7|8|9|10|J|Q|K)/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 324 | |||||||||||
| 325 | 229 | state $lookup = { | |||||||||
| 326 | A => $self->ace, | ||||||||||
| 327 | 2 => $self->two, | ||||||||||
| 328 | 3 => $self->three, | ||||||||||
| 329 | 4 => $self->four, | ||||||||||
| 330 | 5 => $self->five, | ||||||||||
| 331 | 6 => $self->six, | ||||||||||
| 332 | 7 => $self->seven, | ||||||||||
| 333 | 8 => $self->eight, | ||||||||||
| 334 | 9 => $self->nine, | ||||||||||
| 335 | 10 => $self->ten, | ||||||||||
| 336 | J => $self->jack, | ||||||||||
| 337 | Q => $self->queen, | ||||||||||
| 338 | K => $self->king | ||||||||||
| 339 | }; | ||||||||||
| 340 | 229 | return $lookup->{$abbrev}; | |||||||||
| 341 | } | ||||||||||
| 342 | |||||||||||
| 343 | 5 | 1; | |||||||||