blib/lib/Games/Tournament/Swiss/Config.pm

filter: Statementstmt 80.6% 50 / 62 Branchbran 66.6% 20 / 30 Conditioncond 53.8% 14 / 26 MC/DCmcdc 29.4% 5 / 17 Subroutinesub 100% 9 / 9 Podpod 100% 7 / 7 totaltotal 69.5% 105 / 151 CC 28 SCAR 18.5
CC
28
Cov
71%
abbreviation
9.3
frisk
8.3
scores
6.1
CRAP 6.3
« blib/lib/Games/Tournament/Contestant/Swiss/Preference.pm ↑ Summary blib/lib/Games/Tournament/Contestant/Swiss.pm »
1 package Games::Tournament::Swiss::Config;
2 35 $Games::Tournament::Swiss::Config::VERSION = '0.21';
3 # Last Edit: 2016 Jan 01, 13:44:43
4 # $Id: $
5  
6 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Games::Tournament::Swiss::Config - Swiss Competition Configuration
12  
13 =cut
14  
15 =head1 SYNOPSIS
16  
17 use constant ROLES => @Games::Tournament::Swiss::Config::roles = qw/Black White/;
18 use constant ROLES => @Games::Tournament::Swiss::Config::ROLES;
19 $Games::Tournament::Swiss::Config::firstRound = 11;
20  
21 =head1 DESCRIPTION
22  
23 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.
24  
25 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.)
26  
27 =head1 METHODS
28  
29 =head2 new
30  
31 Getter/setter of the genre of competition, eg chess, basketball, football, school exam, etc, the tournament is being held as.
32  
33 =cut
34  
35 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
36 5 my $self = shift;
37 5 my %args = @_;
38 5 ▶ $args{roles} ||= [ Games::Tournament::Swiss::Config->roles ];
Condition50%1/2
$args{"roles"} ||= ["Games::Tournament::Swiss::Config"->roles]
l!l
05
MC/DC0%0/1
$args{"roles"} ||= ["Games::Tournament::Swiss::Config"->roles]
$args{"roles"}
Truth table50%1/2
A
A= $args{"roles"}
Aresult
11
00
39 5 return bless \%args, $self;
40 }
41  
42  
43 =head2 frisk
44  
45 Die if the configuration contains anything but [A-Za-z0-9:,.]
46  
47 =cut
48  
49 70 ▶sub frisk {
Subroutine frisk: called CC=8 SCAR=21.1
Pod documented
50 70 my $self = shift;
51 70 my @suspects = @_;
52 70 for my $suspect ( @suspects )
53 {
54 90 ▶ unless ( ref $suspect ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $suspect) { } 15 75 90
if (do { ref $suspect eq 'ARRAY' }) { } 5 10 15
elsif (ref $suspect eq 'HASH') { } 10 0 10
55 75 ▶ die "We are afraid you may be importing nasty characters with
Branch: 1 branch
BranchTrueFalseTotal
unless $suspect =~ /^[A-Za-z0-9:.,]*$/ 0 75 75
56 $suspect. Please use only [A-Za-z0-9:.,] in your configuration files"
57 unless $suspect =~ m/^[A-Za-z0-9:.,]*$/;
58 }
59 elsif ( ref($suspect) eq "ARRAY" ) {
60 5 for (@$suspect) { $self->frisk($_); }
61 }
62 elsif ( ref($suspect) eq 'HASH' ) {
63 10 for ( keys %$suspect ) { $self->frisk( $suspect->{$_} ); }
64 }
65 else {
66 0 die "We are afraid you may be importing nasty objects with $suspect.
67 Please use only arrays and hashes in your configuration files";
68 }
69 }
70 70 return;
71 }
72  
73  
74 =head2 roles
75  
76 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.
77  
78 =cut
79  
80 37 ▶sub roles {
Subroutine roles: called CC=5 SCAR=16.1
Pod documented
81 37 my $self = shift;
82 37 my $roles = shift;
83 37 ▶ if (ref $self eq "Games::Tournament::Swiss::Config" and $roles) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq "Games::Tournament::Swiss::Config" and $roles) 2 35 37
Condition100%3/3
ref $self eq "Games::Tournament::Swiss::Config" and $roles
!ll&&!rl&&r
3232
MC/DC100%2/2
ref $self eq "Games::Tournament::Swiss::Config" and $roles
ref $self eq "Games::Tournament::Swiss::Config" $roles
Truth table100%3/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $roles
ABresult
0X0
100
111
84 2 $self->{roles} = $roles; return;
85 }
86 35 ▶ if ( ref $self eq "Games::Tournament::Swiss::Config" and $self->{roles} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq 'Games::Tournament::Swiss::Config' and $self->{'roles'}) { } 3 32 35
Condition66%2/3
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"roles"}
!ll&&!rl&&r
3203
MC/DC50%1/2
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"roles"}
ref $self eq "Games::Tournament::Swiss::Config" $self->{"roles"}
Truth table66%2/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $self->{"roles"}
ABresult
0X0
100
111
87 3 { return @{ $self->{roles} }; }
88 32 else { return qw/White Black/; }
89 }
90  
91  
92 =head2 scores
93  
94 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.
95  
96 =cut
97  
98 11 ▶sub scores {
Subroutine scores: called CC=5 SCAR=18.1
Pod documented
99 11 my $self = shift;
100 11 my $scores = shift;
101 11 ▶ if (ref $self eq "Games::Tournament::Swiss::Config" and $scores)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self eq 'Games::Tournament::Swiss::Config' and $scores) { } 2 9 11
elsif (ref $self eq 'Games::Tournament::Swiss::Config' and $self->{'scores'}) { } 0 9 9
Condition66%2/3
ref $self eq "Games::Tournament::Swiss::Config" and $scores
!ll&&!rl&&r
902
MC/DC50%1/2
ref $self eq "Games::Tournament::Swiss::Config" and $scores
ref $self eq "Games::Tournament::Swiss::Config" $scores
Truth table66%2/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $scores
ABresult
0X0
100
111
102 2 { $self->{scores} = $scores; }
103 ▶ elsif (ref $self eq "Games::Tournament::Swiss::Config" and $self->{scores})
Condition33%1/3
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"scores"}
!ll&&!rl&&r
900
MC/DC0%0/2
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"scores"}
ref $self eq "Games::Tournament::Swiss::Config" $self->{"scores"}
Truth table33%1/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $self->{"scores"}
ABresult
0X0
100
111
104 0 { return %{ $self->{scores} }; }
105 9 else { return ( win => 1, loss => 0, draw => 0.5, absent => 0, bye => 1,
106 unpaired => 0, tardy => 0.5, forfeit => 0 ) }
107 }
108  
109  
110 =head2 abbreviation
111  
112 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.
113  
114 =cut
115  
116 2 ▶sub abbreviation {
Subroutine abbreviation: called CC=5 SCAR=22.3
Pod documented
117 2 my $self = shift;
118 2 my $abbreviation = shift;
119 2 ▶ if (ref $self eq "Games::Tournament::Swiss::Config" and $abbreviation)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self eq 'Games::Tournament::Swiss::Config' and $abbreviation) { } 0 2 2
elsif (ref $self eq 'Games::Tournament::Swiss::Config' and $self->{'abbreviation'}) { } 0 2 2
Condition33%1/3
ref $self eq "Games::Tournament::Swiss::Config" and $abbreviation
!ll&&!rl&&r
200
MC/DC0%0/2
ref $self eq "Games::Tournament::Swiss::Config" and $abbreviation
ref $self eq "Games::Tournament::Swiss::Config" $abbreviation
Truth table33%1/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $abbreviation
ABresult
0X0
100
111
120 0 { $self->{abbreviation} = $abbreviation; return; }
121 ▶ elsif (ref $self eq "Games::Tournament::Swiss::Config" and
Condition33%1/3
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"abbreviation"}
!ll&&!rl&&r
200
MC/DC0%0/2
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"abbreviation"}
ref $self eq "Games::Tournament::Swiss::Config" $self->{"abbreviation"}
Truth table33%1/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $self->{"abbreviation"}
ABresult
0X0
100
111
122 $self->{abbreviation} )
123 0 { return %{ $self->{abbreviation} }; }
124 2 else { return ( W => 'White', B => 'Black', 1 => 'Win', 0 => 'Loss',
125 0.5 => 'Draw', '=' => 'Draw', A => 'Absolute', S => 'Strong', M => 'Mild', D => 'Down', U => 'Up', N => 'Not' ); }
126 }
127  
128  
129 =head2 algorithm
130  
131 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.
132  
133 =cut
134  
135 2 ▶sub algorithm {
Subroutine algorithm: called CC=4 SCAR=17.9
Pod documented
136 2 my $self = shift;
137 2 my $algorithm = shift;
138 2 ▶ die "$algorithm name is like Games::Tournament::Swiss::Procedure::AlgoName"
Branch: 1 branch
BranchTrueFalseTotal
unless $algorithm =~ /^Games::Tournament::Swiss::Procedure::\w+$/ 0 2 2
139 unless $algorithm =~ m/^Games::Tournament::Swiss::Procedure::\w+$/;
140 2 ▶ if ($algorithm) { $self->{algorithm} = $algorithm; }
Branch: 2 branches
BranchTrueFalseTotal
if ($algorithm) { } 2 0 2
elsif ($self->{'algorithm'}) { } 0 0 0
141 0 elsif ( $self->{algorithm} ) { return @{ $self->{algorithm} }; }
142 0 else { return 'Games::Tournament::Swiss::Procedure::FIDE' };
143 }
144  
145  
146 =head2 firstround
147  
148 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.
149  
150 =cut
151  
152 5 ▶sub firstround {
Subroutine firstround: called CC=5 SCAR=18.1
Pod documented
153 5 my $self = shift;
154 5 my $first = shift;
155 5 ▶ if (ref $self eq "Games::Tournament::Swiss::Config" and $first)
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self eq 'Games::Tournament::Swiss::Config' and $first) { } 2 3 5
elsif (ref $self eq 'Games::Tournament::Swiss::Config' and $self->{'first'}) { } 0 3 3
Condition66%2/3
ref $self eq "Games::Tournament::Swiss::Config" and $first
!ll&&!rl&&r
032
MC/DC50%1/2
ref $self eq "Games::Tournament::Swiss::Config" and $first
ref $self eq "Games::Tournament::Swiss::Config" $first
Truth table66%2/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $first
ABresult
0X0
100
111
156 2 { $self->{firstround} = $first; }
157 ▶ elsif (ref $self eq "Games::Tournament::Swiss::Config" and $self->{first} )
Condition33%1/3
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"first"}
!ll&&!rl&&r
030
MC/DC0%0/2
ref $self eq "Games::Tournament::Swiss::Config" and $self->{"first"}
ref $self eq "Games::Tournament::Swiss::Config" $self->{"first"}
Truth table33%1/3
A and B
A= ref $self eq "Games::Tournament::Swiss::Config"B= $self->{"first"}
ABresult
0X0
100
111
158 0 { return @{ $self->{firstround} }; }
159 3 else { return 1; }
160 }
161  
162 =head1 AUTHOR
163  
164 Dr Bean, C<< <drbean, followed by the at mark (@), cpan, then a dot, and finally, org> >>
165  
166 =head1 BUGS
167  
168 Please report any bugs or feature requests to
169 C<bug-games-tournament-swiss at rt.cpan.org>, or through the web interface at
170 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Tournament-Swiss>.
171 I will be notified, and then you'll automatically be notified of progress on
172 your bug as I make changes.
173  
174 =head1 SUPPORT
175  
176 You can find documentation for this module with the perldoc command.
177  
178 perldoc Games::Tournament::Swiss::Config
179  
180 You can also look for information at:
181  
182 =over 4
183  
184 =item * AnnoCPAN: Annotated CPAN documentation
185  
186 L<http://annocpan.org/dist/Games-Tournament-Swiss>
187  
188 =item * CPAN Ratings
189  
190 L<http://cpanratings.perl.org/d/Games-Tournament-Swiss>
191  
192 =item * RT: CPAN's request tracker
193  
194 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Tournament-Swiss>
195  
196 =item * Search CPAN
197  
198 L<http://search.cpan.org/dist/Games-Tournament-Swiss>
199  
200 =back
201  
202 =head1 ACKNOWLEDGEMENTS
203  
204 See L<http://www.fide.com/official/handbook.asp?level=C04> for the FIDE's Swiss rules.
205  
206 =head1 COPYRIGHT & LICENSE
207  
208 Copyright 2006 Dr Bean, all rights reserved.
209  
210 This program is free software; you can redistribute it and/or modify it
211 under the same terms as Perl itself.
212  
213 =cut
214  
215 35 1; # End of Games::Tournament::Swiss::Config
216  
217 # vim: set ts=8 sts=4 sw=4 noet:
« blib/lib/Games/Tournament/Contestant/Swiss/Preference.pm ↑ Summary blib/lib/Games/Tournament/Contestant/Swiss.pm »