| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::TagCloud::Extended; |
|
2
|
1
|
|
|
1
|
|
930
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
43
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
16
|
use base qw/Class::Data::Inheritable Class::Accessor::Fast/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1076
|
|
|
5
|
1
|
|
|
1
|
|
6097
|
use Readonly; |
|
|
1
|
|
|
|
|
3342
|
|
|
|
1
|
|
|
|
|
65
|
|
|
6
|
1
|
|
|
1
|
|
596
|
use HTML::TagCloud::Extended::TagColors; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
41
|
|
|
7
|
1
|
|
|
1
|
|
658
|
use HTML::TagCloud::Extended::TagList; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
8
|
1
|
|
|
1
|
|
572
|
use HTML::TagCloud::Extended::Tag; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
21
|
|
|
9
|
1
|
|
|
1
|
|
700
|
use HTML::TagCloud::Extended::Factor; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use HTML::TagCloud::Extended::Exception; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1753
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly my $DEFAULT_BASE_FONT_SIZE => 24; |
|
15
|
|
|
|
|
|
|
Readonly my $DEFAULT_FONT_SIZE_RANGE => 12; |
|
16
|
|
|
|
|
|
|
Readonly my $DEFAULT_CSS_CLASS => "tagcloud"; |
|
17
|
|
|
|
|
|
|
Readonly my $DEFAULT_SIZE_SUFFIX => "px"; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata('_epoch_level'); |
|
20
|
|
|
|
|
|
|
__PACKAGE__->_epoch_level([qw/earliest earlier later latest/]); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ |
|
23
|
|
|
|
|
|
|
colors |
|
24
|
|
|
|
|
|
|
tags |
|
25
|
|
|
|
|
|
|
base_font_size |
|
26
|
|
|
|
|
|
|
font_size_range |
|
27
|
|
|
|
|
|
|
css_class |
|
28
|
|
|
|
|
|
|
use_hot_color |
|
29
|
|
|
|
|
|
|
hot_tags_size |
|
30
|
|
|
|
|
|
|
_size_suffix |
|
31
|
|
|
|
|
|
|
_hot_tags_name |
|
32
|
|
|
|
|
|
|
/); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
|
35
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
36
|
0
|
|
|
|
|
|
my $self = bless { }, $class; |
|
37
|
0
|
|
|
|
|
|
$self->_init(@_); |
|
38
|
0
|
|
|
|
|
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _init { |
|
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
43
|
0
|
|
|
|
|
|
$self->_set_default_parameters(); |
|
44
|
0
|
|
|
|
|
|
$self->_set_custom_parameters(@_); |
|
45
|
0
|
|
|
|
|
|
$self->colors ( HTML::TagCloud::Extended::TagColors->new ); |
|
46
|
0
|
|
|
|
|
|
$self->tags ( HTML::TagCloud::Extended::TagList->new ); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub hot_tags_name { |
|
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
51
|
0
|
0
|
|
|
|
|
if($_[0]) { |
|
52
|
0
|
0
|
|
|
|
|
my $tags = ref $_[0] ? $_[0] : [@_]; |
|
53
|
0
|
|
|
|
|
|
$self->_hot_tags_name($tags); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
return $self->_hot_tags_name; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _check_hot_tag_name { |
|
59
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
|
60
|
0
|
|
|
|
|
|
foreach my $tag_name ( @{ $self->hot_tags_name } ) { |
|
|
0
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
return 1 if $name eq $tag_name; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
return 0; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _set_default_parameters { |
|
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
68
|
0
|
|
|
|
|
|
$self->base_font_size ( $DEFAULT_BASE_FONT_SIZE ); |
|
69
|
0
|
|
|
|
|
|
$self->font_size_range ( $DEFAULT_FONT_SIZE_RANGE ); |
|
70
|
0
|
|
|
|
|
|
$self->css_class ( $DEFAULT_CSS_CLASS ); |
|
71
|
0
|
|
|
|
|
|
$self->_size_suffix ( $DEFAULT_SIZE_SUFFIX ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _set_custom_parameters { |
|
75
|
0
|
|
|
0
|
|
|
my ($self, %args) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ( exists $args{base_font_size} ) { |
|
78
|
0
|
|
|
|
|
|
$self->base_font_size($args{base_font_size}); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
0
|
0
|
|
|
|
|
if ( exists $args{font_size_range} ) { |
|
81
|
0
|
|
|
|
|
|
$self->font_size_range($args{font_size_range}); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
0
|
|
|
|
|
if ( exists $args{css_class} ) { |
|
84
|
0
|
|
|
|
|
|
$self->css_class($args{css_class}); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
0
|
0
|
|
|
|
|
if ( exists $args{hot_tags_size} ) { |
|
87
|
0
|
|
|
|
|
|
$self->hot_tags_size($args{hot_tags_size}); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
else { |
|
90
|
0
|
|
|
|
|
|
my $size = $self->base_font_size + ($self->font_size_range / 2); |
|
91
|
0
|
|
|
|
|
|
$self->hot_tags_size($size); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
0
|
|
|
|
|
if ( exists $args{size_suffix} ) { |
|
94
|
0
|
|
|
|
|
|
$self->size_suffix($args{size_suffix}); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
0
|
0
|
|
|
|
|
$self->_hot_tags_name( exists $args{hot_tags_name} ? $args{hot_tags_name} : [] ); |
|
97
|
0
|
0
|
|
|
|
|
$self->use_hot_color ( exists $args{use_hot_color} ? $args{use_hot_color} : undef ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub size_suffix { |
|
101
|
0
|
|
|
0
|
1
|
|
my ($self, $suffix) = @_; |
|
102
|
0
|
0
|
|
|
|
|
if ($suffix) { |
|
103
|
0
|
|
|
|
|
|
my $correct_suffix; |
|
104
|
0
|
|
|
|
|
|
foreach my $registered ( qw/mm cm in pt pc px/ ) { |
|
105
|
0
|
0
|
|
|
|
|
$correct_suffix = $suffix if $suffix eq $registered; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
0
|
0
|
|
|
|
|
if ($correct_suffix) { |
|
108
|
0
|
|
|
|
|
|
$self->_size_suffix($correct_suffix); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
else { |
|
111
|
0
|
|
|
|
|
|
HTML::TagCloud::Extended::Exception->throw( |
|
112
|
|
|
|
|
|
|
qq/You should correct suffix for text-size [ mm cm in pt pc px ]. / |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
$self->_size_suffix; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add { |
|
120
|
0
|
|
|
0
|
0
|
|
my($self, $tag_name, $url, $count, $timestamp) = @_; |
|
121
|
0
|
|
0
|
|
|
|
my $tag = HTML::TagCloud::Extended::Tag->new( |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
122
|
|
|
|
|
|
|
name => $tag_name || '', |
|
123
|
|
|
|
|
|
|
url => $url || '', |
|
124
|
|
|
|
|
|
|
count => $count || 0, |
|
125
|
|
|
|
|
|
|
timestamp => $timestamp, |
|
126
|
|
|
|
|
|
|
); |
|
127
|
0
|
|
|
|
|
|
$self->tags->add($tag); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub max_font_size { |
|
131
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
132
|
0
|
|
|
|
|
|
return $self->base_font_size + $self->font_size_range; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub min_font_size { |
|
136
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
137
|
0
|
|
|
|
|
|
my $num = $self->base_font_size - $self->font_size_range; |
|
138
|
0
|
0
|
|
|
|
|
return $num > 0 ? $num : 0; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub html_and_css { |
|
142
|
0
|
|
|
0
|
0
|
|
my ($self, $conf) = @_; |
|
143
|
0
|
|
|
|
|
|
my $html = qq|\n|; |
|
144
|
0
|
|
|
|
|
|
$html .= $self->html($conf); |
|
145
|
0
|
|
|
|
|
|
return $html; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub css { |
|
149
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
150
|
0
|
|
|
|
|
|
my $css = ''; |
|
151
|
0
|
|
|
|
|
|
foreach my $type ( keys %{ $self->colors } ) { |
|
|
0
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $color = $self->colors->{$type}; |
|
153
|
0
|
|
|
|
|
|
my $class = $self->css_class; |
|
154
|
0
|
|
|
|
|
|
foreach my $attr ( keys %$color ) { |
|
155
|
0
|
|
|
|
|
|
my $code = $color->{$attr}; |
|
156
|
0
|
|
|
|
|
|
$css .= ".${class} .${type} a:${attr} {text-decoration: none; color: #${code};}\n"; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
0
|
|
|
|
|
|
return $css; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub html { |
|
163
|
0
|
|
|
0
|
0
|
|
my ($self, $conf) = @_; |
|
164
|
0
|
|
|
|
|
|
my $html_tags = $self->html_tags($conf); |
|
165
|
0
|
|
|
|
|
|
my $html = join "", @$html_tags; |
|
166
|
0
|
|
|
|
|
|
return $self->wrap_div($html); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub wrap_span { |
|
170
|
0
|
|
|
0
|
0
|
|
my($self, $html) = @_; |
|
171
|
0
|
0
|
|
|
|
|
return "" unless $html; |
|
172
|
0
|
|
|
|
|
|
return sprintf qq|\n%s\n|, $self->css_class, $html; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub wrap_div { |
|
176
|
0
|
|
|
0
|
0
|
|
my($self, $html) = @_; |
|
177
|
0
|
0
|
|
|
|
|
return "" unless $html; |
|
178
|
0
|
|
|
|
|
|
return sprintf qq| \n%s \n|, $self->css_class, $html; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub html_tags { |
|
182
|
0
|
|
|
0
|
0
|
|
my($self, $conf) = @_; |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my $tags_amount = $self->tags->count; |
|
185
|
0
|
0
|
|
|
|
|
if ($tags_amount == 0) { |
|
|
|
0
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return []; |
|
187
|
|
|
|
|
|
|
} elsif ($tags_amount == 1) { |
|
188
|
0
|
|
|
|
|
|
my $ite = $self->tags->iterator; |
|
189
|
0
|
|
|
|
|
|
my $tag = $ite->first; |
|
190
|
0
|
|
|
|
|
|
my $html = $self->create_html_tag($tag, 'latest', $self->max_font_size); |
|
191
|
0
|
|
|
|
|
|
return [$html]; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
|
0
|
|
|
|
$conf ||= {}; |
|
195
|
0
|
|
0
|
|
|
|
my $order_by = $conf->{order_by} || 'name'; |
|
196
|
0
|
|
|
|
|
|
$self->tags->sort($order_by); |
|
197
|
0
|
|
|
|
|
|
my $limit = $conf->{limit}; |
|
198
|
0
|
0
|
|
|
|
|
my $tags = $limit ? $self->tags->splice(0, $limit) : $self->tags; |
|
199
|
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $count_factor = HTML::TagCloud::Extended::Factor->new( |
|
201
|
|
|
|
|
|
|
min => $tags->min_count, |
|
202
|
|
|
|
|
|
|
max => $tags->max_count, |
|
203
|
|
|
|
|
|
|
range => $self->max_font_size - $self->min_font_size, |
|
204
|
|
|
|
|
|
|
); |
|
205
|
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $epoch_factor = HTML::TagCloud::Extended::Factor->new( |
|
207
|
|
|
|
|
|
|
min => $tags->min_epoch, |
|
208
|
|
|
|
|
|
|
max => $tags->max_epoch, |
|
209
|
|
|
|
|
|
|
range => 3, |
|
210
|
|
|
|
|
|
|
); |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
my @html_tags = (); |
|
213
|
0
|
|
|
|
|
|
my $ite = $tags->iterator; |
|
214
|
0
|
|
|
|
|
|
while( my $tag = $ite->next ) { |
|
215
|
0
|
|
|
|
|
|
my $count_lv = $count_factor->get_level($tag->count); |
|
216
|
0
|
|
|
|
|
|
my $epoch_lv = $epoch_factor->get_level($tag->epoch); |
|
217
|
0
|
|
|
|
|
|
my $color_type = $self->_epoch_level->[$epoch_lv]; |
|
218
|
0
|
|
|
|
|
|
my $font_size = $self->min_font_size + $count_lv; |
|
219
|
0
|
0
|
0
|
|
|
|
if ( ( $self->use_hot_color eq 'name' && $self->_check_hot_tag_name($tag->name) ) |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|| ( $self->use_hot_color eq 'size' && $font_size >= $self->hot_tags_size ) ) { |
|
221
|
0
|
|
|
|
|
|
$color_type = 'hot'; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
0
|
|
|
|
|
|
my $html_tag = $self->create_html_tag($tag, $color_type, $font_size); |
|
224
|
0
|
|
|
|
|
|
push @html_tags, $html_tag; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
0
|
|
|
|
|
|
return \@html_tags; |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub create_html_tag { |
|
230
|
0
|
|
|
0
|
0
|
|
my($self, $tag, $type, $size) = @_; |
|
231
|
0
|
|
|
|
|
|
return sprintf qq|%s\n|, |
|
232
|
|
|
|
|
|
|
$type, |
|
233
|
|
|
|
|
|
|
$size, |
|
234
|
|
|
|
|
|
|
$self->size_suffix, |
|
235
|
|
|
|
|
|
|
$tag->url, |
|
236
|
|
|
|
|
|
|
$tag->name; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |
|
240
|
|
|
|
|
|
|
__END__ |