File Coverage

blib/lib/Games/Tournament.pm
Criterion Covered Total %
statement 155 311 49.8
branch 45 108 41.6
condition 10 42 23.8
subroutine 27 44 61.3
pod 29 29 100.0
total 266 534 49.8


line stmt bran cond sub pod time code
1             package Games::Tournament;
2             $Games::Tournament::VERSION = '0.20';
3             # Last Edit: 2016 Jan 01, 13:44:32
4             # $Id: $
5              
6 30     30   4576 use warnings;
  30         50  
  30         814  
7 30     30   140 use strict;
  30         47  
  30         588  
8 30     30   134 use Carp;
  30         47  
  30         1820  
9              
10 30     30   147 use List::Util qw/first/;
  30         44  
  30         2699  
11 30     30   1776 use List::MoreUtils qw/any all/;
  30         23895  
  30         209  
12 30     30   14584 use Scalar::Util qw/looks_like_number/;
  30         51  
  30         2477  
13 30     30   150 use Scalar::Util qw/looks_like_number/;
  30         59  
  30         1121  
14              
15 30     30   790 use Games::Tournament::Swiss::Config;
  30         63  
  30         1388  
16 30 100       1643 use constant ROLES => @Games::Tournament::Swiss::Config::roles?
17             @Games::Tournament::Swiss::Config::roles:
18 30     30   161 Games::Tournament::Swiss::Config->roles;
  30         44  
19 30     30   141 use constant FIRSTROUND => $Games::Tournament::Swiss::Config::firstround;
  30         50  
  30         113983  
20              
21             =head1 NAME
22              
23             Games::Tournament - Contestant Pairing
24              
25             =cut
26              
27             =head1 SYNOPSIS
28              
29             $tourney = Games::Tournament->new(\@entrants);
30             next if $capablanca->met($alekhine)
31              
32             $round = $tourney->meeting($member1, [$member2, $member3]);
33             ...
34              
35             =head1 DESCRIPTION
36              
37             In a tournament, there are contestants, and matches over rounds between the contestants, in which they are differentiated by role. TODO firstround and roles.
38              
39             =head1 METHODS
40              
41             =head2 new
42              
43             Games::Tournament->new( rounds => 2, entrants => [ $a, $b, $c ] )
44              
45             Creates a competition for entrants, over a number of rounds. entrants is a list of player objects. Enters (see enter method) each of the entrants in the tournament. (But why is the entrants arg being deleted?)
46              
47             =cut
48              
49             sub new {
50 96     96 1 663 my $self = shift;
51 96         310 my %args = @_;
52 96         185 my $entrants = $args{entrants};
53 96         174 delete $args{entrants};
54 96         212 my $object = bless \%args, $self;
55 96         239 for my $entrant ( @$entrants ) { $object->enter( $entrant ); }
  1758         3493  
56 96         280 return $object;
57             }
58              
59              
60             =head2 enter
61              
62             $tourney->enter($player)
63              
64             Enters a Games::Tournament::Contestant player object with a rating, title id, and name in the entrants of the tournament. Die if no name or id. We are authoritarians. Warn if no rating defined. No check for duplicate ids. Set this round as their first round, unless they already entered in an earlier round (But did they play in that round?) Set their absent accessor if they are in absentees.
65              
66             =cut
67              
68             sub enter {
69 1762     1762 1 15987 my $self = shift;
70 1762         1978 my $player = shift;
71 1762         2995 my $round = $self->round;
72 1762 50       4868 die "Player " . $player->id . " entering in Round $round + 1?" unless
73             looks_like_number($round);
74 1762 100       4100 $player->firstround($round+1) unless $player->firstround;
75 1762         4085 my $absent = $self->absentees;
76 1762         2124 my @absentids;
77 1762 50 33     3735 @absentids = map { $_->id } @$absent if $absent and ref $absent eq 'ARRAY';
  0         0  
78 1762 50   0   7222 $player->absent(1) if any { $_ eq $player->id } @absentids;
  0         0  
79 1762         5362 my $entrants = $self->entrants;
80 1762         2688 for my $required ( qw/id name/ ) {
81 3524 50       8439 unless ( $player->$required ) {
82 0         0 croak "No $required for player " . $player->id;
83             }
84             }
85 1762         2484 for my $recommended ( qw/rating/ ) {
86 1762 50       4311 unless ( defined $player->$recommended ) {
87 0         0 carp "No $recommended for player " . $player->id;
88 0         0 $player->$recommended( 'None' );
89             }
90             }
91 1762         2755 push @$entrants, $player;
92 1762         3288 $self->entrants( $entrants );
93             }
94              
95             =head2 rank
96              
97             @rankings = $tourney->rank(@players)
98              
99             Ranks a list of Games::Tournament::Contestant player objects by score, rating, title and name if they all have a score, otherwise ranks them by rating, title and name. This is the same ordering that is used to determine pairing numbers in a swiss tournament.
100              
101             =cut
102              
103             sub rank {
104 5377     5377 1 7407 my $self = shift;
105 5377         10643 my @players = @_;
106 5377 100   16565   21616 if ( all { defined $_->score } @players ) {
  16565         52271  
107             sort {
108 4769 50 100     12582 $b->score <=> $a->score
  17661   66     64467  
109             || $b->rating <=> $a->rating
110             || $a->title cmp $b->title
111             || $a->name cmp $b->name
112             } @players;
113             }
114             else {
115             sort {
116 608 50 66     1597 $b->rating <=> $a->rating
  10113         22863  
117             || $a->title cmp $b->title
118             || $a->name cmp $b->name
119             } @players;
120             }
121             }
122              
123             =head2 reverseRank
124              
125             @reverseRankings = $tourney->reverseRank(@players)
126              
127             Ranks in reverse order a list of Games::Tournament::Contestant player objects by score, rating, title and name if they all have a score, otherwise reverseRanks them by rating, title and name.
128              
129             =cut
130              
131             sub reverseRank {
132 0     0 1 0 my $self = shift;
133 0         0 my @players = @_;
134 0         0 my @rankers = $self->rank(@players);
135 0         0 return reverse @rankers;
136             }
137              
138              
139             #=head2 firstRound
140             #
141             # $tourney->firstRound(7)
142             #
143             #Gets/sets the first round in the competition in which the swiss system is used to pair opponents, when this might not be the first round of the competition.
144             #
145             #=cut
146             #
147             #field 'firstRound' => 1;
148              
149              
150             =head2 named
151              
152             $tourney->named($name)
153              
154             Returns a contestant whose name is $name, the first entrant with a name with stringwise equality. So beware same-named contestants.
155              
156             =cut
157              
158             sub named {
159 0     0 1 0 my $self = shift;
160 0         0 my $name = shift;
161 0         0 my $contestants = $self->entrants;
162 0     0   0 return ( first { $_->name eq $name } @$contestants );
  0         0  
163             }
164              
165              
166             =head2 ided
167              
168             $tourney->ided($id)
169              
170             Returns the contestant whose id is $id. Ids are grepped for stringwise equality.
171              
172             =cut
173              
174             sub ided {
175 8130     8130 1 11979 my $self = shift;
176 8130         10731 my $id = shift;
177 8130         8712 my @contestants = @{ $self->entrants };
  8130         14890  
178 8130     103802   32346 return first { $_->id eq $id } @contestants;
  103802         238162  
179             }
180              
181              
182             =head2 roleCheck
183              
184             roleCheck(@games)
185              
186             Returns the roles of the contestants in the individual $games in @games, eg qw/Black White/, qw/Home Away/, these being all the same (ie no typos), or dies.
187              
188             =cut
189              
190             sub roleCheck {
191 0     0 1 0 my $self = shift;
192 0         0 my @games = @_;
193 0         0 my @roles;
194 0         0 for my $game (@games) {
195 0         0 my $contestants = $game->contestants;
196 0         0 my $result = $game->result;
197 0         0 my @otherroles = sort keys %$contestants;
198 0         0 for my $key ( keys %$result ) {
199             die "$key: $result->{$key}, but no $key player in $game."
200 0 0       0 unless grep { $key eq $_ } @otherroles;
  0         0  
201             }
202 0 0       0 unless (@roles) {
203 0         0 @roles = @otherroles;
204             }
205             else {
206 0         0 my $test = 0;
207 0 0       0 $test++ unless @roles == @otherroles;
208 0         0 for my $i ( 0 .. $#roles ) {
209 0 0       0 $test++ unless $roles[$i] eq $otherroles[$i];
210             }
211 0 0       0 die "@roles in game 1, but @otherroles in $game."
212             if $test;
213             }
214             }
215 0         0 return @roles;
216             }
217              
218              
219             =head2 met
220              
221             @rounds = $tourney->met($deepblue, @grandmasters)
222             next if $tourney->met($deepblue, $capablanca)
223              
224             In list context, returns an array of the rounds in which $deepblue met the corresponding member of @grandmasters (and of the empty string '' if they haven't met.) In scalar context, returns the number of grandmasters met. Don't forget to collect scorecards in the appropriate games first! (Assumes players do not meet more than once!) This is NOT the same as Games::Tournament::Contestant::met! See also Games;:Tournament::Swiss::whoPlayedWho.
225              
226             =cut
227              
228             sub met {
229 41     41 1 187074 my $self = shift;
230 41         72 my $player = shift;
231 41         112 my @opponents = @_;
232 41         76 my @ids = map { $_->id } @opponents;
  233         658  
233 41         146 my $games = $self->play;
234 41         132 my $rounds = $self->round;
235 41         111 my %roundGames = map { $_ => $games->{$_} } FIRSTROUND .. $rounds;
  123         486  
236 41 50       157 carp "No games to round $rounds. Where are the cards?" unless %roundGames;
237 41         58 my @meetings;
238 41         203 @meetings[ 0 .. $#opponents ] = ('') x @opponents;
239 41         85 my $n = 0;
240 41         100 for my $other (@opponents) {
241 233         488 for my $round ( FIRSTROUND .. $rounds ) {
242 699         2346 my $game = $roundGames{$round}{ $other->id };
243 699 100 66     4302 next unless $game and $game->can('contestants');
244 573 100       1610 $meetings[$n] = $round if $other->myOpponent($game) == $player;
245             }
246             }
247 233         539 continue { $n++; }
248 41 50       437 return @meetings if wantarray;
249 0         0 return scalar grep { $_ } @meetings;
  0         0  
250             }
251              
252              
253             =head2 unmarkedCards
254              
255             @unfinished = $tourney->unmarkedCards(@games)
256              
257             Returns an array of the games which have no or a wrong result. The result accessor should be an anonymous hash with roles, or 'Bye' as keys and either 'Win' & 'Loss', 'Loss' & 'Win' or 'Draw' & 'Draw', or 'Bye', as values.
258              
259             =cut
260              
261             sub unmarkedCards {
262 0     0 1 0 my $self = shift;
263 0         0 my @games = @_;
264 0         0 my @unfinished;
265 0         0 for my $game (@games) {
266 0         0 my $contestants = $game->contestants;
267 0         0 my $result = $game->result;
268             push @unfinished, $game
269             unless (
270             ( keys %$contestants == 1 and $result->{Bye} =~ m/Bye/i )
271             or $result->{ (ROLES)[0] } and $result->{ (ROLES)[1] }
272             and (
273             (
274             $result->{ (ROLES)[0] } eq 'Win'
275             and $result->{ (ROLES)[1] } eq 'Loss'
276             )
277             or ( $result->{ (ROLES)[0] } eq 'Loss'
278             and $result->{ (ROLES)[1] } eq 'Win' )
279             or ( $result->{ (ROLES)[0] } eq 'Draw'
280 0 0 0     0 and $result->{ (ROLES)[1] } eq 'Draw' )
      0        
      0        
      0        
      0        
281             )
282             );
283             }
284 0         0 return @unfinished;
285             }
286              
287              
288             =head2 dupes
289              
290             $games = $tourney->dupes(@grandmasters)
291              
292             Returns an anonymous array, of the games in which @grandmasters have met. Don't forget to collect scorecards in the appropriate games first! (Assumes players do not meet more than once!)
293              
294             =cut
295              
296             sub dupes {
297 0     0 1 0 my $self = shift;
298 0         0 my @players = @_;
299 0         0 my @ids = map { $_->id } @players;
  0         0  
300 0         0 my $games = $self->play;
301 0         0 my @dupes;
302             map {
303 0         0 my $id = $_;
  0         0  
304 0 0       0 map { push @dupes, $games->{$id}->{$_} if exists $games->{$id}->{$_}; }
  0         0  
305             @ids;
306             } @ids;
307 0         0 return \@dupes;
308             }
309              
310              
311             =head2 updateScores
312              
313             @scores = $tourney->updateScores;
314              
315             Updates entrants' scores for the present (previous) round, using $tourney's play (ie games played) field. Returns an array of the scores in order of the player ids (not at the moment, it doesn't), dying on those entrants who don't have a result for the round. Be careful. Garbage in, garbage out. What is the present round?
316              
317             =cut
318              
319             sub updateScores {
320 0     0 1 0 my $self = shift;
321 0         0 my $players = $self->entrants;
322 0         0 my $round = $self->round;
323 0         0 my $games = $self->play;
324 0         0 my @scores;
325 0         0 for my $player (@$players) {
326 0         0 my $id = $player->id;
327 0         0 my $oldId = $player->oldId;
328 0         0 my $scores = $player->scores;
329 0         0 my $card = $games->{$round}->{$id};
330 0 0 0     0 die "Game in round $round for player $id? Is $round the right round?"
331             unless $card
332             and $card->isa('Games::Tournament::Card');
333 0         0 my $results = $card->{result};
334 0         0 die @{ [ keys %$results ] } . " roles in player ${id}'s game?"
335 0 0 0     0 unless grep { $_ eq (ROLES)[0] or $_ eq (ROLES)[1] or $_ eq 'Bye' }
  0 0       0  
336             keys %$results;
337 0         0 eval { $card->myResult($player) };
  0         0  
338 0 0 0     0 die "$@: Result in player ${id}'s $card game in round $round?"
339             if not $card or $@;
340 0         0 my $result = $card->myResult($player);
341 0 0       0 die "$result result in $card game for player $id in round $round?"
342             unless $result =~ m/^(?:Win|Loss|Draw|Bye|Forfeit)/i;
343 0         0 $$scores{$round} = $result;
344 0 0       0 $player->scores($scores) if defined $scores;
345 0         0 push @scores, $$scores{$round};
346             }
347 0         0 $self->entrants($players);
348             # return @scores;
349             }
350              
351              
352             =head2 randomRole
353              
354             ( $myrole, $yourrole ) = randomRole;
355              
356             This returns the 2 roles, @Games::Tournament::roles in a random order.
357              
358             =cut
359              
360             sub randomRole {
361 137     137 1 202 my $self = shift;
362 137 100       1544 my $evenRole = int rand(2) ? (ROLES)[0] : (ROLES)[1];
363 137 100       362 my $oddRole = $evenRole eq (ROLES)[0] ? (ROLES)[1] : (ROLES)[0];
364 137         385 return ( $evenRole, $oddRole );
365             }
366              
367              
368             =head2 play
369              
370             $tourney->play
371              
372             Gets the games played, keyed on round and id of player. Also sets, but you don't want to do that.
373              
374             =cut
375              
376             sub play {
377 312     312 1 453 my $self = shift;
378 312         513 my $play = shift;
379 312 100       1304 if ( defined $play ) { $self->{play} = $play; }
  71 100       593  
380 191         534 elsif ( $self->{play} ) { return $self->{play}; }
381             }
382              
383             =head2 entrants
384              
385             $tourney->entrants
386              
387             Gets/sets the entrants as an anonymous array of player objects. Users may rely on the original order being maintained in web app cookies.
388              
389             =cut
390              
391             sub entrants {
392 12451     12451 1 110987 my $self = shift;
393 12451         14377 my $entrants = shift;
394 12451 100       35968 if ( defined $entrants ) { $self->{entrants} = $entrants; }
  1976 100       10361  
395 10379         37812 elsif ( $self->{entrants} ) { return $self->{entrants}; }
396             }
397              
398              
399             =head2 absentees
400              
401             $tourney->absentees
402              
403             Gets/sets the absentees as an anonymous array of player objects. These players won't be included in the brackets of players who are to be paired.
404              
405             =cut
406              
407             sub absentees {
408 1956     1956 1 2256 my $self = shift;
409 1956         2369 my $absentees = shift;
410 1956 50       6141 if ( defined $absentees ) { $self->{absentees} = $absentees; }
  0 50       0  
411 0         0 elsif ( $self->{absentees} ) { return $self->{absentees}; }
412             }
413              
414              
415             =head2 round
416              
417             $tourney->round
418              
419             Gets/sets the round number of a round near you. The default round number is 0. That is, the 'round' before round 1. The question is when one round becomes the next round.
420              
421             =cut
422              
423             sub round {
424 2125     2125 1 2939 my $self = shift;
425 2125         2561 my $round = shift;
426 2125 100       5498 if ( defined $round ) { $self->{round} = $round; }
  134 100       1056  
427 187         519 elsif ( $self->{round} ) { return $self->{round}; }
428 1804         3161 else { return 0 }
429             }
430              
431              
432             =head2 rounds
433              
434             $tourney->rounds
435              
436             Gets/sets the number of rounds in the tournament.
437              
438             =cut
439              
440             sub rounds {
441 0     0 1 0 my $self = shift;
442 0         0 my $rounds = shift;
443 0 0       0 if ( defined $rounds ) { $self->{rounds} = $rounds; }
  0 0       0  
444 0         0 elsif ( $self->{rounds} ) { return $self->{rounds}; }
445             }
446              
447              
448             =head2 size
449              
450             $size = 'Maxi' if $tourney->size > 2**$tourney->rounds
451              
452             Gets the number of entrants
453              
454             =cut
455              
456             sub size {
457 0     0 1 0 my $self = shift;
458 0         0 return scalar @{ $self->entrants };
  0         0  
459             }
460              
461              
462             =head2 idNameCheck
463              
464             $tourney->idNameCheck # WARNING: 13301616 and 13300849 both, Petrosian, Tigran
465              
466             Dies if 2 entrants have the same id, warns if they have the same name.
467              
468             =cut
469              
470             sub idNameCheck {
471 0     0 1 0 my $self = shift;
472 0         0 my $lineup = $self->entrants;
473 0         0 my (%idcheck, %namecheck);
474 0         0 for my $player ( @$lineup ) {
475 0         0 my $id = $player->id;
476 0         0 my $name = $player->name;
477 0 0       0 if ( defined $idcheck{$id} ) {
478 0         0 croak $name . " and $idcheck{$id} have the same id: $id";
479             }
480 0 0       0 if ( defined $namecheck{$name} ) {
481 0         0 carp "WARNING: $id and $namecheck{$name} have the same name: " .
482             $name . ". Proceeding, but BEWARE there may be problems later,";
483             }
484 0         0 $idcheck{$id} = $name;
485 0         0 $namecheck{$name} = $id;
486             }
487             }
488              
489              
490             =head2 idCheck
491              
492             $tourney->idCheck # Petrosian, Tigran, and Tigran Petrosian both 13301616
493              
494             Dies if 2 entrants have the same id
495              
496             =cut
497              
498             sub idCheck {
499 0     0 1 0 my $self = shift;
500 0         0 my $lineup = $self->entrants;
501 0         0 my %idcheck;
502 0         0 for my $player ( @$lineup ) {
503 0         0 my $id = $player->id;
504 0         0 my $name = $player->name;
505 0 0       0 if ( defined $idcheck{$id} ) {
506 0         0 croak $name . " and $idcheck{$id} have the same id: $id";
507             }
508 0         0 $idcheck{$id} = $name;
509             }
510             }
511              
512             =head2 nameCheck
513              
514             $tourney->idNameCheck # WARNING: 13301616 and 13300849 both, Petrosian, Tigran
515              
516             Warn if 2 entrants have the same name
517              
518             =cut
519              
520             sub nameCheck {
521 0     0 1 0 my $self = shift;
522 0         0 my $lineup = $self->entrants;
523 0         0 my %namecheck;
524 0         0 for my $player ( @$lineup ) {
525 0         0 my $id = $player->id;
526 0         0 my $name = $player->name;
527 0 0       0 if ( defined $namecheck{$name} ) {
528 0         0 carp "WARNING: $id and $namecheck{$name} have the same name: " .
529             $name . ". Proceeding, but BEWARE there may be problems later,";
530             }
531 0         0 $namecheck{$name} = $id;
532             }
533             }
534              
535             =head2 odd
536              
537             float($lowest) if $self->odd(@group)
538              
539             Tests whether the number of players in @group is odd or not.
540              
541             =cut
542              
543             sub odd {
544 0     0 1 0 my $self = shift;
545 0         0 my @n = @_;
546 0         0 return @n % 2;
547             }
548              
549              
550             =head2 clearLog
551              
552             $pairing->clearLog(qw/C10 C11/)
553              
554             Discards the logged messages for the passed procedures.
555              
556             =cut
557              
558             sub clearLog {
559 0     0 1 0 my $self = shift;
560 0         0 my @states = @_;
561 0         0 my $log = $self->{log};
562 0         0 delete $log->{$_} for @states;
563 0         0 return;
564             }
565              
566              
567             =head2 catLog
568              
569             $pairing->catLog(qw/C10 C11/)
570              
571             Returns the messages logged for the passed procedures, or all logged procedures if no procedures are passed, as a hash keyed on the procedures. If no messages were logged, because the procedures were not loggedProcedures, no messages will be returned.
572              
573             =cut
574              
575             sub catLog {
576 0     0 1 0 my $self = shift;
577 0         0 my @states = @_;
578 0 0       0 @states = $self->loggedProcedures unless @states;
579 0         0 my $log = $self->{log};
580 0         0 my %report;
581 0         0 for my $state ( @states ) {
582 0         0 my $strings = $log->{$state}->{strings};
583 0 0 0     0 unless ( $strings and ref $strings eq 'ARRAY' ) {
584 0         0 $report{$state} = undef;
585 0         0 next;
586             }
587 0         0 $report{$state} = join '', @$strings;
588             }
589 0         0 return %report;
590             }
591              
592              
593             =head2 tailLog
594              
595             $pairing->tailLog(qw/C10 C11/)
596              
597             Returns the new messages logged for the passed procedures since they were last tailed, as a hash keyed on the procedures. If no messages were logged, because the procedures were not loggedProcedures, no messages will be returned.
598              
599             =cut
600              
601             sub tailLog {
602 133     133 1 163 my $self = shift;
603 133         233 my @states = @_;
604 133 50       274 @states = $self->loggedProcedures unless @states;
605 133         209 my $log = $self->{log};
606 133         206 my %report = map { $_ => $log->{$_}->{strings} } @states;
  133         533  
607 133         221 my %tailpos = map { $_ => $log->{$_}->{tailpos} } @states;
  133         369  
608 133         186 my (%newpos, %lastpos, %tailedReport);
609 133         217 for my $state ( @states )
610             {
611 133 100       333 if ( defined $tailpos{$state} )
    50          
612             {
613 108         203 $newpos{$state} = $tailpos{$state} + 1;
614 108         113 $lastpos{$state} = $#{ $report{$state} };
  108         232  
615             $tailedReport{$state} = join '',
616 108         222 @{$report{$state}}[ $newpos{$state}..$lastpos{$state} ];
  108         319  
617 108         388 $log->{$_}->{tailpos} = $lastpos{$_} for @states;
618             }
619             elsif ( $report{$state} ) {
620 25         42 $newpos{$state} = 0;
621 25         64 $lastpos{$state} = $#{ $report{$state} };
  25         56  
622             $tailedReport{$state} = join '',
623 25         56 @{$report{$state}}[ $newpos{$state}..$lastpos{$state} ];
  25         82  
624 25         94 $log->{$_}->{tailpos} = $lastpos{$_} for @states;
625             }
626             }
627 133         655 return %tailedReport;
628             }
629              
630              
631             =head2 log
632              
633             $pairing->log('x=p=1, no more x increases in Bracket 4 (2).')
634              
635             Saves the message in a log iff this procedure is logged.
636              
637             =cut
638              
639             sub log {
640 6855     6855 1 9433 my $self = shift;
641 6855         9500 my $message = shift;
642 6855 50       13585 return unless $message;
643 6855         72351 (my $method = uc((caller 1)[3])) =~ s/^.*::(\w+)$/$1/;
644 6855         21055 my @loggable = $self->loggedProcedures;
645 180         704 push @{ $self->{log}->{$method}->{strings} }, "\t$message\n" if
646 6855 100   1934   33692 any { $_ eq $method } @loggable;
  1934         2484  
647 6855         25072 return;
648             }
649              
650              
651             =head2 loggedProcedures
652              
653             $group->loggedProcedures(qw/C10 C11 C12/)
654             $group->loggedProcedures(qw/C5 C6PAIRS C7 C8/)
655              
656             Adds messages generated in the procedures named in the argument list to a reportable log. Without an argument returns the logged procedures as an array.
657              
658             =cut
659              
660             sub loggedProcedures {
661 12460     12460 1 17626 my $self = shift;
662 12460         18846 my @states = @_;
663 12460 50       28329 unless ( @states ) { return keys %{ $self->{logged} }; }
  12460         14641  
  12460         46986  
664 0         0 my %logged;
665 0         0 @logged{qw/START NEXT PREV C1 C2 C3 C4 C5 C6PAIRS C6OTHERS C7 C8 C9 C10 C11 C12 C13 C14 BYE MATCHPLAYERS ASSIGNPAIRINGNUMBERS/} = (1) x 21;
666 0         0 for my $state (@states)
667             {
668 0 0       0 carp "$state is unloggable procedure" if not exists $logged{$state};
669 0         0 $self->{logged}->{$state} = 1;
670             # push @{ $self->{log}->{$state}->{strings} }, $state . ",";
671             }
672 0         0 return;
673             }
674              
675              
676             =head2 loggingAll
677              
678             $group->loggingAll
679              
680             Adds messages generated in all the procedures to a reportable log
681              
682             =cut
683              
684             sub loggingAll {
685 2     2 1 27 my $self = shift;
686 2         5 my %logged;
687 2         28 @logged{qw/START NEXT PREV C1 C2 C3 C4 C5 C6PAIRS C6OTHERS C7 C8 C9 C10 C11 C12 C13 C14 BYE MATCHPLAYERS ASSIGNPAIRINGNUMBERS/} = (1) x 21;
688 2         13 for my $state ( keys %logged )
689             {
690             # carp "$state is unloggable procedure" if not exists $logged{$state};
691 42         77 $self->{logged}->{$state} = 1;
692             }
693 2         13 return;
694             }
695              
696              
697             =head2 disloggedProcedures
698              
699             $group->disloggedProcedures
700             $group->disloggedProcedures(qw/C6PAIRS C7 C8/)
701              
702             Stops messages generated in the procedures named in the argument list being added to a reportable log. Without an argument stops logging of all procedures.
703              
704             =cut
705              
706             sub disloggedProcedures {
707 0     0 1   my $self = shift;
708 0           my @states = @_;
709 0 0         unless ( @states )
710             {
711 0           my @methods = keys %{ $self->{logged} };
  0            
712 0           @{$self->{logged}}{@methods} = (0) x @methods;
  0            
713             }
714 0           my %logged;
715 0           @logged{qw/START NEXT PREV C1 C2 C3 C4 C5 C6PAIRS C6OTHERS C7 C8 C9 C10 C11 C12 C13 C14 BYE MATCHPLAYERS ASSIGNPAIRINGNUMBERS/} = (1) x 21;
716 0           for my $state (@states)
717             {
718 0 0         carp "$state is unloggable procedure" if not defined $logged{$state};
719 0           $self->{logged}->{$state} = 0;
720             }
721 0           return;
722             }
723              
724              
725             =head1 AUTHOR
726              
727             Dr Bean, C<< >>
728              
729             =head1 BUGS
730              
731             Please report any bugs or feature requests to
732             C, or through the web interface at
733             L.
734             I will be notified, and then you'll automatically be notified of progress on
735             your bug as I make changes.
736              
737             =head1 SUPPORT
738              
739             You can find documentation for this module with the perldoc command.
740              
741             perldoc Games::Tournament
742              
743             You can also look for information at:
744              
745             =over 4
746              
747             =item * AnnoCPAN: Annotated CPAN documentation
748              
749             L
750              
751             =item * CPAN Ratings
752              
753             L
754              
755             =item * RT: CPAN's request tracker
756              
757             L
758              
759             =item * Search CPAN
760              
761             L
762              
763             =back
764              
765             =head1 ACKNOWLEDGEMENTS
766              
767             =head1 COPYRIGHT & LICENSE
768              
769             Copyright 2006 Dr Bean, all rights reserved.
770              
771             This program is free software; you can redistribute it and/or modify it
772             under the same terms as Perl itself.
773              
774             =cut
775              
776             1; # End of Games::Tournament
777              
778             # vim: set ts=8 sts=4 sw=4 noet: