blib/lib/Game/Mahjong/Tiles.pm

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