line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tags::HTML::Stars; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
73056
|
use base qw(Tags::HTML); |
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
1731
|
|
4
|
4
|
|
|
4
|
|
97775
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
76
|
|
5
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
20
|
use Class::Utils qw(set_params split_params); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
141
|
|
8
|
4
|
|
|
4
|
|
18
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
132
|
|
9
|
4
|
|
|
4
|
|
20
|
use List::Util qw(max); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
329
|
|
10
|
4
|
|
|
4
|
|
1743
|
use MIME::Base64; |
|
4
|
|
|
|
|
2215
|
|
|
4
|
|
|
|
|
194
|
|
11
|
4
|
|
|
4
|
|
25
|
use Readonly; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2179
|
|
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.03; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Constructor. |
39
|
|
|
|
|
|
|
sub new { |
40
|
5
|
|
|
5
|
1
|
2073
|
my ($class, @params) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# No CSS support. |
43
|
5
|
|
|
|
|
13
|
push @params, 'no_css', 1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Create object. |
46
|
5
|
|
|
|
|
18
|
my ($object_params_ar, $other_params_ar) = split_params( |
47
|
|
|
|
|
|
|
['public_image_dir', 'star_width'], @params); |
48
|
5
|
|
|
|
|
154
|
my $self = $class->SUPER::new(@{$other_params_ar}); |
|
5
|
|
|
|
|
20
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Public image directory. |
51
|
4
|
|
|
|
|
139
|
$self->{'public_image_dir'} = undef; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Star width (300px). |
54
|
4
|
|
|
|
|
7
|
$self->{'star_width'} = undef; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Process params. |
57
|
4
|
|
|
|
|
6
|
set_params($self, @{$object_params_ar}); |
|
4
|
|
|
|
|
11
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Object. |
60
|
4
|
|
|
|
|
50
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Process 'Tags'. |
64
|
|
|
|
|
|
|
sub _process { |
65
|
2
|
|
|
2
|
|
27
|
my ($self, $stars_hr) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Main stars. |
68
|
2
|
|
|
|
|
9
|
$self->{'tags'}->put( |
69
|
|
|
|
|
|
|
['b', 'div'], |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
102
|
my $max_num = max(keys %{$stars_hr}); |
|
2
|
|
|
|
|
15
|
|
73
|
2
|
|
|
|
|
7
|
foreach my $num (1 .. $max_num) { |
74
|
6
|
|
|
|
|
1362
|
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
|
|
|
|
28
|
['a', 'style', 'width: '.$self->{'star_width'}.';'], |
82
|
|
|
|
|
|
|
) : (), |
83
|
|
|
|
|
|
|
), |
84
|
|
|
|
|
|
|
['a', 'src', $image_src], |
85
|
|
|
|
|
|
|
['e', 'img'], |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
502
|
$self->{'tags'}->put( |
90
|
|
|
|
|
|
|
['e', 'div'], |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
73
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _star_src { |
97
|
6
|
|
|
6
|
|
10
|
my ($self, $id) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Link to file. |
100
|
6
|
|
|
|
|
6
|
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
|
|
|
|
17
|
if ($id eq 'full') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
116
|
2
|
|
|
|
|
5
|
$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
|
|
|
|
|
12
|
return $src; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |