File Coverage

blib/lib/Vote/Count/BottomRunOff.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 25 26 96.1


line stmt bran cond sub pod time code
1             package Vote::Count::BottomRunOff;
2 39     39   41683 use Moose::Role;
  39         203  
  39         416  
3              
4 39     39   221844 use 5.024;
  39         179  
5 39     39   265 no warnings 'experimental';
  39         97  
  39         1928  
6 39     39   395 use feature ( 'signatures');
  39         134  
  39         13230  
7              
8             our $VERSION='2.00';
9              
10             =head1 NAME
11              
12             Vote::Count::BottomRunOff
13              
14             =head1 VERSION 2.00
15              
16             =head2 Description
17              
18             Bottom RunOff is an elimination method which takes the two lowest choices, usually by Top Count, but alternately by another method such as Approval or Borda, the choice which would lose a runoff is eliminated.
19              
20             =head1 Synopsis
21              
22             my $eliminate = $Election->BottomRunOff();
23             # log the pairing result
24             $Election->logd( $eliminate->{'runoff'} );
25             $Election->logv( "eliminated ${\ $eliminate->{'eliminate'} }."
26             $Election->Defeat( $eliminate->{'eliminate'} );
27              
28             =head1 BottomRunOff ($method)
29              
30             The TieBreakMethod must either be 'precedence' or TieBreakerFallBackPrecedence must be true or BottomRunOff will die. It takes a parameter of method, which is the method used to rank the active choices. The default method is 'TopCount', 'Approval' is a common alternative, any method which returns a RankCount object could be used.
31              
32             my $result = BottomRunOff( $Election, 'Approval' );
33              
34             The returned value is a hashref with the keys: B<eliminate>, B<continuing>, and B<runoff>, runoff is formatted as a table.
35              
36             =cut
37              
38 9     9 0 9379 sub BottomRunOff ( $Election, $method1='TopCount' ) {
  9         16  
  9         16  
  9         13  
39 9         34 my @ranked = $Election->UntieActive($method1, 'precedence' )->OrderedList();
40 9         64 my ( $continuing, $eliminate ) = $Election->UnTieList( 'TopCount', $ranked[-1], $ranked[-2]);
41 8         39 my $tc = $Election->$method1( { $continuing => 1, $eliminate => 1} );
42             return {
43 8         21 eliminate => $eliminate,
44             continuing => $continuing,
45 8         101 runoff => "Elimination Runoff:\n${\ $tc->RankTable }"
46             };
47             }
48              
49             1;
50              
51             #FOOTER
52              
53             =pod
54              
55             BUG TRACKER
56              
57             L<https://github.com/brainbuz/Vote-Count/issues>
58              
59             AUTHOR
60              
61             John Karr (BRAINBUZ) brainbuz@cpan.org
62              
63             CONTRIBUTORS
64              
65             Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
66              
67             LICENSE
68              
69             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>.
70              
71             SUPPORT
72              
73             This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
74              
75             =cut
76