blib/lib/URI/GoogleChart.pm

filter: Statementstmt 96.4% 192 / 199 Branchbran 82.7% 101 / 122 Conditioncond 75.3% 58 / 77 MC/DCmcdc 46.5% 20 / 43 Subroutinesub 100% 20 / 20 Podpod 50.0% 1 / 2 totaltotal 84.6% 392 / 463 CC 102 SCAR 37.2
CC
102
Cov
88%
_data
69.8
new
14.4
__ANON__
12.0
CRAP 41.1
↑ Summary
1 package URI::GoogleChart;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = "1.02";
6  
7 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 my $BASE = "http://chart.apis.google.com/chart";
11  
12 2 our %TYPE_ALIAS = (
13 "lines" => "lc",
14 "sparklines" => "ls",
15 "xy-lines" => "lxy",
16  
17 "horizontal-stacked-bars" => "bhs",
18 "vertical-stacked-bars" => "bvs",
19 "horizontal-grouped-bars" => "bhg",
20 "vertical-grouped-bars" => "bvg",
21  
22 "pie" => "p",
23 "pie-3d" => "p3",
24 "3d-pie" => "p3",
25 "concentric-pie" => "pc",
26  
27 "venn" => "v",
28 "scatter-plot" => "s",
29 "radar" => "r",
30 "radar-splines" => "rs",
31 "google-o-meter" => "gom",
32  
33 "africa" => "t",
34 "asia" => "t",
35 "europe" => "t",
36 "middle_east" => "t",
37 "south_america" => "t",
38 "usa" => "t",
39 "world" => "t",
40 );
41  
42 2 our %COLOR_ALIAS = (
43 "red" => "FF0000",
44 "lime" => "00FF00",
45 "blue" => "0000FF",
46  
47 "green" => "008000",
48 "navy" => "000080",
49  
50 "yellow" => "FFFF00",
51 "aqua" => "00FFFF",
52 "fuchsia" => "FF00FF",
53 "maroon" => "800000",
54 "purple" => "800080",
55 "olive" => "808000",
56 "teal" => "008080",
57  
58 "white" => "FFFFFF",
59 "silver" => "C0C0C0",
60 "gray" => "808080",
61 "black" => "000000",
62  
63 "transparent" => "00000000",
64 );
65  
66 2 our %AXIS_ALIAS = (
67 "left" => "y",
68 "right" => "r",
69 "top" => "t",
70 "bottom" => "x",
71 );
72  
73 2 our %ENCODING_ALIAS = (
74 "text" => "t",
75 "simple" => "s",
76 "extended" => "e",
77 );
78  
79 # constants for data encoding
80 2 my @C = ("A" .. "Z", "a" .. "z", 0 .. 9, "-", ".");
81 2 my $STR_s = join("", @C[0 .. 61]);
82 2 my $STR_e = do {
83 2 my @v;
84 2 for my $x (@C) {
85 128 for my $y (@C) {
86 8192 push(@v, "$x$y");
87 }
88 }
89 2 join("", @v);
90 };
91 2 ▶die unless length($STR_s) == 62;
Branch: 1 branch
BranchTrueFalseTotal
unless length $STR_s == 62 0 2 2
92 2 ▶die unless length($STR_e) == 4096 * 2;
Branch: 1 branch
BranchTrueFalseTotal
unless length $STR_e == 8192 0 2 2
93  
94  
95 22 ▶sub new {
Subroutine new: called CC=13 SCAR=26.6
Pod documented
96 22 my($class, $type, $width, $height, %opt) = @_;
97  
98 22 ▶ croak("Chart type not provided") unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 22 22
99 22 ▶ croak("Chart size not provided") unless $width && $height;
Branch: 1 branch
BranchTrueFalseTotal
unless $width and $height 0 22 22
Condition33%1/3
$width and $height
!ll&&!rl&&r
0022
MC/DC0%0/2
$width and $height
$width $height
Truth table33%1/3
A and B
A= $widthB= $height
ABresult
0X0
100
111
100  
101 my %param = (
102 22 ▶ cht => $TYPE_ALIAS{$type} || $type,
Condition66%2/3
$URI::GoogleChart::TYPE_ALIAS{$type} || $type
l!l&&r!l&&!r
2020
MC/DC0%0/2
$URI::GoogleChart::TYPE_ALIAS{$type} || $type
$URI::GoogleChart::TYPE_ALIAS{$type} $type
Truth table66%2/3
A || B
A= $URI::GoogleChart::TYPE_ALIAS{$type}B= $type
ABresult
1X1
011
000
103 chs => join("x", $width, $height),
104 );
105 22 ▶ $param{chtm} = $type if $param{cht} eq "t" && $type ne "t"; # maps
Branch: 1 branch
BranchTrueFalseTotal
if $param{"cht"} eq "t" and $type ne "t" 3 19 22
Condition66%2/3
$param{"cht"} eq "t" and $type ne "t"
!ll&&!rl&&r
1903
MC/DC50%1/2
$param{"cht"} eq "t" and $type ne "t"
$param{"cht"} eq "t" $type ne "t"
Truth table66%2/3
A and B
A= $param{"cht"} eq "t"B= $type ne "t"
ABresult
0X0
100
111
106  
107 my %handle = (
108 data => \&_data,
109 range => 1,
110 min => 1,
111 max => 1,
112 range_round => 1,
113 range_show => 1,
114 encoding => 1,
115  
116 8 ▶ color => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
117 8 my $v = shift;
118 8 ▶ $v = [$v] unless ref($v);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 2 6 8
119 8 $param{chco} = join(",", map _color($_), @$v);
120 },
121 3 ▶ background => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
122 3 $param{chf} = "bg,s," . _color(shift);
123 },
124 4 ▶ title => sub {
Subroutine __ANON__: called CC=6 SCAR=24.8
125 4 my $title = shift;
126 4 ▶ ($title, my($color, $size)) = @$title if ref($title) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $title eq "ARRAY" 0 4 4
127 4 $title =~ s/\n+\z//;
128 4 $title =~ s/\n/|/g;
129 4 $param{chtt} = $title;
130 4 ▶ if (defined($color) || defined($size)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $color or defined $size) 0 4 4
Condition33%1/3
defined $color or defined $size
l!l&&r!l&&!r
004
MC/DC0%0/2
defined $color or defined $size
defined $color defined $size
Truth table33%1/3
A or B
A= defined $colorB= defined $size
ABresult
1X1
011
000
131 0 ▶ $color = defined($color) ? _color($color) : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $color ? : 0 0 0
132 0 ▶ $size = "" unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
133 0 $param{chts} = "$color,$size";
134 }
135 },
136 7 ▶ label => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
137 7 my $lab = shift;
138 7 ▶ $lab = [$lab] unless ref($lab) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lab eq "ARRAY" 1 6 7
139 7 ▶ my $k = $param{cht} =~ /^p|^gom$/ ? "chl" : "chdl";
Branch: 1 branch
BranchTrueFalseTotal
$param{'cht'} =~ /^p|^gom$/ ? : 4 3 7
140 7 $param{$k} = join("|", @$lab);
141 },
142 2 ▶ rotate => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
143 2 my $p = shift;
144 2 ▶ $p += 360 while $p < 0;
Branch: 1 branch
BranchTrueFalseTotal
$p < 0 and do { $p += 360 } 1 2 3
145 2 $p /= 180 / 3.1416; # convert to radians
146 2 $param{chp} = sprintf "%.2f", $p;
147 },
148 6 ▶ margin => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
149 6 my $m = shift;
150 6 ▶ $m = [($m) x 4] unless ref($m);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $m 5 1 6
151 6 $param{chma} = join(",", @$m);
152 }
153 22 );
154  
155 22 my $data = delete $opt{data}; # need to be processed last
156 22 for my $k (keys %opt) {
157 52 ▶ if (my $h = $handle{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $handle{$k}) { } 45 7 52
158 45 ▶ $h->($opt{$k}, \%param, \%opt) if ref($h) eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $h eq "CODE" 30 15 45
159 }
160 else {
161 7 $param{$k} = $opt{$k};
162 7 ▶ carp("Unrecognized parameter '$k' embedded in GoogleChart URI")
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^ch/ 0 7 7
163 unless $k =~ /^ch/;
164 }
165 }
166 22 ▶ _data($data, \%param, \%opt) if $data;
Branch: 1 branch
BranchTrueFalseTotal
if $data 19 3 22
167  
168 # generate URI
169 22 my $uri = URI->new($BASE);
170 22 $uri->query_form(map { $_ => $param{$_} } _sort_chart_keys(keys %param));
171 22 for ($uri->query) {
172 22 s/%3A/:/g;
173 22 s/%2C/,/g;
174 22 s/%7C/|/g; # XXX doesn't work (it ends up encoded anyways)
175 22 $uri->query($_);
176 }
177 22 return $uri;
178 }
179  
180 19 ▶sub _color {
Subroutine _color: called CC=3 SCAR=11.1
181 19 local $_ = shift;
182 19 ▶ return $COLOR_ALIAS{$_} ||
Branch: 1 branch
BranchTrueFalseTotal
/^[\da-fA-F]{3}\z/ ? : 1 3 4
Condition66%2/3
$URI::GoogleChart::COLOR_ALIAS{$_} || (/^[\da-fA-F]{3}\z/ ? join('', map("$_$_", split(//, $_, 0))) : $_)
l!l&&r!l&&!r
1540
MC/DC0%0/2
$URI::GoogleChart::COLOR_ALIAS{$_} || (/^[\da-fA-F]{3}\z/ ? join('', map("$_$_", split(//, $_, 0))) : $_)
$URI::GoogleChart::COLOR_ALIAS{$_} (/^[\da-fA-F]{3}\z/ ? join('', map("$_$_", split(//, $_, 0))) : $_)
Truth table66%2/3
A || B
A= $URI::GoogleChart::COLOR_ALIAS{$_}B= (/^[\da-fA-F]{3}\z/ ? join('', map("$_$_", split(//, $_, 0))) : $_)
ABresult
1X1
011
000
183 (/^[\da-fA-F]{3}\z/ ? join("", map "$_$_", split(//, $_)) : $_);
184 }
185  
186 22 ▶sub _sort_chart_keys {
Subroutine _sort_chart_keys: called CC=4 SCAR=13.9
187 22 my %o = ( cht => 1, chtm => 2, chs => 3, chd => 100 );
188 22 ▶ return sort { ($o{$a}||=99) <=> ($o{$b}||=99) || $a cmp $b } @_;
Condition85%6/7
($o{$a} ||= 99) <=> ($o{$b} ||= 99) || $a cmp $b
l!l&&r!l&&!r
123510
$o{$a} ||= 99
l!l
15024
$o{$b} ||= 99
l!l
14826
MC/DC0%0/2
($o{$a} ||= 99) <=> ($o{$b} ||= 99) || $a cmp $b
($o{$a} ||= 99) <=> ($o{$b} ||= 99) $a cmp $b
MC/DC100%1/1
$o{$a} ||= 99
$o{$a}
MC/DC100%1/1
$o{$b} ||= 99
$o{$b}
Truth table66%2/3
A || B
A= ($o{$a} ||= 99) <=> ($o{$b} ||= 99)B= $a cmp $b
ABresult
1X1
011
000
Truth table100%2/2
A
A= $o{$a}
Aresult
11
00
Truth table100%2/2
A
A= $o{$b}
Aresult
11
00
189 }
190  
191 25 ▶sub _default_minmax {
Subroutine _default_minmax: called CC=6 SCAR=17.9
192 25 my $param = shift;
193 25 my $t = $param->{cht};
194 25 ▶ return 0, undef if $t =~ /^p/; # pie chart
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /^p/ 3 22 25
195 22 ▶ return 0, undef if $t eq "v"; # venn
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "v" 1 21 22
196 21 ▶ return 0, undef if $t =~ /^r/; # radar chart
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /^r/ 0 21 21
197 21 ▶ return 0, undef if $t =~ /^b/; # bar chart
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /^b/ 6 15 21
198 15 ▶ return 0, 100 if $t eq "gom"; # meter
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "gom" 1 14 15
199 14 return;
200 }
201  
202 19 ▶sub _data {
Subroutine _data: called CC=66 SCAR=42.5
203 19 my($data, $param, $opt) = @_;
204  
205 # various shortcuts
206 19 $data = _deep_copy($data); # want to modify it
207 19 ▶ if (ref($data) eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 18 1 19
elsif (ref $data eq 'HASH') { } 0 1 1
208 18 ▶ $data = [$data] unless ref($data->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data->[0] 14 4 18
209 }
210 elsif (ref($data) eq "HASH") {
211 0 $data = [$data];
212 }
213 else {
214 1 $data = [[$data]];
215 }
216  
217 19 my $range = _deep_copy($opt->{range});
218 19 for (qw(min max range_round range_show)) {
219 76 (my $r = $_) =~ s/^range_//;
220 76 ▶ $range->{""}{$r} = $opt->{$_} if exists $opt->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt->{$_} 10 66 76
221 }
222  
223 19 my $vcount = 0;
224 19 for my $set (@$data) {
225 25 ▶ $set = { v => $set } if ref($set) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $set eq "ARRAY" 23 2 25
226 25 my $v = $set->{v};
227 25 ▶ my $r = $set->{range} ||= "";
Condition100%2/2
$set->{"range"} ||= ""
l!l
223
MC/DC100%1/1
$set->{"range"} ||= ""
$set->{"range"}
Truth table100%2/2
A
A= $set->{"range"}
Aresult
11
00
228 25 ▶ my $rh = $range->{$r} ||= {};
Condition100%2/2
$range->{$r} ||= {}
l!l
1510
MC/DC100%1/1
$range->{$r} ||= {}
$range->{$r}
Truth table100%2/2
A
A= $range->{$r}
Aresult
11
00
229  
230 25 my($min, $max) = _default_minmax($param);
231 25 my $i = 0;
232 25 for (@$v) {
233 136 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 135 136
234 135 ▶ $min = $_ if !defined($min) || $_ < $min;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min or $_ < $min 23 112 135
Condition100%3/3
not defined $min or $_ < $min
l!l&&r!l&&!r
1310112
MC/DC100%2/2
not defined $min or $_ < $min
not defined $min $_ < $min
Truth table100%3/3
not(A) or B
A= not defined $minB= $_ < $min
ABresult
1X1
011
000
235 135 ▶ $max = $_ if !defined($max) || $_ > $max;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max or $_ > $max 61 74 135
Condition100%3/3
not defined $max or $_ > $max
l!l&&r!l&&!r
233874
MC/DC100%2/2
not defined $max or $_ > $max
not defined $max $_ > $max
Truth table100%3/3
not(A) or B
A= not defined $maxB= $_ > $max
ABresult
1X1
011
000
236 135 ▶ if ($param->{cht} =~ /^b.s\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"cht"} =~ /^b.s\z/) 22 113 135
237 # stacked stuff
238 22 ▶ $rh->{stacked}{min}[$i] ||= 0;
Condition50%1/2
$rh->{"stacked"}{"min"}[$i] ||= 0
l!l
022
MC/DC0%0/1
$rh->{"stacked"}{"min"}[$i] ||= 0
$rh->{"stacked"}{"min"}[$i]
Truth table50%1/2
A
A= $rh->{"stacked"}{"min"}[$i]
Aresult
11
00
239 22 ▶ $rh->{stacked}{max}[$i] ||= 0;
Condition100%2/2
$rh->{"stacked"}{"max"}[$i] ||= 0
l!l
517
MC/DC100%1/1
$rh->{"stacked"}{"max"}[$i] ||= 0
$rh->{"stacked"}{"max"}[$i]
Truth table100%2/2
A
A= $rh->{"stacked"}{"max"}[$i]
Aresult
11
00
240 22 ▶ $rh->{stacked}{$_ < 0 ? "min" : "max"}[$i] += $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 ? : 8 14 22
241 }
242 }
243 continue {
244 136 $i++;
245 }
246 25 $vcount += @$v;
247  
248 25 ▶ if ($rh->{stacked}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rh->{"stacked"}) 4 21 25
249 # XXX we really only need to this after we have processed
250 # the last dataset, the other rounds it's wasted effort
251 4 ($min, $max) = (0, 0);
252 4 for (qw(min max)) {
253 8 for my $v (@{$rh->{stacked}{$_}}) {
254 44 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 44 44
255 44 ▶ if ($_ eq "min") {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq 'min') { } 22 22 44
256 22 ▶ $min = $v if $v < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $v < $min 3 19 22
257 }
258 else {
259 22 ▶ $max = $v if $v > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $v > $max 9 13 22
260 }
261 }
262 }
263 }
264  
265 25 ▶ if (defined $min) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min) 24 1 25
266 24 my %h = (min => $min, max => $max);
267 24 for my $k (keys %h) {
268 48 ▶ if (defined $set->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set->{$k}) { } 0 48 48
269 0 $h{$k} = $set->{$k};
270 }
271 else {
272 48 $set->{$k} = $h{$k};
273 }
274  
275 48 my $rv = $rh->{$k};
276 48 ▶ if (!defined($rv) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv or $k eq "min" and $h{$k} < $rv or $k eq "max" and $h{$k} > $rv) 40 8 48
Condition100%12/12
not defined $rv or $k eq "min" and $h{$k} < $rv or $k eq "max" and $h{$k} > $rv
l!l&&r!l&&!r
3828
not defined $rv or $k eq "min" and $h{$k} < $rv
l!l&&r!l&&!r
37110
$k eq "min" and $h{$k} < $rv
!ll&&!rl&&r
551
$k eq "max" and $h{$k} > $rv
!ll&&!rl&&r
532
MC/DC80%4/5
not defined $rv or $k eq "min" and $h{$k} < $rv or $k eq "max" and $h{$k} > $rv
not defined $rv $k eq "min" $h{$k} < $rv $k eq "max" $h{$k} > $rv
Truth table62%5/8
not(A) or B and C or D and E
A= not defined $rvB= $k eq "min"C= $h{$k} < $rvD= $k eq "max"E= $h{$k} > $rv
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
277 ($k eq "min" && $h{$k} < $rv) ||
278 ($k eq "max" && $h{$k} > $rv)
279 )
280 {
281 40 $rh->{$k} = $h{$k};
282 }
283 }
284 }
285 }
286  
287 # should we round any of the ranges
288 19 for my $r (values %$range) {
289 20 ▶ next unless $r->{round};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"round"} 16 4 20
290  
291 2 ▶ use POSIX qw(floor ceil);
Subroutine BEGIN: called CC=1 SCAR=0.0
292 4 ▶ sub log10 { log(shift) / log(10) }
Subroutine log10: called CC=1 SCAR=0.0
Pod undocumented
293  
294 4 my($min, $max) = @$r{"min", "max"};
295 4 my $range = $max - $min;
296 4 ▶ next if $range == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $range == 0 0 4 4
297 4 ▶ die "Assert" if $range < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $range < 0 0 4 4
298  
299 4 my $step = 10 ** int(log10($range));
300 4 ▶ $step /= 10 if $step / $range >= 0.1;
Branch: 1 branch
BranchTrueFalseTotal
if $step / $range >= "0.1" 4 0 4
301 4 ▶ $step *= 5 if $step / $range < 0.05;
Branch: 1 branch
BranchTrueFalseTotal
if $step / $range < "0.05" 3 1 4
302  
303 4 $min = floor($min / $step - 0.2) * $step;
304 4 $max = ceil($max / $step + 0.2) * $step;
305  
306 # zero based minimum is usually a good thing so make it more likely
307 4 ▶ $min = 0 if $min > 0 && $min/$range < 0.4;
Branch: 1 branch
BranchTrueFalseTotal
if $min > 0 and $min / $range < "0.4" 1 3 4
Condition66%2/3
$min > 0 and $min / $range < "0.4"
!ll&&!rl&&r
031
MC/DC50%1/2
$min > 0 and $min / $range < "0.4"
$min > 0 $min / $range < "0.4"
Truth table66%2/3
A and B
A= $min > 0B= $min / $range < "0.4"
ABresult
0X0
100
111
308  
309 4 @$r{"min", "max"} = ($min, $max);
310 }
311  
312 #use Data::Dump; dd $data;
313 #use Data::Dump; dd $range;
314  
315 # encode data
316 19 ▶ my $e = $ENCODING_ALIAS{$opt->{encoding} || ""} || $opt->{encoding};
Condition80%4/5
$URI::GoogleChart::ENCODING_ALIAS{$opt->{'encoding'} or ''} || $opt->{'encoding'}
l!l&&r!l&&!r
0415
$opt->{'encoding'} || ''
l!l
415
MC/DC50%1/2
$URI::GoogleChart::ENCODING_ALIAS{$opt->{'encoding'} or ''} || $opt->{'encoding'}
$URI::GoogleChart::ENCODING_ALIAS{$opt->{'encoding'} or ''} $opt->{'encoding'}
MC/DC100%1/1
$opt->{'encoding'} || ''
$opt->{'encoding'}
Truth table66%2/3
A || B
A= $URI::GoogleChart::ENCODING_ALIAS{$opt->{'encoding'} or ''}B= $opt->{'encoding'}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $opt->{'encoding'}
Aresult
11
00
317 19 ▶ unless ($e) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 15 4 19
318 # try to me a little smart about selecting a suitable encoding based
319 # on the number of data points we're plotting and the resolution of
320 # the generated image
321 15 my @s = ($param->{chs} =~ /(\d+)/g);
322 15 my $res = $s[0] * $s[1];
323 15 ▶ if ($vcount < 20) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vcount < 20) { } 13 2 15
elsif ($vcount > 256 or $res < 60000) { } 2 0 2
324 13 $e = "t";
325 }
326 ▶ elsif ($vcount > 256 || $res < 300*200) {
Condition33%1/3
$vcount > 256 or $res < 60000
l!l&&r!l&&!r
020
MC/DC0%0/2
$vcount > 256 or $res < 60000
$vcount > 256 $res < 60000
Truth table33%1/3
A or B
A= $vcount > 256B= $res < 60000
ABresult
1X1
011
000
327 2 $e = "s";
328 }
329 else {
330 0 $e = "e";
331 }
332 }
333  
334 my %enc = (
335 t => {
336 null => -1,
337 sep1 => ",",
338 sep2 => "|",
339 78 ▶ fmt => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
340 78 my $v = 100 * shift;
341 78 ▶ $v = sprintf "%.1f", $v if $v ne int($v);
Branch: 1 branch
BranchTrueFalseTotal
if $v ne int $v 25 53 78
342 78 $v;
343 },
344 },
345 s => {
346 null => "_",
347 sep1 => "",
348 sep2 => ",",
349 54 ▶ fmt => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
350 54 return substr($STR_s, $_[0] * length($STR_s) - 0.5, 1);
351 },
352 },
353 e => {
354 null => "__",
355 sep1 => "",
356 sep2 => ",",
357 3 ▶ fmt => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
358 3 return substr($STR_e, int($_[0] * length($STR_e) / 2 - 0.5) * 2, 2);
359 },
360 }
361 19 );
362 19 ▶ my $enc = $enc{$e} || croak("unsupported encoding $e");
Condition50%1/2
$enc{$e} || croak("unsupported encoding $e")
l!l
190
MC/DC0%0/1
$enc{$e} || croak("unsupported encoding $e")
$enc{$e}
Truth table50%1/2
A
A= $enc{$e}
Aresult
11
00
363 19 my @res;
364 19 for my $set (@$data) {
365 25 my($min, $max) = @{$range->{$set->{range}}}{"min", "max"};
366 25 my $v = $set->{v};
367 25 for (@$v) {
368 136 ▶ if (defined($_) && $_ >= $min && $_ <= $max && $min != $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and $_ >= $min and $_ <= $max and $min != $max) { } 135 1 136
Condition66%6/9
defined $_ and $_ >= $min and $_ <= $max and $min != $max
!ll&&!rl&&r
10135
defined $_ and $_ >= $min and $_ <= $max
!ll&&!rl&&r
10135
defined $_ and $_ >= $min
!ll&&!rl&&r
10135
MC/DC25%1/4
defined $_ and $_ >= $min and $_ <= $max and $min != $max
defined $_ $_ >= $min $_ <= $max $min != $max
Truth table40%2/5
A and B and C and D
A= defined $_B= $_ >= $minC= $_ <= $maxD= $min != $max
ABCDresult
0XXX0
10XX0
110X0
11100
11111
369 135 $_ = $enc->{fmt}(($_ - $min) / ($max - $min));
370 }
371 else {
372 1 $_ = $enc->{null};
373 }
374 }
375 25 push(@res, join($enc->{sep1}, @$v));
376 }
377 19 $param->{chd} = "$e:" . join($enc->{sep2}, @res);
378  
379 # handle bar chart zero line if we charted negative data
380 19 ▶ if ($param->{cht} =~ /^b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"cht"} =~ /^b/) 4 15 19
381 4 my($min, $max) = @{$range->{""}}{"min", "max"};
382 4 ▶ if ($min < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min < 0) 2 2 4
383 2 ▶ $param->{chp} = $max < 0 ? 1 : sprintf "%.2f", -$min / ($max - $min);
Branch: 1 branch
BranchTrueFalseTotal
$max < 0 ? : 0 2 2
384 }
385 }
386  
387 # enable axis labels?
388 19 for (sort keys %$range) {
389 20 my $r = $range->{$_};
390 20 ▶ my @chxt = split(/,/, $param->{chxt} || "");
Condition100%2/2
$param->{'chxt'} || ''
l!l
218
MC/DC100%1/1
$param->{'chxt'} || ''
$param->{'chxt'}
Truth table100%2/2
A
A= $param->{'chxt'}
Aresult
11
00
391 20 ▶ my @chxr = split(/\|/, $param->{chxr} || "");
Condition100%2/2
$param->{'chxr'} || ''
l!l
119
MC/DC100%1/1
$param->{'chxr'} || ''
$param->{'chxr'}
Truth table100%2/2
A
A= $param->{'chxr'}
Aresult
11
00
392 20 ▶ if (my $rshow = $r->{show}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rshow = $r->{"show"}) 7 13 20
393 7 my($min, $max) = @$r{"min", "max"};
394 7 for ($min, $max) {
395 14 $_ = sprintf "%.2g", $_;
396 }
397 7 ▶ push(@chxt, $AXIS_ALIAS{$rshow} || $rshow);
Condition33%1/3
$URI::GoogleChart::AXIS_ALIAS{$rshow} || $rshow
l!l&&r!l&&!r
700
MC/DC0%0/2
$URI::GoogleChart::AXIS_ALIAS{$rshow} || $rshow
$URI::GoogleChart::AXIS_ALIAS{$rshow} $rshow
Truth table33%1/3
A || B
A= $URI::GoogleChart::AXIS_ALIAS{$rshow}B= $rshow
ABresult
1X1
011
000
398 7 my $i = $#chxt;
399 7 push(@chxr, "$i,$min,$max");
400 }
401 20 ▶ if (@chxt) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chxt) 7 13 20
402 7 $param->{chxt} = join(",", @chxt);
403 7 $param->{chxr} = join("|", @chxr);
404 }
405 }
406 }
407  
408 193 ▶sub _deep_copy {
Subroutine _deep_copy: called CC=4 SCAR=14.0
409 193 my $o = shift;
410 193 ▶ return $o unless ref($o);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $o 160 33 193
411 33 ▶ return [map _deep_copy($_), @$o] if ref($o) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $o eq "ARRAY" 28 5 33
412 5 ▶ return {map { $_ => _deep_copy($o->{$_}) } keys %$o} if ref($o) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $o eq "HASH" 5 0 5
413 0 die "Can't copy " . ref($o);
414 }
415  
416 2 1;
417  
418 __END__
↑ Summary