blib/lib/Game/Schnapsen/Card.pm

filter: Statementstmt 100% 48 / 48 Branchbran 83.3% 5 / 6 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 10 / 10 totaltotal 94.5% 87 / 92 CC 7 SCAR 9.5
CC
7
Cov
95%
_check
6.2
id_of
2.0
BEGIN
1.0
CRAP 2.6
« blib/lib/Game/Schnapsen/Declare.pm ↑ Summary blib/lib/Game/Schnapsen/Hand.pm »
1 package Game::Schnapsen::Card;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 our $VERSION = '0.03';
9 24 our @EXPORT_OK = qw(rank_of suit_of power_of points_of name_of long_name_of id_of
10 ids_of_ranks ranks suits CARDS);
11  
12 24 ▶use constant CARDS => 24;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 24 my @RANKS = qw(A T K Q J 9);
15 24 my @SUITS = qw(S H D C);
16  
17 24 my %POINTS = (A => 11, T => 10, K => 4, Q => 3, J => 2, 9 => 0);
18  
19 24 my %RANK_NAME = (A => 'ace', T => 'ten', K => 'king',
20 Q => 'queen', J => 'jack', 9 => 'nine');
21 24 my %SUIT_NAME = (S => 'spades', H => 'hearts', D => 'diamonds', C => 'clubs');
22  
23 24 my %RANK_AT;
24 24 @RANK_AT{@RANKS} = 0 .. $#RANKS;
25  
26 27 ▶sub ranks { return @RANKS }
Subroutine ranks: called CC=1 SCAR=0.0
Pod documented
27 25 ▶sub suits { return @SUITS }
Subroutine suits: called CC=1 SCAR=0.0
Pod documented
28  
29 2614453 ▶sub _check {
Subroutine _check: called CC=6 SCAR=18.3
30 2614453 my ($id) = @_;
31 2614453 ▶ die 'Game::Schnapsen::Card: no card has id ' . (defined $id ? "'$id'" : 'undef') . "\n"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1 and $id <= 24 3 2614450 2614453
defined $id ? : 3 0 3
Condition77%7/9
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1 and $id <= 24
!ll&&!rl&&r
212614450
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1
!ll&&!rl&&r
202614451
defined $id and $id =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
022614451
MC/DC50%2/4
defined $id and $id =~ /\A[1-9][0-9]*\z/ and $id >= 1 and $id <= 24
defined $id $id =~ /\A[1-9][0-9]*\z/ $id >= 1 $id <= 24
Truth table60%3/5
A and B and C and D
A= defined $idB= $id =~ /\A[1-9][0-9]*\z/C= $id >= 1D= $id <= 24
ABCDresult
0XXX0
10XX0
110X0
11100
11111
32 unless defined $id && $id =~ /\A[1-9][0-9]*\z/ && $id >= 1 && $id <= CARDS;
33 2614450 return $id;
34 }
35  
36 1182532 ▶sub rank_of { my $id = _check($_[0]); return $RANKS[ ($id - 1) % @RANKS ] }
Subroutine rank_of: called CC=1 SCAR=0.0
Pod documented
37 1431921 ▶sub suit_of { my $id = _check($_[0]); return $SUITS[ int(($id - 1) / @RANKS) ] }
Subroutine suit_of: called CC=1 SCAR=0.0
Pod documented
38  
39 376988 ▶sub power_of { return $#RANKS - $RANK_AT{ rank_of($_[0]) } }
Subroutine power_of: called CC=1 SCAR=0.0
Pod documented
40 553128 ▶sub points_of { return $POINTS{ rank_of($_[0]) } }
Subroutine points_of: called CC=1 SCAR=0.0
Pod documented
41  
42 726 ▶sub name_of { my ($id) = @_; return rank_of($id) . suit_of($id) }
Subroutine name_of: called CC=1 SCAR=0.0
Pod documented
43  
44 2 ▶sub long_name_of {
Subroutine long_name_of: called CC=1 SCAR=0.0
Pod documented
45 2 my ($id) = @_;
46 2 return $RANK_NAME{ rank_of($id) } . ' of ' . $SUIT_NAME{ suit_of($id) };
47 }
48  
49 24 my %ID;
50 24 for my $id (1 .. CARDS) { $ID{ name_of($id) } = $id }
51  
52 38841 ▶sub id_of {
Subroutine id_of: called CC=2 SCAR=6.9
Pod documented
53 38841 my ($name) = @_;
54 38841 ▶ return undef unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 38840 38841
55 38840 return $ID{ uc $name };
56 }
57  
58 37 ▶sub ids_of_ranks {
Subroutine ids_of_ranks: called CC=1 SCAR=0.0
Pod documented
59 37 my ($want) = @_;
60 37 my %keep = map { $_ => 1 } @$want;
61 37 return [ grep { $keep{ rank_of($_) } } 1 .. CARDS ];
62 }
63  
64 24 1;
65  
66 __END__
« blib/lib/Game/Schnapsen/Declare.pm ↑ Summary blib/lib/Game/Schnapsen/Hand.pm »