line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::TagCloud::Simple; |
2
|
1
|
|
|
1
|
|
49276
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
26
|
use 5.010; # sorry, need smart matching |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
1044
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our @EXPORT = qw(); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(build_cloud); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
## TODO |
15
|
|
|
|
|
|
|
# need to add the reverse sorting mechanisms |
16
|
|
|
|
|
|
|
# come up with good way to test this output |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$HTML::Tag::Font_Family = 'monospace'; |
19
|
|
|
|
|
|
|
@HTML::Tag::Font_Sizes = ('70%', '85%', '100%', '115%', '130%'); # hmm.. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
## generalized routines for generating HTML tag clouds |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub build_cloud { |
24
|
|
|
|
|
|
|
# build_cloud(\%hash, $base_url, $height, $width, [$sort_method], [$min_count]) -- returns an HTML string for a tag 'cloud' |
25
|
4
|
|
|
4
|
0
|
245434
|
my $href = shift; |
26
|
4
|
|
|
|
|
10
|
my %tags = %{$href}; |
|
4
|
|
|
|
|
67
|
|
27
|
4
|
|
|
|
|
14
|
my $base_url = shift; |
28
|
4
|
|
50
|
|
|
16
|
my $height = shift // 50; |
29
|
4
|
|
50
|
|
|
10
|
my $width = shift // 50; |
30
|
4
|
|
50
|
|
|
13
|
my $sort_method = shift // 'ascii'; # allows sorting by 'ascii' or 'value' (can also prefix either with 'reverse-') |
31
|
4
|
|
100
|
|
|
20
|
my $min_count = shift // 0; |
32
|
4
|
|
|
|
|
7
|
my $html; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
## need to cull entries with less than $min_count |
35
|
4
|
|
|
|
|
26
|
my @keepers = grep { $tags{$_}{count} > $min_count; } keys %tags; |
|
112
|
|
|
|
|
219
|
|
36
|
4
|
|
|
|
|
26
|
foreach (keys %tags) { |
37
|
112
|
100
|
|
|
|
2311
|
delete $tags{$_} unless @keepers ~~ /$_/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
45
|
my @ordered = sort { $tags{$a}{count} <=> $tags{$b}{count} } keys %tags; |
|
542
|
|
|
|
|
897
|
|
41
|
4
|
|
|
|
|
18
|
my $high = $tags{$ordered[-1]}{count}; |
42
|
4
|
|
|
|
|
15
|
my $range = ($high / $#HTML::Tag::Font_Sizes); |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
25
|
foreach my $tag (keys %tags) { |
45
|
110
|
|
|
|
|
150
|
my $count = $tags{$tag}{count}; |
46
|
|
|
|
|
|
|
|
47
|
110
|
100
|
|
|
|
320
|
my $size = ($count < ($range)) ? $HTML::Tag::Font_Sizes[0] : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
48
|
|
|
|
|
|
|
($count < ($range * 2)) ? $HTML::Tag::Font_Sizes[1] : |
49
|
|
|
|
|
|
|
($count < ($range * 3)) ? $HTML::Tag::Font_Sizes[2] : |
50
|
|
|
|
|
|
|
($count < ($range * 4)) ? $HTML::Tag::Font_Sizes[3] : |
51
|
|
|
|
|
|
|
$HTML::Tag::Font_Sizes[-1]; # default |
52
|
110
|
|
|
|
|
239
|
$tags{$tag}{size} = $size; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
## build the initial HTML |
57
|
4
|
|
|
|
|
1272
|
my $id = 'tag_cloud_1'; |
58
|
4
|
|
|
|
|
50
|
$html = " "; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
## iterate keys according to sort |
61
|
4
|
|
|
|
|
7
|
my @keys; |
62
|
4
|
50
|
|
|
|
14
|
if ($sort_method =~ /value/i) { |
63
|
0
|
|
|
|
|
0
|
@keys = sort { $tags{$a}{count} <=> $tags{$b}{count} } keys %tags; |
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
} else { |
65
|
4
|
|
|
|
|
26
|
@keys = sort { $a cmp $b } keys %tags; |
|
549
|
|
|
|
|
658
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
|
|
24
|
for (my $i = 0; $i <= $#keys; $i++) { |
69
|
110
|
|
|
|
|
120
|
my $lhtml; |
70
|
110
|
|
|
|
|
154
|
my $key = $keys[$i]; |
71
|
110
|
|
|
|
|
110
|
my %tag = %{$tags{$key}}; # need to have some error checking here |
|
110
|
|
|
|
|
457
|
|
72
|
110
|
|
|
|
|
203
|
my $size = $tag{size}; |
73
|
110
|
|
|
|
|
138
|
my $count = $tag{count}; |
74
|
|
|
|
|
|
|
|
75
|
110
|
|
|
|
|
121
|
my $link; |
76
|
110
|
100
|
|
|
|
200
|
if (defined $tag{link_rel}) { |
|
|
50
|
|
|
|
|
|
77
|
107
|
|
|
|
|
281
|
my $link = $tag{link_rel}; |
78
|
107
|
|
|
|
|
119
|
my $alt = $count; |
79
|
|
|
|
|
|
|
|
80
|
107
|
50
|
|
|
|
208
|
warn "WARN:: '' specified in '$key', but no 'base' spec in build_cloud() call" unless $base_url; |
81
|
107
|
|
|
|
|
320
|
$link =~ s//$base_url/; |
82
|
107
|
|
|
|
|
274
|
$link =~ s//$count/g; |
83
|
107
|
|
|
|
|
157
|
$link =~ s//$key/g; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
107
|
|
|
|
|
303
|
$lhtml = "$key"; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} elsif (defined $tag{link_abs}) { |
89
|
3
|
|
|
|
|
6
|
my $link = $tag{link_abs}; |
90
|
3
|
|
|
|
|
6
|
my $alt = $count; |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
24
|
$lhtml = "$key"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
0
|
warn "WARN:: no 'link_abs' or 'link_rel' specified for '$key'"; |
96
|
0
|
|
|
|
|
0
|
next; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
110
|
|
|
|
|
510
|
$html .= " " . $lhtml; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
## build the closing HTML |
104
|
4
|
|
|
|
|
6
|
$html .= ""; |
105
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
153
|
return $html; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |