DataObjects/Player.pm

filter: Statementstmt 27.9% 64 / 229 Branchbran 4.1% 4 / 96 Conditioncond 6.4% 2 / 31 MC/DCmcdc 5.8% 1 / 17 Subroutinesub 45.6% 21 / 46 Podpod 77.2% 17 / 22 totaltotal 24.7% 109 / 441 CC 66 SCAR 39.4
CC
66
Cov
20%
delete_game
272.0
adj_rating
42.0
no_result
30.0
CRAP 51.5
« DataObjects/Tournament.pm ↑ Summary DataObjects/Register.pm »
1 #===============================================================================
2 #
3 # FILE: Games::Go::AGA::DataObjects::Player.pm
4 # PODNAME: Games::Go::AGA::DataObjects::Player
5 # ABSTRACT: model an AGA player
6 #
7 # AUTHOR: Reid Augustin (REID), <reid@com->full_name
8 # CREATED: 11/19/2010 03:13:05 PM PST
9 #===============================================================================
10  
11  
12 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 package Games::Go::AGA::DataObjects::Player;
16 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use Carp qw{ cluck carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Scalar::Util qw( refaddr looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use Games::Go::AGA::Parse::Util qw( normalize_ID Rank_to_Rating );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use Games::Go::AGA::DataObjects::Types qw( is_ID is_Rating is_Rank_or_Rating isa_ArrayRef isa_Num isa_CodeRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 our $VERSION = '0.152'; # VERSION
25  
26 5 our $deprecate = 0;
27 has id => (
28 is => 'rw',
29 33 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
30 33 ▶ confess("$_[0] is not an ID\n") if (not is_ID($_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if not is_ID($_[0]) 0 33 33
31 },
32 33 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 # TODO: make this a coercion?
34 33 my ($self, $new) = @_;
35 33 $self->{id} = normalize_ID($new);
36 33 $self->changed;
37 },
38 5 );
39 has last_name => (
40 is => 'rw',
41 29 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 5 );
43 has first_name => (
44 is => 'rw',
45 29 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 5 );
47 has rank => (
48 is => 'rw',
49 30 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
50 30 ▶ confess("$_[0] is not a Rank or Rating\n") if (not is_Rank_or_Rating($_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if not is_Rank_or_Rating($_[0]) 0 30 30
51 },
52 30 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
53 30 my ($self, $new) = @_;
54 30 ▶ if (is_Rating($new)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_Rating($new)) 17 13 30
55 17 $self->{rank} += 0; # force numification
56 }
57 30 shift->changed;
58 },
59 5 );
60 has date => (
61 is => 'rw',
62 lazy => 1,
63 default => '',
64 0 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 5 );
66 has membership => (
67 is => 'rw',
68 lazy => 1,
69 default => '',
70 0 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 5 );
72 has state => (
73 is => 'rw',
74 lazy => 1,
75 default => '',
76 0 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 5 );
78 has club => (
79 is => 'rw',
80 lazy => 1,
81 default => '',
82 18 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 18 my $self = shift;
84 18 $self->{club} = uc $self->{club};
85 18 $self->changed;
86 },
87 5 );
88 5 has flags => (
89 is => 'rw',
90 isa => \&isa_ArrayRef,
91 );
92 has comment => (
93 is => 'rw',
94 lazy => 1,
95 default => '',
96 22 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 5 );
98 has sigma => (
99 is => 'rw',
100 isa => \&isa_Num,
101 0 ▶ trigger => sub { shift->changed; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 5 );
103 has games => (
104 is => 'rw',
105 isa => \&isa_ArrayRef,
106 lazy => 1,
107 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 # trigger => sub { shift->changed; },
109 5 );
110 has change_callback => (
111 is => 'rw',
112 isa => \&isa_CodeRef,
113 lazy => 1,
114 29 ▶ default => sub { sub { } }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
115 5 );
116 has _adj_ratings => ( # array of adjusted ratings, one per round_num, but not 0
117 is => 'lazy',
118 isa => \&isa_ArrayRef,
119 0 ▶ default => sub { [] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 5 );
121  
122 29 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
123 29 my ($self) = @_;
124 29 ▶ $self->{flags} ||= []; # empty array
Condition100%2/2
$self->{"flags"} ||= []
l!l
254
MC/DC100%1/1
$self->{"flags"} ||= []
$self->{"flags"}
Truth table100%2/2
A
A= $self->{"flags"}
Aresult
11
00
125 }
126  
127 161 ▶sub changed {
Subroutine changed: called CC=1 SCAR=0.0
Pod undocumented
128 161 my ($self) = @_;
129  
130 161 &{$self->change_callback}(@_);
131 }
132  
133 0 ▶sub full_name {
Subroutine full_name: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my ($self) = @_;
135  
136 0 ▶ if (my $name = $self->first_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->first_name) 0 0 0
137 0 return join(', ', $self->last_name, $name),
138 }
139 # some players don't have first name
140 0 return $self->last_name;
141 }
142  
143  
144 # sub comment {
145 # my $self = shift;
146 # if (@_) {
147 # if (defined $_[0]) {
148 # $self->{comment} = join '', @_;
149 # }
150 # else {
151 # delete $self->{comment};
152 # }
153 # }
154 # return $self->{comment};
155 # }
156  
157 0 ▶sub add_game {
Subroutine add_game: not called CC=4 SCAR=30.0
Pod documented
158 0 my ($self, $game, $idx) = @_;
159  
160 0 ▶croak("Player::add_game deprecated: Use tournament->round->games list instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
161 0 my $add_refaddr = refaddr $game; # ID of game to add
162 0 ▶ if(not grep { (refaddr $_) == $add_refaddr } @{$self->{games}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({builtin::refaddr($_) == $add_refaddr;} @{$$self{"games"};})) 0 0 0
163 #print STDERR "add_game $game to " . $self->full_name . "\n";
164 0 ▶ if (@_ < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 3) { } 0 0 0
165 0 push @{$self->{games}}, $game;
166 }
167 else {
168 0 splice @{$self->{games}}, $idx, 0, $game;
169 }
170 #$self->changed;
171 }
172 }
173  
174 0 ▶sub delete_game {
Subroutine delete_game: not called CC=16 SCAR=56.1
Pod documented
175 0 my ($self, $idx, $id1) = @_;
176  
177 0 ▶croak("Player::delete_game deprecated: Use tournament->round->games list instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
178 0 my $games = $self->{games};
179 0 ▶ if (not looks_like_number($idx)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($idx)) 0 0 0
180 0 ▶ if (ref $idx) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $idx) { } 0 0 0
elsif ($id1) { } 0 0 0
181 # $idx is actually a Game object, find its idx in our games
182 # list
183 0 my $game = $idx;
184 0 my $refaddr = refaddr($game);
185 0 for my $ii (0 .. $#{$games}) {
186 0 ▶ if (refaddr($games->[$ii]) == $refaddr) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($games->[$ii]) == $refaddr) 0 0 0
187 0 $idx = $ii;
188 0 last;
189 }
190 }
191 }
192 elsif ($id1) {
193 0 my $id0 = $idx; # idx is actually ID_0
194 0 for my $ii (0 .. $#{$games}) {
195 0 ▶ if (($games->[$ii]->black->id eq $id0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($games->[$ii]->black->id eq $id0 and $games->[$ii]->white->id eq $id1 or $games->[$ii]->black->id eq $id1 and $games->[$ii]->white->id eq $id0) 0 0 0
Condition0%0/9
$games->[$ii]->black->id eq $id0 and $games->[$ii]->white->id eq $id1 or $games->[$ii]->black->id eq $id1 and $games->[$ii]->white->id eq $id0
l!l&&r!l&&!r
000
$games->[$ii]->black->id eq $id0 and $games->[$ii]->white->id eq $id1
!ll&&!rl&&r
000
$games->[$ii]->black->id eq $id1 and $games->[$ii]->white->id eq $id0
!ll&&!rl&&r
000
MC/DC0%0/4
$games->[$ii]->black->id eq $id0 and $games->[$ii]->white->id eq $id1 or $games->[$ii]->black->id eq $id1 and $games->[$ii]->white->id eq $id0
$games->[$ii]->black->id eq $id0 $games->[$ii]->white->id eq $id1 $games->[$ii]->black->id eq $id1 $games->[$ii]->white->id eq $id0
Truth table0%0/7
A and B or C and D
A= $games->[$ii]->black->id eq $id0B= $games->[$ii]->white->id eq $id1C= $games->[$ii]->black->id eq $id1D= $games->[$ii]->white->id eq $id0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
196 $games->[$ii]->white->id eq $id1) or
197 ($games->[$ii]->black->id eq $id1 and
198 $games->[$ii]->white->id eq $id0)) {
199 0 $idx = $ii;
200 0 last;
201 }
202 }
203 }
204 }
205 0 ▶ if (not looks_like_number($idx)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($idx)) 0 0 0
206 0 ▶ if (ref $idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $idx) { } 0 0 0
207 0 croak(sprintf "Can't find game %s vs %s in games list for %s\n",
208 $idx->white->last_name,
209 $idx->black->last_name,
210 $self->id,
211 );
212 }
213 else {
214 0 ▶ $idx ||= '<>';
Condition0%0/2
$idx ||= "<>"
l!l
00
MC/DC0%0/1
$idx ||= "<>"
$idx
Truth table0%0/2
A
A= $idx
Aresult
11
00
215 0 ▶ $id1 ||= '<>';
Condition0%0/2
$id1 ||= "<>"
l!l
00
MC/DC0%0/1
$id1 ||= "<>"
$id1
Truth table0%0/2
A
A= $id1
Aresult
11
00
216 0 my $id = $self->id;
217 0 croak("Can't find game $idx vs $id1 in games list for $id\n");
218 }
219 }
220 0 splice(@{$games}, $idx, 1); # remove from list
221 #$self->changed; # not recorded in any file, so ignore
222 0 return $idx;
223 }
224  
225 0 ▶sub adj_rating {
Subroutine adj_rating: not called CC=6 SCAR=37.4
Pod documented
226 0 my ($self, $round_num, $new) = @_;
227  
228 0 ▶ $round_num ||= -1; # if no round number, use last round
Condition0%0/2
$round_num ||= -1
l!l
00
MC/DC0%0/1
$round_num ||= -1
$round_num
Truth table0%0/2
A
A= $round_num
Aresult
11
00
229 0 ▶ croak('adj_rating: round_num not valid') if ($round_num < -1);
Branch: 1 branch
BranchTrueFalseTotal
if $round_num < -1 0 0 0
230 # there is no round_num 0, but -1 is allowed
231  
232 0 ▶ $self->{adj_rating} = [] if (not $self->{adj_rating});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"adj_rating"} 0 0 0
233 0 my $adj_rating = $self->{adj_rating};
234 0 ▶ if (@_ > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 0 0
235 0 $self->_adj_ratings->[$round_num] = $new;
236 }
237 # rating if no adjusted rating has been set
238 0 ▶ return $self->rating if (not $self->_adj_ratings->[$round_num]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_adj_ratings->[$round_num] 0 0 0
239 0 return $self->_adj_ratings->[$round_num];
240 }
241  
242 0 ▶sub handicap_rating {
Subroutine handicap_rating: not called CC=3 SCAR=24.8
Pod documented
243 0 my ($self, $new) = @_;
244  
245 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
246 0 $self->{handicap_rating} = $new;
247 }
248 return defined $self->{handicap_rating}
249 ? $self->{handicap_rating}
250 0 ▶ : $self->rating;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'handicap_rating'} ? : 0 0 0
251 }
252  
253 0 ▶sub opponents {
Subroutine opponents: not called CC=3 SCAR=24.8
Pod documented
254 0 my ($self) = @_;
255  
256 0 ▶croak("Player::opponents deprecated: Use tournament->round->games list instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
257 0 my @opps = map { $_->opponent($self) } @{$self->{games}};
258 return wantarray ? @opps
259 0 ▶ : scalar @opps;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
260 }
261  
262 0 ▶sub defeated {
Subroutine defeated: not called CC=4 SCAR=30.0
Pod documented
263 0 my ($self) = @_;
264  
265 0 ▶croak("Player::defeated deprecated: Use tournament->player_defeated instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
266 0 my $me = refaddr $self;
267 0 my @defeated = map { $_->loser }
268 0 ▶ grep { defined $_->winner and
Condition0%0/3
defined $_->winner && builtin::refaddr($_->winner) == $me
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->winner && builtin::refaddr($_->winner) == $me
defined $_->winner builtin::refaddr($_->winner) == $me
Truth table0%0/3
A && B
A= defined $_->winnerB= builtin::refaddr($_->winner) == $me
ABresult
0X0
100
111
269 0 (refaddr($_->winner) == $me) } @{$self->{games}};
270 return wantarray ? @defeated
271 0 ▶ : scalar @defeated;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
272 }
273  
274 0 ▶sub defeated_by {
Subroutine defeated_by: not called CC=4 SCAR=30.0
Pod documented
275 0 my ($self) = @_;
276  
277 0 ▶croak("Player::defeated_by deprecated: Use tournament->player_defeated_by instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
278 0 my $me = refaddr $self;
279 0 my @defeated_by = map { $_->winner }
280 0 ▶ grep { defined $_->loser and
Condition0%0/3
defined $_->loser && builtin::refaddr($_->loser) == $me
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->loser && builtin::refaddr($_->loser) == $me
defined $_->loser builtin::refaddr($_->loser) == $me
Truth table0%0/3
A && B
A= defined $_->loserB= builtin::refaddr($_->loser) == $me
ABresult
0X0
100
111
281 0 (refaddr($_->loser) == $me) } @{$self->{games}};
282 return wantarray ? @defeated_by
283 0 ▶ : scalar @defeated_by;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
284 }
285  
286 # games with no result (usually means still playing)
287 0 ▶sub no_result {
Subroutine no_result: not called CC=5 SCAR=34.0
Pod undocumented
288 0 my ($self) = @_;
289  
290 0 ▶croak("Player::defeated_by deprecated: Use tournament->player_no_result instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
291 0 my $me = refaddr $self;
292 0 ▶ my @no_result = map { (refaddr($_->black) == $me) ? $_->white : $_->black }
Branch: 1 branch
BranchTrueFalseTotal
builtin::refaddr($_->black) == $me ? : 0 0 0
293 0 ▶ grep { not defined $_->loser and
Condition0%0/3
defined $_->loser || defined $_->winner
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $_->loser || defined $_->winner
defined $_->loser defined $_->winner
Truth table0%0/3
A || B
A= defined $_->loserB= defined $_->winner
ABresult
1X1
011
000
294 0 not defined $_->winner } @{$self->{games}};
295 return wantarray ? @no_result
296 0 ▶ : scalar @no_result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
297 }
298  
299 0 ▶sub wins {
Subroutine wins: not called CC=4 SCAR=30.0
Pod documented
300 0 my ($self) = @_;
301  
302 0 ▶croak("Player::wins deprecated: Use tournament->player_wins instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
303 0 my $me = refaddr $self;
304 0 ▶ my @wins = grep { (refaddr($_->winner) || -1) == $me} @{$self->{games}};
Condition0%0/2
builtin::refaddr($_->winner) || -1
l!l
00
MC/DC0%0/1
builtin::refaddr($_->winner) || -1
builtin::refaddr($_->winner)
Truth table0%0/2
A
A= builtin::refaddr($_->winner)
Aresult
11
00
305 return wantarray ? @wins
306 0 ▶ : scalar @wins;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
307 }
308  
309 0 ▶sub losses {
Subroutine losses: not called CC=4 SCAR=30.0
Pod documented
310 0 my ($self) = @_;
311  
312 0 ▶croak("Player::losses deprecated: Use tournament->player_losses instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
313 0 my $me = refaddr $self;
314 0 ▶ my @losses = grep {defined $_->winner and
Condition0%0/3
defined $_->winner && builtin::refaddr($_->winner) != $me
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->winner && builtin::refaddr($_->winner) != $me
defined $_->winner builtin::refaddr($_->winner) != $me
Truth table0%0/3
A && B
A= defined $_->winnerB= builtin::refaddr($_->winner) != $me
ABresult
0X0
100
111
315 0 refaddr $_->winner != $me} @{$self->{games}};
316 return wantarray ? @losses
317 0 ▶ : scalar @losses;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
318 }
319  
320 0 ▶sub completed_games {
Subroutine completed_games: not called CC=3 SCAR=24.8
Pod undocumented
321 0 my ($self) = @_;
322  
323 0 ▶croak("Player::completed_games deprecated: Use tournament->round->games list instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
324 0 my @games = grep { $_->winner } @{$self->{games}};
325 return wantarray ? @games
326 0 ▶ : scalar @games;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
327 }
328  
329 0 ▶sub drop {
Subroutine drop: not called CC=5 SCAR=34.0
Pod documented
330 0 my ($self, $round_num) = @_;
331  
332 0 ▶croak("Player::drop deprecated: Use tournament->get_directive('DROP') instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
333 0 ▶ return 1 if ($self->get_flag('drop'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_flag("drop") 0 0 0
334 0 ▶ if (defined $round_num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $round_num) 0 0 0
335 0 ▶ return 1 if ($self->get_flag("drop$round_num"));
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_flag("drop$round_num") 0 0 0
336 }
337 0 return 0;
338 }
339  
340 0 ▶sub bye {
Subroutine bye: not called CC=2 SCAR=17.9
Pod documented
341 0 my ($self) = @_;
342  
343 0 ▶croak("Player::bye deprecated: Use tournament->get_directive('BYE_CANDIDATE') instead\n") if ($deprecate > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Games::Go::AGA::DataObjects::Player::deprecate > 0 0 0 0
344 0 return $self->get_flag('bye');
345 }
346  
347 0 ▶sub get_flag {
Subroutine get_flag: not called CC=3 SCAR=24.8
Pod documented
348 0 my ($self, $key) = @_;
349  
350 0 my $flags = $self->{flags};
351 0 my $ii = 0;
352 0 for (@{$flags}) {
353 0 ▶ last if (uc $key eq uc $flags->[$ii]);
Branch: 1 branch
BranchTrueFalseTotal
if uc $key eq uc $flags->[$ii] 0 0 0
354 0 $ii++;
355 }
356 0 return $flags->[$ii];
357 }
358  
359 0 ▶sub set_flag {
Subroutine set_flag: not called CC=3 SCAR=24.8
Pod documented
360 0 my ($self, $key) = @_;
361  
362 0 my $flags = $self->{flags};
363 0 my $ii = 0;
364 0 for (@{$flags}) {
365 0 ▶ last if (uc $key eq uc $flags->[$ii]);
Branch: 1 branch
BranchTrueFalseTotal
if uc $key eq uc $flags->[$ii] 0 0 0
366 0 $ii++;
367 }
368 0 $flags->[$ii] = $key; # add if not there, overwrite if it is
369 0 $self->changed;
370 0 return $flags->[$ii];
371 }
372  
373 0 ▶sub clear_flag {
Subroutine clear_flag: not called CC=4 SCAR=30.0
Pod documented
374 0 my ($self, $key) = @_;
375  
376 0 my $flags = $self->{flags};
377 0 my $ii = 0;
378 0 for (@{$flags}) {
379 0 ▶ last if (uc $key eq uc $flags->[$ii]);
Branch: 1 branch
BranchTrueFalseTotal
if uc $key eq uc $flags->[$ii] 0 0 0
380 0 $ii++;
381 }
382 0 ▶ if ($ii < @{$flags}) { # if element was found
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < @{$flags;}) 0 0 0
383 0 splice @{$flags}, $ii, 1; # remove it
384 0 $self->changed;
385 }
386 }
387  
388 36 ▶sub rating {
Subroutine rating: called CC=1 SCAR=0.0
Pod documented
389 36 my ($self) = @_;
390  
391 36 return Rank_to_Rating($self->rank);
392 }
393  
394 # in register.tde format
395 0 ▶sub fprint_register {
Subroutine fprint_register: not called CC=4 SCAR=30.0
Pod documented
396 0 my ($self, $fh) = @_;
397  
398 0 my @flags = @{$self->{flags}};
399 0 ▶ push(@flags, "Club=" . $self->club) if ($self->club);
Branch: 1 branch
BranchTrueFalseTotal
if $self->club 0 0 0
400  
401 0 $fh->printf("%s %s, %s %s",
402 $self->id,
403 $self->last_name,
404 $self->first_name,
405 $self->rank,
406 );
407 0 ▶ $fh->printf(" %s", join(' ', @flags)) if (@flags);
Branch: 1 branch
BranchTrueFalseTotal
if @flags 0 0 0
408 0 my $comment = $self->comment;
409 0 ▶ if ($comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment) 0 0 0
410 0 $comment =~ s/\n/\\n/g; # prevent newlines which would mess things up
411 0 $comment =~ s/^\s*(.*?)\s*$/$1/; # remove preceding and trailing whitespace
412 0 $fh->print(" # $comment");
413 }
414 0 $fh->print("\n");
415 }
416  
417 # in tdlist format
418 0 ▶sub fprint_tdlist {
Subroutine fprint_tdlist: not called CC=1 SCAR=6.9
Pod documented
419 0 my ($self, $fh) = @_;
420  
421 0 $fh->printf("%s, %s %s %s %s %s %s %s\n",
422 $self->last_name,
423 $self->first_name,
424 $self->id,
425 $self->membership,
426 $self->rank,
427 $self->date,
428 $self->club,
429 $self->state,
430 );
431 }
432  
433 5 1;
434  
435 __END__
« DataObjects/Tournament.pm ↑ Summary DataObjects/Register.pm »