File Coverage

blib/lib/Games/Tournament/Swiss/Config.pm
Criterion Covered Total %
statement 19 60 31.6
branch 6 30 20.0
condition 6 26 23.0
subroutine 5 9 55.5
pod 7 7 100.0
total 43 132 32.5


line stmt bran cond sub pod time code
1             package Games::Tournament::Swiss::Config;
2              
3             # Last Edit: 2010 9月 02, 11時31分54秒
4             # $Id: $
5              
6 30     30   151 use warnings;
  30         47  
  30         1967  
7 30     30   1289 use strict;
  30         57  
  30         22616  
8              
9             =head1 NAME
10              
11             Games::Tournament::Swiss::Config - Swiss Competition Configuration
12              
13             =head1 VERSION
14              
15             Version 0.03
16              
17             =cut
18              
19             our $VERSION = '0.03';
20              
21             =head1 SYNOPSIS
22              
23             use constant ROLES => @Games::Tournament::Swiss::Config::roles = qw/Black White/;
24             use constant ROLES => @Games::Tournament::Swiss::Config::ROLES;
25             $Games::Tournament::Swiss::Config::firstRound = 11;
26              
27             =head1 DESCRIPTION
28              
29             Actually, a swiss tournament is not just one kind of tournament, but a whole genre of tournaments. If you are using Games::Tournament::Swiss for other than chess tournaments, where the players take black and white roles, and score 0,0.5, or 1, for example, you probably want to configure it. You also might want to start swiss pairing at a random round in the tournament, in which case you will set firstround.
30              
31             The roles, scores, firstround, algorithm methods in this module are here just to stop perl warning about 'only one use, possible typo' warnings, with the use of fully qualified Games::Tournament::Swiss::Config package variables. (Is that actually true? Anyway I want the methods (class and object) to return values, default and assigned.)
32              
33             =head1 METHODS
34              
35             =head2 new
36              
37             Getter/setter of the genre of competition, eg chess, basketball, football, school exam, etc, the tournament is being held as.
38              
39             =cut
40              
41             sub new {
42 0     0 1 0 my $self = shift;
43 0         0 my %args = @_;
44 0   0     0 $args{roles} ||= [ Games::Tournament::Swiss::Config->roles ];
45 0         0 return bless \%args, $self;
46             }
47              
48              
49             =head2 frisk
50              
51             Die if the configuration contains anything but [A-Za-z0-9:,.]
52              
53             =cut
54              
55             sub frisk {
56 0     0 1 0 my $self = shift;
57 0         0 my @suspects = @_;
58 0         0 for my $suspect ( @suspects )
59             {
60 0 0       0 unless ( ref $suspect ) {
    0          
    0          
61 0 0       0 die "We are afraid you may be importing nasty characters with
62             $suspect. Please use only [A-Za-z0-9:.,] in your configuration files"
63             unless $suspect =~ m/^[A-Za-z0-9:.,]*$/;
64             }
65             elsif ( ref($suspect) eq "ARRAY" ) {
66 0         0 for (@$suspect) { $self->frisk($_); }
  0         0  
67             }
68             elsif ( ref($suspect) eq 'HASH' ) {
69 0         0 for ( keys %$suspect ) { $self->frisk( $suspect->{$_} ); }
  0         0  
70             }
71             else {
72 0         0 die "We are afraid you may be importing nasty objects with $suspect.
73             Please use only arrays and hashes in your configuration files";
74             }
75             }
76 0         0 return;
77             }
78              
79              
80             =head2 roles
81              
82             Getter/setter of the roles the 2 players take, eg Black, White, or Home, Away. The default is White, Black. Both object and class method.
83              
84             =cut
85              
86             sub roles {
87 25     25 1 50 my $self = shift;
88 25         38 my $roles = shift;
89 25 50 33     92 if (ref $self eq "Games::Tournament::Swiss::Config" and $roles) {
90 0         0 $self->{roles} = $roles; return;
  0         0  
91             }
92 25 50 33     91 if ( ref $self eq "Games::Tournament::Swiss::Config" and $self->{roles} )
93 0         0 { return @{ $self->{roles} }; }
  0         0  
94 25         8330 else { return qw/White Black/; }
95             }
96              
97              
98             =head2 scores
99              
100             Getter/setter of the scores the 2 players can get, eg win: 1, loss: 0, draw: 0.5, absent: 0, bye: 1, which is the default. Both object and class method.
101              
102             =cut
103              
104             sub scores {
105 9     9 1 19 my $self = shift;
106 9         16 my $scores = shift;
107 9 50 33     147 if (ref $self eq "Games::Tournament::Swiss::Config" and $scores)
    50 33        
108 0         0 { $self->{scores} = $scores; }
109             elsif (ref $self eq "Games::Tournament::Swiss::Config" and $self->{scores})
110 0         0 { return %{ $self->{scores} }; }
  0         0  
111 9         16580 else { return ( win => 1, loss => 0, draw => 0.5, absent => 0, bye => 1,
112             unpaired => 0, tardy => 0.5, forfeit => 0 ) }
113             }
114              
115              
116             =head2 abbreviation
117              
118             Getter/setter of the abbreviations used and their full translations. The default is W: White, B: Black, 1: Win, 0: Loss, '0.5': Draw, '=': Draw. Both object and class method. Also Absolute, Strong and Mild preferences, and Down, Up, and Not floats.
119              
120             =cut
121              
122             sub abbreviation {
123 2     2 1 3240 my $self = shift;
124 2         5 my $abbreviation = shift;
125 2 50 33     21 if (ref $self eq "Games::Tournament::Swiss::Config" and $abbreviation)
    50 33        
126 0         0 { $self->{abbreviation} = $abbreviation; return; }
  0         0  
127             elsif (ref $self eq "Games::Tournament::Swiss::Config" and
128             $self->{abbreviation} )
129 0         0 { return %{ $self->{abbreviation} }; }
  0         0  
130 2         55 else { return ( W => 'White', B => 'Black', 1 => 'Win', 0 => 'Loss',
131             0.5 => 'Draw', '=' => 'Draw', A => 'Absolute', S => 'Strong', M => 'Mild', D => 'Down', U => 'Up', N => 'Not' ); }
132             }
133              
134              
135             =head2 algorithm
136              
137             Getter/setter of the algorithm by which swiss pairing is carried out. There is no default. Pass a name as a string. I recommend Games::Tournament::Swiss::Procedure::FIDE. Make sure something is set.
138              
139             =cut
140              
141             sub algorithm {
142 0     0 1   my $self = shift;
143 0           my $algorithm = shift;
144 0 0         die "$algorithm name is like Games::Tournament::Swiss::Procedure::AlgoName"
145             unless $algorithm =~ m/^Games::Tournament::Swiss::Procedure::\w+$/;
146 0 0         if ($algorithm) { $self->{algorithm} = $algorithm; }
  0 0          
147 0           elsif ( $self->{algorithm} ) { return @{ $self->{algorithm} }; }
  0            
148 0           else { return 'Games::Tournament::Swiss::Procedure::FIDE' };
149             }
150              
151              
152             =head2 firstround
153              
154             Getter/setter of the first round in which swiss pairing started. Perhaps some other pairing method was used in rounds earlier than this. The default is 1. Both object and class method.
155              
156             =cut
157              
158             sub firstround {
159 0     0 1   my $self = shift;
160 0           my $first = shift;
161 0 0 0       if (ref $self eq "Games::Tournament::Swiss::Config" and $first)
    0 0        
162 0           { $self->{firstround} = $first; }
163             elsif (ref $self eq "Games::Tournament::Swiss::Config" and $self->{first} )
164 0           { return @{ $self->{firstround} }; }
  0            
165 0           else { return 1; }
166             }
167              
168             =head1 AUTHOR
169              
170             Dr Bean, C<< >>
171              
172             =head1 BUGS
173              
174             Please report any bugs or feature requests to
175             C, or through the web interface at
176             L.
177             I will be notified, and then you'll automatically be notified of progress on
178             your bug as I make changes.
179              
180             =head1 SUPPORT
181              
182             You can find documentation for this module with the perldoc command.
183              
184             perldoc Games::Tournament::Swiss::Config
185              
186             You can also look for information at:
187              
188             =over 4
189              
190             =item * AnnoCPAN: Annotated CPAN documentation
191              
192             L
193              
194             =item * CPAN Ratings
195              
196             L
197              
198             =item * RT: CPAN's request tracker
199              
200             L
201              
202             =item * Search CPAN
203              
204             L
205              
206             =back
207              
208             =head1 ACKNOWLEDGEMENTS
209              
210             See L for the FIDE's Swiss rules.
211              
212             =head1 COPYRIGHT & LICENSE
213              
214             Copyright 2006 Dr Bean, all rights reserved.
215              
216             This program is free software; you can redistribute it and/or modify it
217             under the same terms as Perl itself.
218              
219             =cut
220              
221             1; # End of Games::Tournament::Swiss::Config
222              
223             # vim: set ts=8 sts=4 sw=4 noet: