| 1 | package Gnuplot::Builder::JoinDict; | ||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use Gnuplot::Builder::PartiallyKeyedList; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Exporter 5.57 qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use overload '""' => "to_string"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 17 | our @EXPORT_OK = qw(joind); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 197 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 197 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 13 | my $self = bless { | ||||||||||||||||||||||||||||
| 14 | separator => defined($args{separator}) ? $args{separator} : "", | ||||||||||||||||||||||||||||
| 15 | pkl => Gnuplot::Builder::PartiallyKeyedList->new, | ||||||||||||||||||||||||||||
| 16 | filter => $args{filter}, | ||||||||||||||||||||||||||||
| 17 | validator => $args{validator}, | ||||||||||||||||||||||||||||
| 18 | 197 | ▶ | }, $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 197 | ▶ | croak "filter must be a code-ref" if defined($self->{filter}) && ref($self->{filter}) ne "CODE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"filter"} and ref $self->{"filter"} ne "CODE"
MC/DC0%0/2
defined $self->{"filter"} and ref $self->{"filter"} ne "CODE"
defined $self->{"filter"}
ref $self->{"filter"} ne "CODE"
Truth table66%2/3
A and B
A= defined $self->{"filter"}B= ref $self->{"filter"} ne "CODE"
| |||||||||||||||||||||||||||||
| 20 | 197 | ▶ | croak "validator must be a code-ref" if defined($self->{validator}) && ref($self->{validator}) ne "CODE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"validator"} and ref $self->{"validator"} ne "CODE"
MC/DC0%0/2
defined $self->{"validator"} and ref $self->{"validator"} ne "CODE"
defined $self->{"validator"}
ref $self->{"validator"} ne "CODE"
Truth table66%2/3
A and B
A= defined $self->{"validator"}B= ref $self->{"validator"} ne "CODE"
| |||||||||||||||||||||||||||||
| 21 | 197 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 22 | 197 | ▶ | $content = [] if not defined $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 197 | ▶ | croak "content must be an array-ref" if ref($content) ne "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 197 | $self->_set_destructive(@$content); | |||||||||||||||||||||||||||
| 25 | 194 | return $self; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | sub joind { | ||||||||||||||||||||||||||
|
Subroutine
joind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 2 | my ($separator, @content) = @_; | |||||||||||||||||||||||||||
| 30 | 2 | return __PACKAGE__->new( | |||||||||||||||||||||||||||
| 31 | separator => $separator, | ||||||||||||||||||||||||||||
| 32 | content => \@content | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 153 | ▶ | sub get_all_keys { | ||||||||||||||||||||||||||
|
Subroutine
get_all_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 153 | return $_[0]->{pkl}->get_all_keys; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 52 | ▶ | sub get_all_values { | ||||||||||||||||||||||||||
|
Subroutine
get_all_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | return $_[0]->{pkl}->get_all_values | ||||||||||||||||||||||||||||
| 42 | 52 | } | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 240 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 240 | my ($self) = @_; | |||||||||||||||||||||||||||
| 46 | my @vals = defined($self->{filter}) | ||||||||||||||||||||||||||||
| 47 | ? $self->{filter}->($self) | ||||||||||||||||||||||||||||
| 48 | 240 | ▶ | : $self->{pkl}->get_all_values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 239 | return join($self->{separator}, grep { defined($_) } @vals); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 22 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 22 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 54 | 22 | ▶ | return undef if not defined $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 22 | return $self->{pkl}->get($key); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 143 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 143 | my ($self, @content) = @_; | |||||||||||||||||||||||||||
| 60 | 143 | return $self->clone->_set_destructive(@content); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6 | ▶ | sub set_all { | ||||||||||||||||||||||||||
|
Subroutine
set_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 6 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 65 | 6 | return $self->set(map { $_ => $value } $self->{pkl}->get_all_keys); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 344 | ▶ | sub _validate { | ||||||||||||||||||||||||||
|
Subroutine
_validate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 69 | 344 | my ($self) = @_; | |||||||||||||||||||||||||||
| 70 | 344 | ▶ | $self->{validator}->($self) if defined $self->{validator}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 340 | ▶ | sub _set_destructive { | ||||||||||||||||||||||||||
|
Subroutine
_set_destructive: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 74 | 340 | my ($self, @content) = @_; | |||||||||||||||||||||||||||
| 75 | 340 | ▶ | croak "odd number of elements in content" if @content % 2 != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 338 | foreach my $i (0 .. (@content / 2 - 1)) { | |||||||||||||||||||||||||||
| 77 | 703 | my ($key, $value) = @content[2*$i, 2*$i+1]; | |||||||||||||||||||||||||||
| 78 | 703 | ▶ | croak "undefined key in content" if not defined $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 701 | $self->{pkl}->set($key, $value); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 336 | $self->_validate(); | |||||||||||||||||||||||||||
| 82 | 331 | return $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 154 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 154 | my ($self) = @_; | |||||||||||||||||||||||||||
| 87 | 154 | my $clone = ref($self)->new(separator => $self->{separator}, filter => $self->{filter}); | |||||||||||||||||||||||||||
| 88 | 154 | $clone->{pkl}->merge($self->{pkl}); | |||||||||||||||||||||||||||
| 89 | 154 | $clone->{validator} = $self->{validator}; | |||||||||||||||||||||||||||
| 90 | 154 | return $clone; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 8 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 8 | my ($self, @keys) = @_; | |||||||||||||||||||||||||||
| 95 | 8 | my $clone = $self->clone; | |||||||||||||||||||||||||||
| 96 | 8 | $clone->{pkl}->delete($_) foreach grep { defined($_) } @keys; | |||||||||||||||||||||||||||
| 97 | 8 | $clone->_validate(); | |||||||||||||||||||||||||||
| 98 | 8 | return $clone; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 14 | ▶ | sub separator { | ||||||||||||||||||||||||||
|
Subroutine
separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||
| 103 | 14 | return $self->{separator}; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub Lens { | ||||||||||||||||||||||||||
|
Subroutine
Lens: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 108 | 0 | require Gnuplot::Builder::Lens; | |||||||||||||||||||||||||||
| 109 | 0 | return Gnuplot::Builder::Lens->new( | |||||||||||||||||||||||||||
| 110 | "get", "set", $key | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 17 | 1; | |||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||