Chart/Data/Extended.pm

filter: Statementstmt 44.2% 31 / 70 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 63.6% 7 / 11 Podpod 66.6% 2 / 3 totaltotal 39.2% 40 / 102 CC 10 SCAR 31.8
CC
10
Cov
36%
BUILDARGS
56.0
as_string
20.0
parameter_value
2.0
CRAP 24.1
« Chart/Axis.pm ↑ Summary Chart/Title.pm »
1 # $Id$
2  
3 package Google::Chart::Data::Extended;
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 with 'Google::Chart::Data';
8  
9 1 has 'max_value' => (
10 is => 'rw',
11 isa => 'Num',
12 required => 1,
13 );
14  
15 1 has 'min_value' => (
16 is => 'rw',
17 isa => 'Num',
18 required => 1,
19 default => 0,
20 );
21  
22 1 has '+dataset' => (
23 isa => 'ArrayRef[Google::Chart::Data::Extended::DataSet]',
24 );
25  
26 1 __PACKAGE__->meta->make_immutable;
27  
28 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub BUILDARGS {
Subroutine BUILDARGS: not called CC=7 SCAR=40.3
Pod documented
31 0 my $self = shift;
32  
33 # A dataset must be an array of arrays or array of values
34 0 my @dataset;
35 my @dataargs;
36 0 my %args;
37  
38 0 ▶ if (@_ == 1 && ref $_[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
39 0 @dataargs = @{$_[0]};
40 } else {
41 0 %args = @_;
42 0 ▶ @dataargs = @{ delete $args{dataset} || [] };
Condition0%0/2
delete $args{'dataset'} || []
l!l
00
MC/DC0%0/1
delete $args{'dataset'} || []
delete $args{'dataset'}
Truth table0%0/2
A
A= delete $args{'dataset'}
Aresult
11
00
43 }
44  
45 0 ▶ if (! ref $dataargs[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $dataargs[0]) 0 0 0
46 0 @dataargs = ([ @dataargs]);
47 }
48  
49 0 foreach my $dataset ( @dataargs ) {
50 0 ▶ if (! Scalar::Util::blessed $dataset) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($dataset)) 0 0 0
51 0 $dataset = Google::Chart::Data::Extended::DataSet->new(data => $dataset)
52 }
53 0 push @dataset, $dataset;
54 }
55  
56 0 return { %args, dataset => \@dataset }
57 }
58  
59 0 ▶sub parameter_value {
Subroutine parameter_value: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61 0 my $max = $self->max_value;
62 0 my $min = $self->min_value;
63 sprintf('e:%s',
64 0 join( ',', map { $_->as_string({max => $max, min => $min}) } @{ $self->dataset } ) );
65 }
66  
67 package # hide from PAUSE
68 Google::Chart::Data::Extended::DataSet;
69 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 1 subtype 'Google::Chart::Data::Extended::DataSet::Value'
73 => as 'Num';
74  
75 has 'data' => (
76 is => 'rw',
77 isa => 'ArrayRef[Maybe[Google::Chart::Data::Extended::DataSet::Value]]',
78 required => 1,
79 0 ▶ default => sub { +[] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 1 );
81  
82 1 __PACKAGE__->meta->make_immutable;
83  
84 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 1 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 1 my @map = ('A'..'Z', 'a'..'z', 0..9, '-', '.');
88  
89 0 ▶sub as_string {
Subroutine as_string: not called CC=4 SCAR=30.0
Pod undocumented
90 0 my ($self, $args) = @_;
91 0 my $max = $args->{max};
92 0 my $min = $args->{min};
93 0 my $map_size = scalar @map;
94 0 my $scale = $map_size ** 2 - 1;
95 0 my $result = '';
96 0 for my $data (@{$self->data}) {
97 0 my $v = '__';
98 # if (defined $data && looks_like_number($data)) {
99 0 my $normalized = int((($data - $min) * $scale) / abs($max - $min));
100 0 ▶ if ($normalized < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($normalized < 0) { } 0 0 0
elsif ($normalized >= $scale) { } 0 0 0
101 0 $normalized = 0;
102 } elsif ($normalized >= $scale) {
103 0 $normalized = $scale - 1;
104 }
105  
106 0 $v = $map[ int($normalized / $map_size) ] . $map[ int($normalized % $map_size) ];
107 # }
108  
109 0 $result .= $v;
110 }
111 0 return $result;
112 }
113  
114 1 1;
115  
116 __END__
« Chart/Axis.pm ↑ Summary Chart/Title.pm »