Mario/Hearts.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 92.8% 13 / 14 Podpod 100% 5 / 5 totaltotal 86.1% 62 / 72 SCAR 19.5
CC
7
Cov
90%
powerup
4.1
damage
3.0
hearts
2.0
CRAP 7.1
« Mario.pm ↑ Summary Mario/SMB2.pm »
1 4 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Games::Nintendo::Mario::Hearts 0.208;
4  
5 4 ▶use parent qw(Games::Nintendo::Mario);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub _states { qw[normal] }
Subroutine _states: called CC=1 SCAR=0.0
9 1 ▶sub _items { qw[heart] }
Subroutine _items: called CC=1 SCAR=0.0
10 3 ▶sub _other_defaults { ( max_hearts => 3 ) }
Subroutine _other_defaults: called CC=1 SCAR=0.0
11 3 ▶sub __default_hearts { 1 };
Subroutine __default_hearts: called CC=1 SCAR=0.0
12  
13 3 ▶sub _goto_hash { {} } # not used by base Hearts class
Subroutine _goto_hash: called CC=1 SCAR=0.0
14  
15 sub max_hearts {
16 return $_[0]->{max_hearts}
17 10 ▶}
Subroutine max_hearts: called CC=1 SCAR=0.0
Pod documented
18  
19 4 fieldhash my %hearts;
20 sub hearts {
21 41 ▶ my ($self) = @_;
Subroutine hearts: called CC=2 SCAR=7.0
Pod documented
22 41 ▶ $hearts{ $self } //= $self->__default_hearts;
Condition66%2/3
$hearts{$self} //= $self->__default_hearts
l!l&&r!l&&!r
3830
MC/DC0%0/2
$hearts{$self} //= $self->__default_hearts
$hearts{$self} $self->__default_hearts
Truth table66%2/3
A //= B
A= $hearts{$self}B= $self->__default_hearts
ABresult
1X1
011
000
23 41 return $hearts{ $self };
24 }
25  
26 sub powerup {
27 5 ▶ my $plumber = shift;
Subroutine powerup: called CC=4 SCAR=14.0
Pod documented
28 5 my $item = shift;
29  
30 5 ▶ if (($item eq 'heart') and ($plumber->hearts) and ($plumber->hearts < $plumber->max_hearts)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item eq "heart" and $plumber->hearts and $plumber->hearts < $plumber->max_hearts) 2 3 5
Condition66%4/6
$item eq "heart" and $plumber->hearts and $plumber->hearts < $plumber->max_hearts
!ll&&!rl&&r
302
$item eq "heart" and $plumber->hearts
!ll&&!rl&&r
302
MC/DC33%1/3
$item eq "heart" and $plumber->hearts and $plumber->hearts < $plumber->max_hearts
$item eq "heart" $plumber->hearts $plumber->hearts < $plumber->max_hearts
Truth table50%2/4
A and B and C
A= $item eq "heart"B= $plumber->heartsC= $plumber->hearts < $plumber->max_hearts
ABCresult
0XX0
10X0
1100
1111
31 2 $hearts{ $plumber }++;
32 }
33 5 $plumber->SUPER::powerup($item);
34 }
35  
36 sub damage {
37 4 ▶ my $self = shift;
Subroutine damage: called CC=3 SCAR=11.0
Pod documented
38 4 my $item = shift;
39  
40 4 ▶ if ($self->hearts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hearts) 4 0 4
41 4 ▶ $self->{state} = 'dead' unless --$hearts{ $self };
Branch: 1 branch
BranchTrueFalseTotal
unless --$hearts{$self} 2 2 4
42 }
43  
44 4 $self->SUPER::damage;
45 }
46  
47 sub games {
48 0 ▶ return ();
Subroutine games: not called CC=1 SCAR=6.9
Pod documented
49 }
50  
51 4 "It's-a me! Mario!";
52  
53 __END__
« Mario.pm ↑ Summary Mario/SMB2.pm »