File Coverage

lib/App/Sandy/Role/Counter.pm
Criterion Covered Total %
statement 3 14 21.4
branch 0 2 0.0
condition n/a
subroutine 1 3 33.3
pod 0 1 0.0
total 4 20 20.0


line stmt bran cond sub pod time code
1             package App::Sandy::Role::Counter;
2             # ABSTRACT: Bayes counter
3              
4 6     6   3504 use App::Sandy::Base 'role';
  6         12  
  6         41  
5              
6             our $VERSION = '0.22'; # VERSION
7              
8             sub with_make_counter {
9             # ALgorithm based in perlfaq:
10             # How do I select a random line from a file?
11             # "The Art of Computer Programming"
12              
13 0     0 0   my ($self, $num, $picks) = @_;
14             return sub {
15 0     0     state $count_down = $num;
16 0           state $picks_left = $picks;
17              
18 0           my $rc = 0;
19 0           my $rand = int(rand($count_down));
20              
21 0 0         if ($rand < $picks_left) {
22 0           $rc = 1;
23 0           $picks_left--;
24             }
25              
26 0           $count_down--;
27 0           return $rc;
28 0           };
29             }
30              
31             __END__
32              
33             =pod
34              
35             =encoding UTF-8
36              
37             =head1 NAME
38              
39             App::Sandy::Role::Counter - Bayes counter
40              
41             =head1 VERSION
42              
43             version 0.22
44              
45             =head1 AUTHORS
46              
47             =over 4
48              
49             =item *
50              
51             Thiago L. A. Miller <tmiller@mochsl.org.br>
52              
53             =item *
54              
55             J. Leonel Buzzo <lbuzzo@mochsl.org.br>
56              
57             =item *
58              
59             Felipe R. C. dos Santos <fsantos@mochsl.org.br>
60              
61             =item *
62              
63             Helena B. Conceição <hconceicao@mochsl.org.br>
64              
65             =item *
66              
67             Gabriela Guardia <gguardia@mochsl.org.br>
68              
69             =item *
70              
71             Fernanda Orpinelli <forpinelli@mochsl.org.br>
72              
73             =item *
74              
75             Pedro A. F. Galante <pgalante@mochsl.org.br>
76              
77             =back
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is Copyright (c) 2018 by Teaching and Research Institute from Sírio-Libanês Hospital.
82              
83             This is free software, licensed under:
84              
85             The GNU General Public License, Version 3, June 2007
86              
87             =cut