Deck.pm

filter: Statementstmt 100% 36 / 36 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 91.0% 51 / 56 CC 7 SCAR 8.6
CC
7
Cov
93%
_build_cards
5.0
__ANON__
2.1
__ANON__
2.1
CRAP 2.4
« Game/Pineapple.pm ↑ Summary Game/Badugi.pm »
1 package Poker::Deck;
2 13 our $VERSION = '0.12';
3  
4  
5 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Poker::Card;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Poker::Deck - Simple class to represent a deck of poker cards.
14  
15 =head1 VERSION
16  
17 Version 0.12
18  
19 =cut
20  
21  
22 =head1 SYNOPSIS
23  
24 This class is used internally by Poker::Dealer. Attributes include
25 cards, discards, card_type, and joker_count.
26  
27 my $deck = Poker::Deck->new( joker_count => 2 ); # 54 cards
28  
29 =cut
30  
31 has 'joker_count' => (
32 is => 'ro',
33 1 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 13 );
35  
36 13 has 'card_type' => (
37 is => 'rw',
38 builder => '_build_card_type',
39 );
40  
41 47 ▶sub _build_card_type {
Subroutine _build_card_type: called CC=1 SCAR=0.0
42 47 return 'Poker::Card';
43 }
44  
45 has 'cards' => (
46 is => 'rw',
47 lazy => 1,
48 97 ▶ isa => sub { die "Not a Tie::IxHash!" unless $_[0]->isa('Tie::IxHash') },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("Tie::IxHash") 0 97 97
49 13 builder => '_build_cards',
50 );
51  
52 has 'discards' => (
53 is => 'rw',
54 47 ▶ isa => sub { die "Not an array!" unless ref( $_[0] ) eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 47 47
55 47 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 13 );
57  
58 97 ▶sub _build_cards {
Subroutine _build_cards: called CC=5 SCAR=16.1
59 97 my $self = shift;
60 97 my $cards = Tie::IxHash->new;
61 97 for my $rank (qw(2 3 4 5 6 7 8 9 T J Q K A)) {
62 1261 for my $suit (qw(c d h s)) {
63 5044 $cards->Push(
64 $rank
65 . $suit => $self->card_type->new(
66 id => $cards->Length,
67 suit => $suit,
68 rank => $rank
69 )
70 );
71 }
72 }
73 97 ▶ my $jokers = $self->joker_count // 0;
Condition50%1/2
$self->joker_count // 0
l!l
970
MC/DC0%0/1
$self->joker_count // 0
$self->joker_count
Truth table50%1/2
A
A= $self->joker_count
Aresult
11
00
74 97 for my $i ( 1 .. $jokers ) {
75 12 my $name = "Jo$i";
76 12 $cards->Push(
77 $name => $self->card_type->new(
78 id => $cards->Length,
79 rank => 'Joker',
80 suit => $i,
81 wild_flag => 1,
82 )
83 );
84 }
85 97 return $cards;
86 }
87  
88 47 ▶sub BUILD { }
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
89  
90 =head1 AUTHOR
91  
92 Nathaniel Graham, C<< <ngraham at cpan.org> >>
93  
94 =head1 LICENSE AND COPYRIGHT
95  
96 Copyright 2016 Nathaniel Graham.
97  
98 =cut
99  
100 13 1;
« Game/Pineapple.pm ↑ Summary Game/Badugi.pm »