blib/lib/Gnuplot/Builder/JoinDict.pm

filter: Statementstmt 95.7% 68 / 71 Branchbran 80.0% 16 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 95.0% 19 / 20 Podpod 91.6% 11 / 12 totaltotal 88.7% 118 / 133 SCAR 27.2
CC
15
Cov
91%
new
8.5
_set_destructive
4.0
get
2.0
CRAP 15.2
« blib/lib/Gnuplot/Builder/PartiallyKeyedList.pm ↑ Summary blib/lib/Gnuplot/Builder/Dataset.pm »
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 sub new {
12 197 ▶ my ($class, %args) = @_;
Subroutine new: called CC=8 SCAR=21.4
Pod documented
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
BranchTrueFalseTotal
defined $args{'separator'} ? : 187 10 197
19 197 ▶ croak "filter must be a code-ref" if defined($self->{filter}) && ref($self->{filter}) ne "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"filter"} and ref $self->{"filter"} ne "CODE" 0 197 197
Condition66%2/3
defined $self->{"filter"} and ref $self->{"filter"} ne "CODE"
!ll&&!rl&&r
163340
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"
ABresult
0X0
100
111
20 197 ▶ croak "validator must be a code-ref" if defined($self->{validator}) && ref($self->{validator}) ne "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"validator"} and ref $self->{"validator"} ne "CODE" 0 197 197
Condition66%2/3
defined $self->{"validator"} and ref $self->{"validator"} ne "CODE"
!ll&&!rl&&r
18890
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"
ABresult
0X0
100
111
21 197 my $content = $args{content};
22 197 ▶ $content = [] if not defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 163 34 197
23 197 ▶ croak "content must be an array-ref" if ref($content) ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $content ne "ARRAY" 0 197 197
24 197 $self->_set_destructive(@$content);
25 194 return $self;
26 }
27  
28 sub joind {
29 2 ▶ my ($separator, @content) = @_;
Subroutine joind: called CC=1 SCAR=0.0
Pod documented
30 2 return __PACKAGE__->new(
31 separator => $separator,
32 content => \@content
33 );
34 }
35  
36 sub get_all_keys {
37 153 ▶ return $_[0]->{pkl}->get_all_keys;
Subroutine get_all_keys: called CC=1 SCAR=0.0
Pod documented
38 }
39  
40 sub get_all_values {
41 return $_[0]->{pkl}->get_all_values
42 52 ▶}
Subroutine get_all_values: called CC=1 SCAR=0.0
Pod documented
43  
44 sub to_string {
45 240 ▶ my ($self) = @_;
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
46 my @vals = defined($self->{filter})
47 ? $self->{filter}->($self)
48 240 ▶ : $self->{pkl}->get_all_values;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'filter'} ? : 29 211 240
49 239 return join($self->{separator}, grep { defined($_) } @vals);
50 }
51  
52 sub get {
53 22 ▶ my ($self, $key) = @_;
Subroutine get: called CC=2 SCAR=7.1
Pod documented
54 22 ▶ return undef if not defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 22 22
55 22 return $self->{pkl}->get($key);
56 }
57  
58 sub set {
59 143 ▶ my ($self, @content) = @_;
Subroutine set: called CC=1 SCAR=0.0
Pod documented
60 143 return $self->clone->_set_destructive(@content);
61 }
62  
63 sub set_all {
64 6 ▶ my ($self, $value) = @_;
Subroutine set_all: called CC=1 SCAR=0.0
Pod documented
65 6 return $self->set(map { $_ => $value } $self->{pkl}->get_all_keys);
66 }
67  
68 sub _validate {
69 344 ▶ my ($self) = @_;
Subroutine _validate: called CC=2 SCAR=6.9
70 344 ▶ $self->{validator}->($self) if defined $self->{validator};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"validator"} 129 215 344
71 }
72  
73 sub _set_destructive {
74 340 ▶ my ($self, @content) = @_;
Subroutine _set_destructive: called CC=4 SCAR=13.9
75 340 ▶ croak "odd number of elements in content" if @content % 2 != 0;
Branch: 1 branch
BranchTrueFalseTotal
if @content % 2 != 0 2 338 340
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
BranchTrueFalseTotal
unless defined $key 2 701 703
79 701 $self->{pkl}->set($key, $value);
80 }
81 336 $self->_validate();
82 331 return $self;
83 }
84  
85 sub clone {
86 154 ▶ my ($self) = @_;
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
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 sub delete {
94 8 ▶ my ($self, @keys) = @_;
Subroutine delete: called CC=2 SCAR=6.9
Pod documented
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 sub separator {
102 14 ▶ my ($self) = @_;
Subroutine separator: called CC=1 SCAR=0.0
Pod documented
103 14 return $self->{separator};
104 }
105  
106 sub Lens {
107 0 ▶ my ($self, $key) = @_;
Subroutine Lens: not called CC=1 SCAR=6.9
Pod undocumented
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__
« blib/lib/Gnuplot/Builder/PartiallyKeyedList.pm ↑ Summary blib/lib/Gnuplot/Builder/Dataset.pm »