line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::JoinDict; |
2
|
14
|
|
|
14
|
|
167855
|
use strict; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
348
|
|
3
|
14
|
|
|
14
|
|
71
|
use warnings; |
|
14
|
|
|
|
|
1124
|
|
|
14
|
|
|
|
|
368
|
|
4
|
14
|
|
|
14
|
|
5091
|
use Gnuplot::Builder::PartiallyKeyedList; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
338
|
|
5
|
14
|
|
|
14
|
|
70
|
use Carp; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
884
|
|
6
|
14
|
|
|
14
|
|
73
|
use Exporter 5.57 qw(import); |
|
14
|
|
|
|
|
277
|
|
|
14
|
|
|
|
|
451
|
|
7
|
14
|
|
|
14
|
|
14063
|
use overload '""' => "to_string"; |
|
14
|
|
|
|
|
10018
|
|
|
14
|
|
|
|
|
162
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(joind); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
197
|
|
|
197
|
1
|
13241
|
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
|
100
|
|
|
|
2091
|
}, $class; |
19
|
197
|
50
|
66
|
|
|
1203
|
croak "filter must be a code-ref" if defined($self->{filter}) && ref($self->{filter}) ne "CODE"; |
20
|
197
|
50
|
66
|
|
|
627
|
croak "validator must be a code-ref" if defined($self->{validator}) && ref($self->{validator}) ne "CODE"; |
21
|
197
|
|
|
|
|
282
|
my $content = $args{content}; |
22
|
197
|
100
|
|
|
|
493
|
$content = [] if not defined $content; |
23
|
197
|
50
|
|
|
|
520
|
croak "content must be an array-ref" if ref($content) ne "ARRAY"; |
24
|
197
|
|
|
|
|
461
|
$self->_set_destructive(@$content); |
25
|
194
|
|
|
|
|
531
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub joind { |
29
|
2
|
|
|
2
|
1
|
382
|
my ($separator, @content) = @_; |
30
|
2
|
|
|
|
|
13
|
return __PACKAGE__->new( |
31
|
|
|
|
|
|
|
separator => $separator, |
32
|
|
|
|
|
|
|
content => \@content |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_all_keys { |
37
|
153
|
|
|
153
|
1
|
6972
|
return $_[0]->{pkl}->get_all_keys; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_all_values { |
41
|
|
|
|
|
|
|
return $_[0]->{pkl}->get_all_values |
42
|
52
|
|
|
52
|
1
|
175
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub to_string { |
45
|
240
|
|
|
240
|
1
|
10153
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
my @vals = defined($self->{filter}) |
47
|
|
|
|
|
|
|
? $self->{filter}->($self) |
48
|
240
|
100
|
|
|
|
966
|
: $self->{pkl}->get_all_values; |
49
|
239
|
|
|
|
|
1319
|
return join($self->{separator}, grep { defined($_) } @vals); |
|
4396
|
|
|
|
|
8196
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get { |
53
|
22
|
|
|
22
|
1
|
1678
|
my ($self, $key) = @_; |
54
|
22
|
50
|
|
|
|
64
|
return undef if not defined $key; |
55
|
22
|
|
|
|
|
82
|
return $self->{pkl}->get($key); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub set { |
59
|
143
|
|
|
143
|
1
|
6851
|
my ($self, @content) = @_; |
60
|
143
|
|
|
|
|
324
|
return $self->clone->_set_destructive(@content); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub set_all { |
64
|
6
|
|
|
6
|
1
|
3829
|
my ($self, $value) = @_; |
65
|
6
|
|
|
|
|
25
|
return $self->set(map { $_ => $value } $self->{pkl}->get_all_keys); |
|
13
|
|
|
|
|
36
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _validate { |
69
|
344
|
|
|
344
|
|
550
|
my ($self) = @_; |
70
|
344
|
100
|
|
|
|
1107
|
$self->{validator}->($self) if defined $self->{validator}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _set_destructive { |
74
|
340
|
|
|
340
|
|
726
|
my ($self, @content) = @_; |
75
|
340
|
100
|
|
|
|
1280
|
croak "odd number of elements in content" if @content % 2 != 0; |
76
|
338
|
|
|
|
|
1056
|
foreach my $i (0 .. (@content / 2 - 1)) { |
77
|
703
|
|
|
|
|
1636
|
my ($key, $value) = @content[2*$i, 2*$i+1]; |
78
|
703
|
100
|
|
|
|
1718
|
croak "undefined key in content" if not defined $key; |
79
|
701
|
|
|
|
|
2099
|
$self->{pkl}->set($key, $value); |
80
|
|
|
|
|
|
|
} |
81
|
336
|
|
|
|
|
726
|
$self->_validate(); |
82
|
331
|
|
|
|
|
990
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub clone { |
86
|
154
|
|
|
154
|
1
|
3023
|
my ($self) = @_; |
87
|
154
|
|
|
|
|
619
|
my $clone = ref($self)->new(separator => $self->{separator}, filter => $self->{filter}); |
88
|
154
|
|
|
|
|
566
|
$clone->{pkl}->merge($self->{pkl}); |
89
|
154
|
|
|
|
|
664
|
$clone->{validator} = $self->{validator}; |
90
|
154
|
|
|
|
|
421
|
return $clone; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub delete { |
94
|
8
|
|
|
8
|
1
|
4812
|
my ($self, @keys) = @_; |
95
|
8
|
|
|
|
|
23
|
my $clone = $self->clone; |
96
|
8
|
|
|
|
|
18
|
$clone->{pkl}->delete($_) foreach grep { defined($_) } @keys; |
|
11
|
|
|
|
|
55
|
|
97
|
8
|
|
|
|
|
30
|
$clone->_validate(); |
98
|
8
|
|
|
|
|
23
|
return $clone; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub separator { |
102
|
14
|
|
|
14
|
1
|
5807
|
my ($self) = @_; |
103
|
14
|
|
|
|
|
68
|
return $self->{separator}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |