lib/VANAMBURG/SuitSingleton.pm

filter: Statementstmt 100% 31 / 31 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 97.7% 44 / 45 CC 2 SCAR 1.6
CC
2
Cov
97%
suit_by_abbreviation
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/VANAMBURG/PacketFactory.pm ↑ Summary lib/VANAMBURG/SHoCkeDOrder.pm »
1 package VANAMBURG::SuitSingleton;
2 3 ▶use MooseX::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use VANAMBURG::Suit;
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 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 VANAMBURG::SuitSingleton
10  
11 Provides singelton instances of VANAMBURG::Suit objects
12 for efficient use creating cards.
13  
14 =cut
15  
16 =head2 spade
17  
18 Instance of VANAMBURG::Suit representing the Spades
19 suit.
20 name => "Spades",
21 unicode_char => "\x{2660}",
22 abbreviation => 'S'
23
24 =cut
25
26 has 'spade' => (
27 isa => 'VANAMBURG::Suit',
28 is => 'ro',
29 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 2 return VANAMBURG::Suit->new(
31 name => "Spades",
32 unicode_char => "\x{2660}",
33 abbreviation => 'S'
34 );
35 }
36 3 );
37  
38  
39 =head2 heart
40  
41 Instance of VANAMBURG::Suit representing the Hearts
42 suit.
43 name => "Hearts",
44 unicode_char => "\x{2661}",
45 abbreviation => 'H'
46
47 =cut
48  
49 has 'heart' => (
50 isa => 'VANAMBURG::Suit',
51 is => 'ro',
52 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 2 VANAMBURG::Suit->new(
54 name => "Hearts",
55 unicode_char => "\x{2661}",
56 abbreviation => 'H'
57 );
58 }
59 3 );
60  
61  
62 =head2 club
63  
64 Instance of VANAMBURG::Suit representing the Clubs
65 suit.
66 name => "Clubs",
67 unicode_char => "\x{2663}",
68 abbreviation => 'C'
69
70 =cut
71  
72 has 'club' => (
73 isa => 'VANAMBURG::Suit',
74 is => 'ro',
75 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 2 VANAMBURG::Suit->new(
77 name => "Clubs",
78 unicode_char => "\x{2663}",
79 abbreviation => 'C'
80 );
81 }
82 3 );
83  
84  
85 =head2 diamond
86  
87 Instance of VANAMBURG::Suit representing the Diamonds
88 suit.
89 name => "Diamonds",
90 unicode_char => "\x{2662}",
91 abbreviation => 'D'
92
93 =cut
94  
95 has 'diamond' => (
96 isa => 'VANAMBURG::Suit',
97 is => 'ro',
98 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
99 2 VANAMBURG::Suit->new(
100 name => "Diamonds",
101 unicode_char => "\x{2662}",
102 abbreviation => 'D'
103 );
104 }
105 3 );
106  
107 =head2 suit_by_abbreviation
108  
109 Given a suit abbreviation ("H","S", etc.) this method returns the appropriate singleton for the suit.
110  
111 =cut
112  
113 221 ▶sub suit_by_abbreviation{
Subroutine suit_by_abbreviation: called CC=2 SCAR=7.0
Pod documented
114 221 my ($self, $abbrev) = @_;
115
116 221 $abbrev = uc $abbrev;
117 221 ▶ croak "Invalid suit abbreviation: $abbrev" if ($abbrev !~ /(S|H|C|D)/);
Branch: 1 branch
BranchTrueFalseTotal
unless $abbrev =~ /(S|H|C|D)/ 0 221 221
118
119 221 state $lookup = {S => $self->spade, H => $self->heart, C => $self->club, D => $self->diamond};
120 221 return $lookup->{$abbrev};
121 }
122  
123  
124 3 1;
« blib/lib/VANAMBURG/PacketFactory.pm ↑ Summary lib/VANAMBURG/SHoCkeDOrder.pm »