| 1 | # $Id: Ballot.pm 60 2008-09-02 12:11:49Z johntrammell $ | ||||||||||
| 2 | # $URL: https://algorithm-voting.googlecode.com/svn/tags/rel-0.01-1/lib/Algorithm/Voting/Ballot.pm $ | ||||||||||
| 3 | |||||||||||
| 4 | package Algorithm::Voting::Ballot; | ||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use base 'Class::Accessor::Fast'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Params::Validate 'validate'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | __PACKAGE__->mk_accessors(qw/ candidate /); | |||||||||
| 11 | |||||||||||
| 12 | =pod | ||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | Algorithm::Voting::Ballot - represents a ballot to cast in a race | ||||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | use Algorithm::Voting::Ballot; | ||||||||||
| 21 | my $ballot = Algorithm::Voting::Ballot->new('Pedro'); | ||||||||||
| 22 | |||||||||||
| 23 | Or equivalently: | ||||||||||
| 24 | |||||||||||
| 25 | use Algorithm::Voting::Ballot; | ||||||||||
| 26 | my $ballot = Algorithm::Voting::Ballot->new(candidate => 'Pedro'); | ||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | Instances of this class contain the information specified on a ballot. Expect | ||||||||||
| 31 | this class to gain complexity as more complicated voting systems (e.g. IRV, | ||||||||||
| 32 | Condorcet) are implemented. | ||||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 Algorithm::Voting::Ballot->new() | ||||||||||
| 37 | |||||||||||
| 38 | Constructs a new ballot object. Currently only suitable for indicating a | ||||||||||
| 39 | single candidate, e.g. for Plurality ballots. | ||||||||||
| 40 | |||||||||||
| 41 | # vote for Pedro | ||||||||||
| 42 | my $ballot = Algorithm::Voting::Ballot->new('Pedro') | ||||||||||
| 43 | |||||||||||
| 44 | =cut | ||||||||||
| 45 | |||||||||||
| 46 | 25 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 25 | my $class = shift; | |||||||||
| 48 | 25 | ▶ | if (@_ == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 12 | return $class->new(candidate => $_[0]); | |||||||||
| 50 | } | ||||||||||
| 51 | 13 | my %valid = ( | |||||||||
| 52 | candidate => 0, | ||||||||||
| 53 | ); | ||||||||||
| 54 | 13 | my %args = validate(@_, \%valid); | |||||||||
| 55 | 13 | return bless \%args, $class; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | =head2 $ballot->candidate() | ||||||||||
| 59 | |||||||||||
| 60 | Returns a scalar (presumably a string, although this is not enforced) | ||||||||||
| 61 | containing the candidate for whom this ballot is cast. | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | 4 | 1; | |||||||||
| 66 | |||||||||||