File Coverage

blib/lib/Algorithm/Voting/Ballot.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
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     4   7025 use strict;
  4         5  
  4         128  
6 4     4   20 use warnings;
  4         6  
  4         124  
7 4     4   20 use base 'Class::Accessor::Fast';
  4         10  
  4         1971  
8 4     4   15288 use Params::Validate 'validate';
  4         35501  
  4         930  
9              
10             __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             sub new {
47 25     25 1 6373 my $class = shift;
48 25 100       61 if (@_ == 1) {
49 12         41 return $class->new(candidate => $_[0]);
50             }
51 13         33 my %valid = (
52             candidate => 0,
53             );
54 13         192 my %args = validate(@_, \%valid);
55 13         120 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             1;
66