line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RandomPerson::Choice; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
578
|
use strict; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
149
|
|
4
|
7
|
|
|
7
|
|
19
|
use warnings; |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
159
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
2562
|
use List::Util::WeightedChoice qw(choose_weighted); |
|
7
|
|
|
|
|
61881
|
|
|
7
|
|
|
|
|
1431
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
55
|
|
|
55
|
1
|
693
|
my ($class) = @_; |
10
|
|
|
|
|
|
|
|
11
|
55
|
|
|
|
|
259
|
return bless {}, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add { |
15
|
81
|
|
|
81
|
1
|
453
|
my ( $self, $value, $count ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
81
|
|
100
|
|
|
282
|
$count ||= 1; |
18
|
|
|
|
|
|
|
|
19
|
81
|
|
|
|
|
63
|
push @{ $self->{data} }, $value; |
|
81
|
|
|
|
|
193
|
|
20
|
81
|
|
|
|
|
89
|
push @{ $self->{weight} }, $count; |
|
81
|
|
|
|
|
127
|
|
21
|
81
|
|
|
|
|
175
|
$self->{size}++; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub add_list { |
25
|
35
|
|
|
35
|
1
|
13237
|
my ( $self, @list ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
35
|
|
|
|
|
38
|
push @{ $self->{data} }, @list; |
|
35
|
|
|
|
|
18049
|
|
28
|
35
|
|
|
|
|
186
|
push @{ $self->{weight} }, 1 for 1..scalar(@list); |
|
199058
|
|
|
|
|
162509
|
|
29
|
35
|
|
|
|
|
6149
|
$self->{size} += scalar(@list); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub size { |
33
|
34
|
|
|
34
|
1
|
434
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
34
|
|
|
|
|
165
|
return $self->{size}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub pick { |
39
|
2562
|
|
|
2562
|
1
|
22564
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
|
41
|
2562
|
100
|
|
|
|
5626
|
die "No data has been added to the list" unless $self->{size}; |
42
|
|
|
|
|
|
|
|
43
|
2561
|
|
|
|
|
5697
|
return choose_weighted($self->{data}, $self->{weight}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |