line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::HTML::Stars; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
67735
|
use base qw(Tags::HTML); |
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
1587
|
|
4
|
4
|
|
|
4
|
|
90355
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
66
|
|
5
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
94
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
18
|
use Class::Utils qw(set_params split_params); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
175
|
|
8
|
4
|
|
|
4
|
|
20
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
151
|
|
9
|
4
|
|
|
4
|
|
23
|
use List::Util qw(max); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
304
|
|
10
|
4
|
|
|
4
|
|
1523
|
use MIME::Base64; |
|
4
|
|
|
|
|
2041
|
|
|
4
|
|
|
|
|
182
|
|
11
|
4
|
|
|
4
|
|
22
|
use Readonly; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2040
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constants. |
14
|
|
|
|
|
|
|
Readonly::Scalar our $STAR_FULL_FILENAME => 'Star*.svg'; |
15
|
|
|
|
|
|
|
Readonly::Scalar our $STAR_HALF_FILENAME => 'Star-.svg'; |
16
|
|
|
|
|
|
|
Readonly::Scalar our $STAR_NOTHING_FILENAME => 'StarĀ½.svg'; |
17
|
|
|
|
|
|
|
Readonly::Scalar our $IMG_STAR_FULL => encode_base64(<<'END', ''); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
END |
22
|
|
|
|
|
|
|
Readonly::Scalar our $IMG_STAR_HALF => encode_base64(<<'END', ''); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
END |
30
|
|
|
|
|
|
|
Readonly::Scalar our $IMG_STAR_NOTHING => encode_base64(<<'END', ''); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
END |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = 0.04; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Constructor. |
39
|
|
|
|
|
|
|
sub new { |
40
|
5
|
|
|
5
|
1
|
2074
|
my ($class, @params) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# No CSS support. |
43
|
5
|
|
|
|
|
13
|
push @params, 'no_css', 1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Create object. |
46
|
5
|
|
|
|
|
17
|
my ($object_params_ar, $other_params_ar) = split_params( |
47
|
|
|
|
|
|
|
['public_image_dir', 'star_width'], @params); |
48
|
5
|
|
|
|
|
153
|
my $self = $class->SUPER::new(@{$other_params_ar}); |
|
5
|
|
|
|
|
24
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Public image directory. |
51
|
4
|
|
|
|
|
135
|
$self->{'public_image_dir'} = undef; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Star width (300px). |
54
|
4
|
|
|
|
|
8
|
$self->{'star_width'} = undef; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Process params. |
57
|
4
|
|
|
|
|
6
|
set_params($self, @{$object_params_ar}); |
|
4
|
|
|
|
|
11
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Object. |
60
|
4
|
|
|
|
|
49
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Process 'Tags'. |
64
|
|
|
|
|
|
|
sub _process { |
65
|
2
|
|
|
2
|
|
25
|
my ($self, $stars_hr) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Main stars. |
68
|
2
|
|
|
|
|
8
|
$self->{'tags'}->put( |
69
|
|
|
|
|
|
|
['b', 'div'], |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
98
|
my $max_num = max(keys %{$stars_hr}); |
|
2
|
|
|
|
|
12
|
|
73
|
2
|
|
|
|
|
6
|
foreach my $num (1 .. $max_num) { |
74
|
6
|
|
|
|
|
1299
|
my $image_src = $self->_star_src($stars_hr->{$num}); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$self->{'tags'}->put( |
77
|
|
|
|
|
|
|
['b', 'img'], |
78
|
|
|
|
|
|
|
( |
79
|
|
|
|
|
|
|
$self->{'star_width'} |
80
|
|
|
|
|
|
|
? ( |
81
|
6
|
100
|
|
|
|
29
|
['a', 'style', 'width: '.$self->{'star_width'}.';'], |
82
|
|
|
|
|
|
|
) : (), |
83
|
|
|
|
|
|
|
), |
84
|
|
|
|
|
|
|
['a', 'src', $image_src], |
85
|
|
|
|
|
|
|
['e', 'img'], |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
508
|
$self->{'tags'}->put( |
90
|
|
|
|
|
|
|
['e', 'div'], |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
73
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _star_src { |
97
|
6
|
|
|
6
|
|
11
|
my ($self, $id) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Link to file. |
100
|
6
|
|
|
|
|
7
|
my $src; |
101
|
6
|
50
|
|
|
|
12
|
if (defined $self->{'public_image_dir'}) { |
102
|
0
|
|
|
|
|
0
|
$src = $self->{'public_image_dir'}; |
103
|
0
|
0
|
|
|
|
0
|
if ($src ne '') { |
104
|
0
|
|
|
|
|
0
|
$src .= '/'; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
0
|
|
|
|
0
|
if ($id eq 'full') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
$src .= $STAR_FULL_FILENAME; |
108
|
|
|
|
|
|
|
} elsif ($id eq 'half') { |
109
|
0
|
|
|
|
|
0
|
$src .= $STAR_HALF_FILENAME; |
110
|
|
|
|
|
|
|
} elsif ($id eq 'nothing') { |
111
|
0
|
|
|
|
|
0
|
$src .= $STAR_NOTHING_FILENAME |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} else { |
114
|
6
|
|
|
|
|
8
|
$src = 'data:image/svg+xml;base64,'; |
115
|
6
|
100
|
|
|
|
14
|
if ($id eq 'full') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
116
|
2
|
|
|
|
|
6
|
$src .= $IMG_STAR_FULL; |
117
|
|
|
|
|
|
|
} elsif ($id eq 'half') { |
118
|
2
|
|
|
|
|
5
|
$src .= $IMG_STAR_HALF; |
119
|
|
|
|
|
|
|
} elsif ($id eq 'nothing') { |
120
|
2
|
|
|
|
|
4
|
$src .= $IMG_STAR_NOTHING; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
11
|
return $src; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |