line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Vote::Count::ReadBallots; |
2
|
|
|
|
|
|
|
$Vote::Count::ReadBallots::VERSION = '0.007'; # TRIAL |
3
|
9
|
|
|
9
|
|
275274
|
use 5.022; |
|
9
|
|
|
|
|
39
|
|
4
|
9
|
|
|
9
|
|
51
|
use feature qw/postderef signatures/; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
996
|
|
5
|
|
|
|
|
|
|
# use strict; |
6
|
|
|
|
|
|
|
# use warnings; |
7
|
9
|
|
|
9
|
|
51
|
no warnings qw/experimental/; |
|
9
|
|
|
|
|
36
|
|
|
9
|
|
|
|
|
365
|
|
8
|
9
|
|
|
9
|
|
56
|
use Path::Tiny; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
490
|
|
9
|
9
|
|
|
9
|
|
77
|
use Carp; |
|
9
|
|
|
|
|
72
|
|
|
9
|
|
|
|
|
483
|
|
10
|
9
|
|
|
9
|
|
72
|
use Data::Dumper; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
407
|
|
11
|
9
|
|
|
9
|
|
94
|
use Data::Printer; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
92
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Exporter::Easy ( |
14
|
9
|
|
|
|
|
68
|
OK => [ qw( read_ballots ) ], |
15
|
9
|
|
|
9
|
|
4683
|
); |
|
9
|
|
|
|
|
11802
|
|
16
|
|
|
|
|
|
|
|
17
|
34
|
|
|
34
|
|
1430
|
sub _choices ( $choices ) { |
|
34
|
|
|
|
|
72
|
|
|
34
|
|
|
|
|
58
|
|
18
|
34
|
|
|
|
|
79
|
my %C = (); |
19
|
34
|
|
|
|
|
148
|
$choices =~ m/^\:CHOICES\:(.*)/; |
20
|
34
|
|
|
|
|
260
|
for my $choice ( split /:/, $1 ) { |
21
|
295
|
|
|
|
|
563
|
$C{$choice} = 1; |
22
|
|
|
|
|
|
|
} |
23
|
34
|
|
|
|
|
130
|
return \%C; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
33
|
|
|
33
|
0
|
27116
|
sub read_ballots( $filename ) { |
|
33
|
|
|
|
|
83
|
|
|
33
|
|
|
|
|
80
|
|
27
|
33
|
|
|
|
|
227
|
my %data = ( |
28
|
|
|
|
|
|
|
'choices' => undef, 'ballots' => {}, 'options' => { 'rcv' => 1 } ); |
29
|
33
|
|
|
|
|
196
|
for my $line_raw ( path($filename)->lines ) { |
30
|
329
|
|
|
|
|
11061
|
chomp $line_raw; |
31
|
329
|
100
|
|
|
|
773
|
if ( $line_raw =~ m/^\:CHOICES\:/ ) { |
32
|
35
|
100
|
|
|
|
124
|
if ( $data{'choices'} ) { |
33
|
2
|
|
|
|
|
33
|
croak("File $filename redefines CHOICES \n$line_raw\n"); |
34
|
|
|
|
|
|
|
} |
35
|
33
|
|
|
|
|
126
|
else { $data{'choices'} = _choices($line_raw); } |
36
|
33
|
|
|
|
|
79
|
next; |
37
|
|
|
|
|
|
|
} |
38
|
294
|
|
|
|
|
357
|
my $line = $line_raw; |
39
|
294
|
100
|
|
|
|
831
|
next unless ( $line =~ /\w/ ); |
40
|
286
|
|
|
|
|
676
|
$line =~ s/(\d+)\://; |
41
|
286
|
100
|
|
|
|
602
|
my $numbals = $1 ? $1 : 1; |
42
|
286
|
100
|
|
|
|
480
|
if ( $data{'ballots'}{$line} ) { |
43
|
|
|
|
|
|
|
$data{'ballots'}{$line}{'count'} = |
44
|
45
|
|
|
|
|
119
|
$data{'ballots'}{$line}{'count'} + $numbals; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
241
|
|
|
|
|
307
|
my @votes = (); |
48
|
241
|
|
|
|
|
510
|
for my $choice ( split( /:/, $line ) ) { |
49
|
610
|
100
|
|
|
|
979
|
unless ( $data{'choices'}{$choice} ) { |
50
|
|
|
|
|
|
|
die "Choice: $choice is not in defined choice list: " |
51
|
2
|
|
|
|
|
31
|
. join( ", ", keys( $data{'choices'}->%* ) ) . "\n"; |
52
|
|
|
|
|
|
|
} |
53
|
608
|
|
|
|
|
842
|
push @votes, $choice; |
54
|
|
|
|
|
|
|
} |
55
|
239
|
|
|
|
|
631
|
$data{'ballots'}{$line}{'count'} = $numbals; |
56
|
239
|
|
|
|
|
547
|
$data{'ballots'}{$line}{'votes'} = \@votes; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
29
|
|
|
|
|
1115
|
return \%data ; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |