blib/lib/Game/Mahjong/Tiles.pm

filter: Statementstmt 100% 53 / 53 Branchbran 92.8% 13 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 6 / 6 totaltotal 96.9% 94 / 97 CC 11 SCAR 9.9
CC
11
Cov
97%
name_of
5.0
suit_name
4.1
next_in_suit
3.0
CRAP 2.7
« blib/lib/Game/Mahjong/Tally.pm ↑ Summary blib/arch/Game/Mahjong/Install/Files.pm »
1 package Game::Mahjong::Tiles;
2  
3 34 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 our $VERSION = '0.03';
8  
9 34 ▶use constant KINDS => 34;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 34 ▶use constant BONUS => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 34 ▶use constant PATTERNS => 42;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 34 ▶use constant PER_KIND => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 34 ▶use constant TILES => 144;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 34 my @RANK = qw(one two three four five six seven eight nine);
16 34 my %SUIT = (m => 'characters', p => 'dots', s => 'bamboo');
17 34 my @WIND = qw(east south west north);
18 34 my @DRAGON = qw(red green white);
19 34 my @FLOWER = qw(plum orchid bamboo chrysanthemum);
20 34 my @SEASON = qw(spring summer autumn winter);
21  
22 316 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod documented
23 316 my @set;
24 316 for my $kind (1 .. KINDS) {
25 10744 push @set, ($kind) x PER_KIND;
26 }
27 316 push @set, (KINDS + 1) .. PATTERNS;
28 316 return @set;
29 }
30  
31 1 ▶sub kinds { return (1 .. KINDS) }
Subroutine kinds: called CC=1 SCAR=0.0
Pod documented
32  
33 1 ▶sub patterns { return (1 .. PATTERNS) }
Subroutine patterns: called CC=1 SCAR=0.0
Pod documented
34  
35 51 ▶sub name_of {
Subroutine name_of: called CC=5 SCAR=16.1
Pod documented
36 51 my ($kind) = @_;
37 51 my $code = code_of($kind);
38 51 ▶ if (my $suit = suit_of($kind)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $suit = suit_of($kind)) 30 21 51
39 30 return $RANK[ rank_of($kind) - 1 ] . ' of ' . $SUIT{$suit};
40 }
41 21 ▶ return $WIND[ wind_index($kind) ] . ' wind' if is_wind($kind);
Branch: 1 branch
BranchTrueFalseTotal
if is_wind($kind) 5 16 21
42 16 ▶ return $DRAGON[ dragon_index($kind) ] . ' dragon' if is_dragon($kind);
Branch: 1 branch
BranchTrueFalseTotal
if is_dragon($kind) 4 12 16
43 12 ▶ return $FLOWER[ bonus_index($kind) ] if is_flower($kind);
Branch: 1 branch
BranchTrueFalseTotal
if is_flower($kind) 7 5 12
44 5 return $SEASON[ bonus_index($kind) ];
45 }
46  
47 2 ▶sub suit_name {
Subroutine suit_name: called CC=4 SCAR=14.2
Pod documented
48 2 my ($letter) = @_;
49 die "Game::Mahjong::Tiles: there is no suit '" . (defined $letter ? $letter : 'undef') . "'"
50 2 ▶ unless defined $letter && $SUIT{$letter};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $letter and $SUIT{$letter} 1 1 2
defined $letter ? : 1 0 1
Condition66%2/3
defined $letter and $SUIT{$letter}
!ll&&!rl&&r
011
MC/DC50%1/2
defined $letter and $SUIT{$letter}
defined $letter $SUIT{$letter}
Truth table66%2/3
A and B
A= defined $letterB= $SUIT{$letter}
ABresult
0X0
100
111
51 1 return $SUIT{$letter};
52 }
53  
54 4 ▶sub next_in_suit {
Subroutine next_in_suit: called CC=3 SCAR=11.0
Pod documented
55 4 my ($kind) = @_;
56 4 my $rank = rank_of($kind);
57 4 ▶ return undef unless defined $rank && $rank < 9;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rank and $rank < 9 3 1 4
Condition100%3/3
defined $rank and $rank < 9
!ll&&!rl&&r
121
MC/DC100%2/2
defined $rank and $rank < 9
defined $rank $rank < 9
Truth table100%3/3
A and B
A= defined $rankB= $rank < 9
ABresult
0X0
100
111
58 1 return $kind + 1;
59 }
60  
61 34 1;
62  
63 __END__
« blib/lib/Game/Mahjong/Tally.pm ↑ Summary blib/arch/Game/Mahjong/Install/Files.pm »