Count.pm

filter: Statementstmt 100% 57 / 57 Branchbran 100% 10 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 1 totaltotal 93.4% 86 / 92 CC 8 SCAR 12.7
CC
8
Cov
96%
_tiebreakvalidation
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.6
« Count/Charge.pm ↑ Summary Count/Floor.pm »
1 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 39 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use feature qw /postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Toolkit for implementing voting methods.
7  
8 package Vote::Count;
9 39 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 39 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 39 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 39 ▶use Vote::Count::Matrix;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 # use Storable 3.15 'dclone';
18  
19 39 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 39 our $VERSION='2.02';
22  
23 =head1 NAME
24  
25 Vote::Count - a tool kit for preferential ballots
26  
27 =head1 VERSION 2.02
28  
29 =head2 A Toolkit for Resolving Preferential Ballots.
30  
31 Vote::Count provides a combination of methods and variations for conducting elections and studying different methods of resolving preferential ballots.
32  
33 =head1 DOCUMENTATION
34  
35 =head2 L<OVERVIEW|Vote::Count::Overview>
36  
37 An overview of Preferential Voting and an introduction to Vote::Count. Read this document first.
38  
39 =head2 L<COMMON|Vote::Count::Common>
40  
41 The core methods of Vote::Count are documented in this Module.
42  
43 =head2 L<CATALOG|Vote::Count::Catalog>
44  
45 Catalog of Preferential Voting Methods implemented by Vote::Count and the Modules providing them.
46  
47 =head2 L<MULTIMEMBER|Vote::Count::MultiMember>
48  
49 Overview of Preferential Ballots for Multi-Member Elections and their implementation in Vote::Count.
50  
51 =cut
52  
53 # This should be in tiebreaker's BUILD but
54 # I've found role's BUILD unreliable.
55 ▶sub _tiebreakvalidation ( $self ) {
Subroutine _tiebreakvalidation: called CC=8 SCAR=20.9
56 177 ▶ if ( defined $self->TieBreakMethod ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->TieBreakMethod) 71 106 177
57 71 ▶ if ( lc( $self->TieBreakMethod ) eq 'precedence' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $self->TieBreakMethod eq "precedence") 13 58 71
58 13 ▶ unless ( defined $self->PrecedenceFile() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->PrecedenceFile) 1 12 13
59 1 die
60 'Precedence File must be defined when setting TieBreakMethod to Precedence';
61 }
62 }
63 }
64 176 ▶ if ( $self->TieBreakerFallBackPrecedence ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->TieBreakerFallBackPrecedence) 8 168 176
65 39 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 8 my $tb = $self->TieBreakMethod;
67 8 ▶ if ( $tb eq 'none' or $tb eq 'all' or !defined($tb) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tb eq "none" or $tb eq "all" or not defined $tb) 3 5 8
Condition50%3/6
$tb eq "none" or $tb eq "all" or not defined $tb
l!l&&r!l&&!r
035
$tb eq "none" or $tb eq "all"
l!l&&r!l&&!r
008
MC/DC33%1/3
$tb eq "none" or $tb eq "all" or not defined $tb
$tb eq "none" $tb eq "all" not defined $tb
Truth table50%2/4
A or B or not(C)
A= $tb eq "none"B= $tb eq "all"C= not defined $tb
ABCresult
1XX1
01X1
0011
0000
68 3 die
69 "FATAL: TieBreakerFallBackPrecedence will not be triggered if the TieBreakMethod is none, all or undefined.\n";
70 }
71 }
72 }
73  
74 sub BUILD {
75 177 ▶ my $self = shift;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
76 # Verbose Log
77 177 $self->{'LogV'} = localtime->cdate . "\n";
78 # Debugging Log
79 177 $self->{'LogD'} = qq/Vote::Count Version $VERSION\n/;
80 177 $self->{'LogD'} .= localtime->cdate . "\n";
81 # Terse Log
82 177 $self->{'LogT'} = '';
83 # Force build of Active, Methods that deal with it often go to $self->{'Active'}
84 # make sure it is built before this happens, Active has to be built after
85 # loading ballotset.
86 177 $self->GetActive();
87 177 $self->_tiebreakvalidation();
88 }
89  
90 # load the roles providing the underlying ops.
91 39 with
92 'Vote::Count::Common',
93 'Vote::Count::Approval',
94 'Vote::Count::Borda',
95 'Vote::Count::BottomRunOff',
96 'Vote::Count::Floor',
97 'Vote::Count::IRV',
98 'Vote::Count::Log',
99 'Vote::Count::Score',
100 'Vote::Count::TieBreaker',
101 'Vote::Count::TopCount',
102 ;
103  
104 39 __PACKAGE__->meta->make_immutable;
105 39 1;
106  
107 #INDEXSECTION
108  
109 =pod
110  
111 =head1 INDEX of Vote::Count Modules and Documentation
112  
113 =over
114  
115 =item *
116  
117 L<Vote::Count - a tool kit for preferential ballots>
118  
119 =item *
120  
121 L<Vote::Count::Approval>
122  
123 =item *
124  
125 L<Vote::Count::Borda>
126  
127 =item *
128  
129 L<Vote::Count::BottomRunOff>
130  
131 =item *
132  
133 L<Vote::Count::Catalog>
134  
135 =item *
136  
137 L<Vote::Count::Charge>
138  
139 =item *
140  
141 L<Vote::Count::Charge::Cascade>
142  
143 =item *
144  
145 L<Vote::Count::Common>
146  
147 =item *
148  
149 L<Vote::Count::Floor>
150  
151 =item *
152  
153 L<Vote::Count::Helper>
154  
155 =item *
156  
157 L<Vote::Count::Helper::FullCascadeCharge>
158  
159 =item *
160  
161 L<Vote::Count::Helper::NthApproval>
162  
163 =item *
164  
165 L<Vote::Count::Helper::Table>
166  
167 =item *
168  
169 L<Vote::Count::Helper::TestBalance;>
170  
171 =item *
172  
173 L<Vote::Count::IRV>
174  
175 =item *
176  
177 L<Vote::Count::Log>
178  
179 =item *
180  
181 L<Vote::Count::Matrix>
182  
183 =item *
184  
185 L<Vote::Count::Method::Cascade>
186  
187 =item *
188  
189 L<Vote::Count::Method::CondorcetDropping>
190  
191 =item *
192  
193 L<Vote::Count::Method::CondorcetIRV>
194  
195 =item *
196  
197 L<Vote::Count::Method::CondorcetVsIRV>
198  
199 =item *
200  
201 L<Vote::Count::Method::MinMax>
202  
203 =item *
204  
205 L<Vote::Count::Method::STAR>
206  
207 =item *
208  
209 L<Vote::Count::Method::WIGM>
210  
211 =item *
212  
213 L<Vote::Count::MultiMember - Overview of Multi Member and Proportional Elections and Vote::Count support for them.>
214  
215 =item *
216  
217 L<Vote::Count::Overview>
218  
219 =item *
220  
221 L<Vote::Count::Range>
222  
223 =item *
224  
225 L<Vote::Count::RankCount>
226  
227 =item *
228  
229 L<Vote::Count::ReadBallots>
230  
231 =item *
232  
233 L<Vote::Count::Redact>
234  
235 =item *
236  
237 L<Vote::Count::Score>
238  
239 =item *
240  
241 L<Vote::Count::Start>
242  
243 =item *
244  
245 L<Vote::Count::TextTableTiny>
246  
247 =item *
248  
249 L<Vote::Count::TieBreaker>
250  
251 =item *
252  
253 L<Vote::Count::TopCount>
254  
255 =back
256  
257 =cut
258  
259 #FOOTER
260  
261 =pod
262  
263 BUG TRACKER
264  
265 L<https://github.com/brainbuz/Vote-Count/issues>
266  
267 AUTHOR
268  
269 John Karr (BRAINBUZ) brainbuz@cpan.org
270  
271 CONTRIBUTORS
272  
273 Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
274  
275 LICENSE
276  
277 This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit L<http://fsf.org>.
278  
279 SUPPORT
280  
281 This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
282  
283 =cut
284  
« Count/Charge.pm ↑ Summary Count/Floor.pm »