line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
3024
|
use 5.16.0; |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
273
|
|
2
|
8
|
|
|
8
|
|
36
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
424
|
|
3
|
|
|
|
|
|
|
package Games::Nintendo::Mario; |
4
|
|
|
|
|
|
|
our $VERSION = 0.208; # <-- for PAUSE indexer |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Games::Nintendo::Mario - a class for jumping Italian plumbers |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
version 0.208 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Games::Nintendo::Mario; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $hero = Games::Nintendo::Mario->new(name => 'Luigi'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$hero->damage; # cue the Mario Death Music |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module provides a base class for representing the Mario Brothers from |
25
|
|
|
|
|
|
|
Nintendo's long-running Mario franchise of games. Each Mario object keeps |
26
|
|
|
|
|
|
|
track of the plumber's current state and can be damaged or given powerups to |
27
|
|
|
|
|
|
|
change his state. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
8
|
|
|
8
|
|
43
|
use Carp qw(cluck); |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
5746
|
|
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
2
|
|
9
|
sub _names { qw[Mario Luigi] } |
34
|
1
|
|
|
1
|
|
4
|
sub _states { qw[normal] } |
35
|
1
|
|
|
1
|
|
754
|
sub _items { () } |
36
|
38
|
|
|
38
|
|
112
|
sub _other_defaults { () } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _goto_hash { |
39
|
0
|
|
|
0
|
|
0
|
{ damage => 'dead' } |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _goto { |
43
|
28
|
|
|
28
|
|
35
|
my $self = shift; |
44
|
28
|
|
|
|
|
39
|
my ($state, $item) = @_; |
45
|
28
|
|
|
|
|
72
|
my $goto = $self->_goto_hash; |
46
|
|
|
|
|
|
|
|
47
|
28
|
100
|
|
|
|
83
|
return unless exists $goto->{$item}; |
48
|
19
|
100
|
|
|
|
53
|
return $goto->{$item} unless ref $goto->{$item} eq 'HASH'; |
49
|
18
|
100
|
|
|
|
622
|
return $goto->{$item}{_else} unless $goto->{$item}{$state}; |
50
|
5
|
|
|
|
|
20
|
return $goto->{$item}{$state}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 C |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $hero = Games::Nintendo::Mario->new(name => 'Luigi'); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The constructor for Mario objects takes two named parameters, C and |
60
|
|
|
|
|
|
|
C. C must be either "Mario" or "Luigi" and C must be |
61
|
|
|
|
|
|
|
"normal" |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
If left undefined, C and C will default to "Mario" and "normal" |
64
|
|
|
|
|
|
|
respectively. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new { |
69
|
41
|
|
|
41
|
1
|
209
|
my $class = shift; |
70
|
41
|
|
|
|
|
158
|
my %args = (name => 'Mario', state => 'normal', @_); |
71
|
|
|
|
|
|
|
|
72
|
41
|
50
|
|
|
|
158
|
unless (grep { $_ eq $args{name} } $class->_names) { |
|
106
|
|
|
|
|
302
|
|
73
|
0
|
|
|
|
|
0
|
cluck "bad name for plumber"; |
74
|
0
|
|
|
|
|
0
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
41
|
50
|
|
|
|
148
|
unless (grep { $_ eq $args{state} } $class->_states) { |
|
210
|
|
|
|
|
400
|
|
77
|
0
|
|
|
|
|
0
|
cluck "bad starting state for plumber"; |
78
|
0
|
|
|
|
|
0
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
41
|
|
|
|
|
159
|
my $plumber = { |
82
|
|
|
|
|
|
|
state => $args{state}, |
83
|
|
|
|
|
|
|
name => $args{name}, |
84
|
|
|
|
|
|
|
$class->_other_defaults |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
41
|
|
|
|
|
334
|
bless $plumber => $class; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 C |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$hero->powerup('hammer'); # this won't work |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
As the base Games::Nintendo::Mario class represents Mario from the original |
95
|
|
|
|
|
|
|
Mario Bros., there is no valid way to call this method. Subclasses |
96
|
|
|
|
|
|
|
representing Mario in other games may allow various powerup names to be passed. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub powerup { |
101
|
19
|
|
|
19
|
1
|
29
|
my $plumber = shift; |
102
|
19
|
|
|
|
|
26
|
my $item = shift; |
103
|
|
|
|
|
|
|
|
104
|
19
|
50
|
|
|
|
36
|
if ($plumber->state eq 'dead') { |
105
|
0
|
|
|
|
|
0
|
cluck "$plumber->{name} can't power up when dead"; |
106
|
0
|
|
|
|
|
0
|
return $plumber; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
19
|
50
|
|
|
|
61
|
unless (grep { $_ eq $item } $plumber->_items) { |
|
52
|
|
|
|
|
112
|
|
110
|
0
|
|
|
|
|
0
|
cluck "$plumber->{name} can't power up with that!"; |
111
|
0
|
|
|
|
|
0
|
return $plumber; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
19
|
|
|
|
|
612
|
my $goto = $plumber->_goto($plumber->state,$item); |
115
|
|
|
|
|
|
|
|
116
|
19
|
100
|
|
|
|
52
|
$plumber->{state} = $goto if $goto; |
117
|
|
|
|
|
|
|
|
118
|
19
|
|
|
|
|
55
|
return $plumber; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 C |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$hero->damage; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This method causes the object to react as if Mario has been attacked or |
126
|
|
|
|
|
|
|
damaged. In the base Games::Nintendo::Mario class, this will always result in |
127
|
|
|
|
|
|
|
his death. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub damage { |
132
|
9
|
|
|
9
|
1
|
17
|
my $plumber = shift; |
133
|
|
|
|
|
|
|
|
134
|
9
|
|
|
|
|
20
|
my $goto = $plumber->_goto($plumber->state,'damage'); |
135
|
|
|
|
|
|
|
|
136
|
9
|
100
|
|
|
|
42
|
$plumber->{state} = $goto if $goto; |
137
|
|
|
|
|
|
|
|
138
|
9
|
|
|
|
|
27
|
return $plumber; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 C |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
print $hero->state; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This method accesses the name of Mario's current state. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub state { ## no critic Homonym |
150
|
110
|
|
|
110
|
1
|
143
|
my $plumber = shift; |
151
|
|
|
|
|
|
|
|
152
|
110
|
|
|
|
|
493
|
return $plumber->{state}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 C |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
print $hero->name; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This method returns the name of the plumber's current form. (In the base |
160
|
|
|
|
|
|
|
class, this is always the same as the name passed to the constructor.) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub name { |
165
|
6
|
|
|
6
|
1
|
4786
|
my $plumber = shift; |
166
|
|
|
|
|
|
|
|
167
|
6
|
100
|
|
|
|
51
|
return $plumber->{name} if $plumber->state eq 'normal'; |
168
|
|
|
|
|
|
|
|
169
|
1
|
|
|
|
|
4
|
my $name = $plumber->state . q{ } . $plumber->{name}; |
170
|
1
|
|
|
|
|
21
|
$name =~ s/(^.)/\u$1/; |
171
|
1
|
|
|
|
|
9
|
return $name; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 C |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
if (grep /World/, $hero->games) { ... } |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This returns a list of the games in which Mario behaved according to the model |
179
|
|
|
|
|
|
|
provided by this class. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub games { |
184
|
0
|
|
|
0
|
1
|
|
return ('Mario Bros.'); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
"It's-a me! Mario!"; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 TODO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Wario, SMW. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Ricardo SIGNES Erjbs@cpan.orgE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 COPYRIGHT |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Copyright 2003 by Ricardo SIGNES Erjbs@cpan.orgE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
202
|
|
|
|
|
|
|
the same terms as Perl itself. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |