line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Stars; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
88381
|
use strict; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
119
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
113
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2016
|
use Class::Utils qw(set_params); |
|
4
|
|
|
|
|
107742
|
|
|
4
|
|
|
|
|
85
|
|
7
|
4
|
|
|
4
|
|
323
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1108
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.01; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constructor. |
12
|
|
|
|
|
|
|
sub new { |
13
|
6
|
|
|
6
|
1
|
5481
|
my ($class, @params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Create object. |
16
|
6
|
|
|
|
|
17
|
my $self = bless {}, $class; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Number of stars. |
19
|
6
|
|
|
|
|
21
|
$self->{'number_of_stars'} = 10; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Process parameters. |
22
|
6
|
|
|
|
|
32
|
set_params($self, @params); |
23
|
|
|
|
|
|
|
|
24
|
5
|
100
|
|
|
|
85
|
if ($self->{'number_of_stars'} !~ m/^\d+$/) { |
25
|
1
|
|
|
|
|
4
|
err "Parameter 'number_of_stars' must be a number."; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
21
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Convert percent number to stars definition. |
32
|
|
|
|
|
|
|
sub percent_stars { |
33
|
6
|
|
|
6
|
1
|
2839
|
my ($self, $percent) = @_; |
34
|
|
|
|
|
|
|
|
35
|
6
|
|
|
|
|
13
|
my $stars_hr = {}; |
36
|
6
|
|
|
|
|
15
|
my $star_percent = 100 / $self->{'number_of_stars'}; |
37
|
6
|
|
|
|
|
16
|
foreach my $star_id (1 .. $self->{'number_of_stars'}) { |
38
|
53
|
100
|
|
|
|
101
|
if ($percent >= $star_id * $star_percent) { |
|
|
100
|
|
|
|
|
|
39
|
26
|
|
|
|
|
57
|
$stars_hr->{$star_id} = 'full'; |
40
|
|
|
|
|
|
|
} elsif ($percent >= ($star_id * $star_percent) - ($star_percent / 2)) { |
41
|
2
|
|
|
|
|
6
|
$stars_hr->{$star_id} = 'half', |
42
|
|
|
|
|
|
|
} else { |
43
|
25
|
|
|
|
|
49
|
$stars_hr->{$star_id} = 'nothing', |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
24
|
return $stars_hr; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |