lib/VANAMBURG/SiStebbins.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 56 / 56 CC 3 SCAR 2.9
CC
3
Cov
100%
BUILD
2.0
suit_singleton
2.0
BEGIN
1.0
CRAP 1.3
« lib/VANAMBURG/Suit.pm ↑ Summary lib/VANAMBURG/BCS.pm »
1 package VANAMBURG::SiStebbins;
2 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 extends 'VANAMBURG::Packet';
4 3 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use VANAMBURG::FaceValueSingleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use VANAMBURG::SuitSingletonCHaSeD;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use VANAMBURG::SuitSingletonSHoCkeD;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use VANAMBURG::StackCard;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 VANAMBURG::SiStebbins
11  
12 A class to represent the classic Si Stebbins stack. CHaSeD and SHoCkeD
13 orders are optional as well as a step of 3 or 4
14  
15 =cut
16  
17 7 ▶subtype 'SuitOrder', as 'Str', where { $_ =~ /(CHaSeD|SHoCkeD)/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 3 has 'step' => ( is => 'ro', isa => 'Int', default => 3 );
20 3 has 'suit_order' => ( is => 'ro', isa => 'SuitOrder', default => 'CHaSeD' );
21  
22 =head2 BUILD
23  
24 Post constructor Moose method to setup instance of a Packet
25 in the orrect Si Stebbins suit order (SHoCkeD or CHaSeD)
26  
27 =cut
28  
29 7 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
30 7 my $self = shift;
31  
32 7 my $fvs = VANAMBURG::FaceValueSingleton->instance;
33 7 my $first_card = VANAMBURG::StackCard->new(
34 value => $fvs->ace,
35 suit => $self->suit_singleton->suit_cycle->[0],
36 stack_number => 1
37 );
38 7 $self->add_card($first_card);
39 7 my $last_card = $first_card;
40 7 for ( 2 .. 52 ) {
41 357 $last_card = $self->card_after($last_card);
42 357 $self->add_card($last_card);
43 }
44  
45 }
46  
47 =head2 suit_singleton
48  
49 A short cut to the correct SuitSingleton class.
50  
51 Returns either VANAMBURG::SuitSingletonCHaSeD->instance() or
52 VANAMBURG::SuitSingletonSHoCkeD->instance() depending on the
53 value of $self->suit_order
54
55 =cut
56
57 364 ▶sub suit_singleton {
Subroutine suit_singleton: called CC=2 SCAR=6.9
Pod documented
58 364 my $self = shift;
59 364 ▶ if ( $self->suit_order eq 'CHaSeD' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->suit_order eq 'CHaSeD') { } 156 208 364
60 156 return VANAMBURG::SuitSingletonCHaSeD->instance();
61 }
62 else {
63 208 return VANAMBURG::SuitSingletonSHoCkeD->instance();
64 }
65 }
66  
67 =head2 card_after
68  
69 Given a card, and instance of L<VANAMBURG::StackCard>, this method returns the next card in the system.
70  
71 Returns an instance of L<VANAMBURG::StackCard>
72  
73 =cut
74  
75 357 ▶sub card_after {
Subroutine card_after: called CC=1 SCAR=0.0
Pod documented
76 357 my ( $self, $card ) = @_;
77  
78 357 my $next_val_index = ( ( $card->value->value + $self->step ) % 13 ) - 1;
79 357 my $next_value =
80 VANAMBURG::FaceValueSingleton->instance->default_value_cycle
81 ->[$next_val_index];
82 357 my $next_suit =
83 $self->suit_singleton->next_suit( $card->suit );
84 357 VANAMBURG::StackCard->new(
85 value => $next_value,
86 suit => $next_suit,
87 stack_number => $card->stack_number + 1,
88 );
89 }
90  
91 3 1;
« lib/VANAMBURG/Suit.pm ↑ Summary lib/VANAMBURG/BCS.pm »