Clicker/Data/Series.pm

filter: Statementstmt 94.3% 50 / 53 Branchbran 100% 10 / 10 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 90.9% 10 / 11 Podpod 75.0% 3 / 4 totaltotal 92.3% 85 / 92 CC 11 SCAR 11.8
CC
11
Cov
94%
BUILDARGS
6.0
get_value_for_key
4.0
_build_range
2.0
CRAP 3.2
« Clicker/Decoration/Plot.pm ↑ Summary Clicker/Axis/DivisionType/Exact.pm »
1 package Chart::Clicker::Data::Series;
2 11 $Chart::Clicker::Data::Series::VERSION = '2.90';
3 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: A series of key, value pairs representing chart data
6  
7 11 ▶use List::Util qw(max min);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Chart::Clicker::Data::Range;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 has 'keys' => (
12 traits => [ 'Array' ],
13 is => 'rw',
14 isa => 'ArrayRef[Num]',
15 7 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 11 handles => {
17 'add_to_keys' => 'push',
18 'key_count' => 'count'
19 }
20 );
21  
22  
23 11 has 'name' => (
24 is => 'rw',
25 isa => 'Str',
26 predicate => 'has_name'
27 );
28  
29  
30 11 has 'range' => (
31 is => 'rw',
32 isa => 'Chart::Clicker::Data::Range',
33 lazy_build => 1
34 );
35  
36  
37 has 'values' => (
38 traits => [ 'Array' ],
39 is => 'rw',
40 isa => 'ArrayRef[Num|Undef]',
41 7 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 11 handles => {
43 'add_to_values' => 'push',
44 'value_count' => 'count'
45 }
46 );
47  
48 5 ▶sub _build_range {
Subroutine _build_range: called CC=2 SCAR=6.9
49 5 my ($self) = @_;
50  
51 5 my $values = $self->values;
52  
53 confess('A series must have values before it can be charted')
54 5 ▶ unless scalar(@{ $values });
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$values;} 1 4 5
55  
56 return Chart::Clicker::Data::Range->new(
57 13 lower => min(grep { defined } @{ $values }),
58 4 upper => max(grep { defined } @{ $values })
59 );
60 }
61  
62 21 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=6 SCAR=17.9
Pod documented
63 21 my ($class, @args) = @_;
64  
65 21 ▶ if(@args == 1 && (ref($args[0]) eq 'HASH') && !exists($args[0]->{keys})) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args == 1 and ref $args[0] eq 'HASH' and not exists $args[0]{'keys'}) { } 1 20 21
elsif (@args % 2 == 0) { } 17 3 20
Condition83%5/6
@args == 1 and ref $args[0] eq "HASH" and not exists $args[0]{"keys"}
!ll&&!rl&&r
1731
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
1704
MC/DC66%2/3
@args == 1 and ref $args[0] eq "HASH" and not exists $args[0]{"keys"}
@args == 1 ref $args[0] eq "HASH" not exists $args[0]{"keys"}
Truth table75%3/4
A and B and not(C)
A= @args == 1B= ref $args[0] eq "HASH"C= not exists $args[0]{"keys"}
ABCresult
0XX0
10X0
1100
1111
66 1 my @keys = sort { $a <=> $b } keys %{ $args[0] };
67 1 my @values = ();
68 1 foreach my $k (@keys) {
69 4 push(@values, $args[0]->{$k})
70 }
71 1 return { keys => \@keys, values => \@values }
72 } elsif(@args % 2 == 0) {
73 17 return { @args };
74 }
75  
76 3 return $args[0];
77 }
78  
79  
80 0 ▶sub add_pair {
Subroutine add_pair: not called CC=1 SCAR=6.9
Pod documented
81 0 my ($self, $key, $value) = @_;
82  
83 0 $self->add_to_keys($key);
84 0 $self->add_to_values($value);
85 }
86  
87  
88 5 ▶sub get_value_for_key {
Subroutine get_value_for_key: called CC=4 SCAR=13.9
Pod documented
89 5 my ($self, $key) = @_;
90  
91 5 for(0..$self->key_count) {
92 11 my $ikey = $self->keys->[$_];
93 11 ▶ return $self->values->[$_] if defined($ikey) && $ikey == $key;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ikey and $ikey == $key 4 7 11
Condition100%3/3
defined $ikey and $ikey == $key
!ll&&!rl&&r
164
MC/DC100%2/2
defined $ikey and $ikey == $key
defined $ikey $ikey == $key
Truth table100%3/3
A and B
A= defined $ikeyB= $ikey == $key
ABresult
0X0
100
111
94 }
95  
96 # We found nothing, return undef
97 1 return undef;
98 }
99  
100 6 ▶sub prepare {
Subroutine prepare: called CC=2 SCAR=6.9
Pod undocumented
101 6 my ($self) = @_;
102  
103 6 ▶ if($self->key_count != $self->value_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->key_count != $self->value_count) 1 5 6
104 1 die('Series key/value counts dont match: '.$self->key_count.' != '.$self->value_count.'.');
105 }
106  
107 5 return 1;
108 }
109  
110 11 __PACKAGE__->meta->make_immutable;
111  
112 11 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 11 1;
115  
116 __END__
« Clicker/Decoration/Plot.pm ↑ Summary Clicker/Axis/DivisionType/Exact.pm »