ZofCMS/Plugin/TagCloud.pm

filter: Statementstmt 31.8% 14 / 44 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 2 totaltotal 26.8% 18 / 67 CC 6 SCAR 29.4
CC
6
Cov
26%
process
42.0
new
2.0
_make_css
2.0
CRAP 18.9
« ZofCMS/Plugin/AntiSpamMailTo.pm ↑ Summary ZofCMS/Plugin/FileToTemplate.pm »
1 package App::ZofCMS::Plugin::TagCloud;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use List::Util (qw/shuffle/);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 0 ▶sub process {
Subroutine process: not called CC=6 SCAR=37.4
Pod undocumented
14 0 my ( $self, $template, $query, $config ) = @_;
15  
16 my %conf = (
17 id => 'zofcms_tag_cloud',
18 class => 'zofcms_tag_cloud',
19 unit => '%',
20 uri_prefix => '',
21 shuffle => 0,
22 fg => '#00d',
23 bg => 'transparent',
24 fg_hover => '#66f',
25 bg_hover => 'transparent',
26 fg_visited => '#333',
27 bg_visited => 'transparent',
28 0 ▶ %{ delete $config->conf->{plug_tag_cloud} || {} },
Condition0%0/2
delete $config->conf->{'plug_tag_cloud'} || {}
l!l
00
MC/DC0%0/1
delete $config->conf->{'plug_tag_cloud'} || {}
delete $config->conf->{'plug_tag_cloud'}
Truth table0%0/2
A
A= delete $config->conf->{'plug_tag_cloud'}
Aresult
11
00
29 0 ▶ %{ delete $template->{plug_tag_cloud} || {} },
Condition0%0/2
delete $template->{'plug_tag_cloud'} || {}
l!l
00
MC/DC0%0/1
delete $template->{'plug_tag_cloud'} || {}
delete $template->{'plug_tag_cloud'}
Truth table0%0/2
A
A= delete $template->{'plug_tag_cloud'}
Aresult
11
00
30 );
31  
32 return
33 0 ▶ unless keys %conf;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %conf 0 0 0
34  
35 0 my @tags = @{ delete $conf{tags} };
36 0 ▶ if ( not ref $tags[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $tags[0]) 0 0 0
37 0 @tags = map [ splice @tags, 0, 3 ], 0..$#tags/3;
38 }
39  
40 0 ▶ if ( $conf{shuffle} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{"shuffle"}) 0 0 0
41 0 @tags = shuffle @tags;
42 }
43  
44 0 my $t = $self->_tag_template;
45 $t->param(
46 id => $conf{id},
47 tags => [
48 map +{
49 tag => $_->[0],
50 href => $conf{uri_prefix} . $_->[1],
51 0 class => do {
52 0 my $x = $conf{class} . $_->[2];
53 0 $x =~ s/[^\w-]/_/g;
54 0 $x;
55 },
56 }, @tags
57 ],
58 );
59  
60 0 $template->{t}{tag_cloud} = $t->output;
61 0 $template->{t}{tag_cloud_css} = $self->_make_css( \@tags, \%conf );
62 }
63  
64 0 ▶sub _make_css {
Subroutine _make_css: not called CC=1 SCAR=6.9
65 0 my ( $self, $tags, $conf ) = @_;
66 0 my @sizes = sort { $a <=> $b } map $_->[2], @$tags;
67 0 my $t = $self->_css_template;
68 $t->param(
69 tags => [
70 map +{
71 class => $conf->{class},
72 0 class_num => do { my $x = $_; $x =~ s/[^\w-]/_/g; $x; },
73 num => $_,
74 unit => $conf->{unit},
75 }, @sizes
76 ],
77 0 map +( $_ => $conf->{ $_ } ),
78 qw/id fg bg fg_hover bg_hover fg_visited bg_visited/,
79 );
80 0 return $t->output;
81 }
82  
83 0 ▶sub _css_template {
Subroutine _css_template: not called CC=1 SCAR=6.9
84 0 return HTML::Template->new_scalar_ref( \ <<'END'
85 #<tmpl_var name="id"> li {
86 display: inline;
87 }
88 #<tmpl_var name="id"> a {
89 color: <tmpl_var name="fg">;
90 background: <tmpl_var name="bg">;
91 }
92 #<tmpl_var name="id"> a:visited {
93 color: <tmpl_var name="fg_visited">;
94 background: <tmpl_var name="bg_visited">;
95 }
96 #<tmpl_var name="id"> a:hover {
97 color: <tmpl_var name="fg_hover">;
98 background: <tmpl_var name="bg_hover">;
99 }
100 <tmpl_loop name="tags">.<tmpl_var name="class"><tmpl_var name="class_num"> { font-size: <tmpl_var name="num"><tmpl_var name="unit">; }
101 </tmpl_loop>
102 END
103 );
104 }
105  
106 0 ▶sub _tag_template {
Subroutine _tag_template: not called CC=1 SCAR=6.9
107 0 return HTML::Template->new_scalar_ref( \ <<'END'
108 <ul id="<tmpl_var escape="html" name="id">"><tmpl_loop name="tags">
109 <li class="<tmpl_var escape="html" name="class">"><a href="<tmpl_var escape="html" name="href">"><tmpl_var escape="html" name="tag"></a></li></tmpl_loop>
110 </ul>
111 END
112 );
113 }
114  
115 1 1;
116 __END__
« ZofCMS/Plugin/AntiSpamMailTo.pm ↑ Summary ZofCMS/Plugin/FileToTemplate.pm »