| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
@args == 1 and ref $args[0] eq "HASH" and not exists $args[0]{"keys"}
@args == 1 and ref $args[0] eq "HASH"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $ikey and $ikey == $key
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||