line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::JoinDict; |
2
|
14
|
|
|
14
|
|
172941
|
use strict; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
370
|
|
3
|
14
|
|
|
14
|
|
75
|
use warnings; |
|
14
|
|
|
|
|
1201
|
|
|
14
|
|
|
|
|
371
|
|
4
|
14
|
|
|
14
|
|
5053
|
use Gnuplot::Builder::PartiallyKeyedList; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
429
|
|
5
|
14
|
|
|
14
|
|
72
|
use Carp; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
871
|
|
6
|
14
|
|
|
14
|
|
76
|
use Exporter 5.57 qw(import); |
|
14
|
|
|
|
|
284
|
|
|
14
|
|
|
|
|
459
|
|
7
|
14
|
|
|
14
|
|
14428
|
use overload '""' => "to_string"; |
|
14
|
|
|
|
|
10428
|
|
|
14
|
|
|
|
|
164
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(joind); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
197
|
|
|
197
|
1
|
18161
|
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
|
|
|
|
2242
|
}, $class; |
19
|
197
|
50
|
66
|
|
|
1289
|
croak "filter must be a code-ref" if defined($self->{filter}) && ref($self->{filter}) ne "CODE"; |
20
|
197
|
50
|
66
|
|
|
611
|
croak "validator must be a code-ref" if defined($self->{validator}) && ref($self->{validator}) ne "CODE"; |
21
|
197
|
|
|
|
|
296
|
my $content = $args{content}; |
22
|
197
|
100
|
|
|
|
509
|
$content = [] if not defined $content; |
23
|
197
|
50
|
|
|
|
550
|
croak "content must be an array-ref" if ref($content) ne "ARRAY"; |
24
|
197
|
|
|
|
|
485
|
$self->_set_destructive(@$content); |
25
|
194
|
|
|
|
|
534
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub joind { |
29
|
2
|
|
|
2
|
1
|
405
|
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
|
10847
|
return $_[0]->{pkl}->get_all_keys; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_all_values { |
41
|
|
|
|
|
|
|
return $_[0]->{pkl}->get_all_values |
42
|
52
|
|
|
52
|
1
|
247
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub to_string { |
45
|
240
|
|
|
240
|
1
|
15393
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
my @vals = defined($self->{filter}) |
47
|
|
|
|
|
|
|
? $self->{filter}->($self) |
48
|
240
|
100
|
|
|
|
1093
|
: $self->{pkl}->get_all_values; |
49
|
239
|
|
|
|
|
1539
|
return join($self->{separator}, grep { defined($_) } @vals); |
|
4396
|
|
|
|
|
8220
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get { |
53
|
22
|
|
|
22
|
1
|
2389
|
my ($self, $key) = @_; |
54
|
22
|
50
|
|
|
|
67
|
return undef if not defined $key; |
55
|
22
|
|
|
|
|
88
|
return $self->{pkl}->get($key); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub set { |
59
|
143
|
|
|
143
|
1
|
7596
|
my ($self, @content) = @_; |
60
|
143
|
|
|
|
|
323
|
return $self->clone->_set_destructive(@content); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub set_all { |
64
|
6
|
|
|
6
|
1
|
4570
|
my ($self, $value) = @_; |
65
|
6
|
|
|
|
|
25
|
return $self->set(map { $_ => $value } $self->{pkl}->get_all_keys); |
|
13
|
|
|
|
|
41
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _validate { |
69
|
344
|
|
|
344
|
|
559
|
my ($self) = @_; |
70
|
344
|
100
|
|
|
|
1154
|
$self->{validator}->($self) if defined $self->{validator}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _set_destructive { |
74
|
340
|
|
|
340
|
|
762
|
my ($self, @content) = @_; |
75
|
340
|
100
|
|
|
|
1163
|
croak "odd number of elements in content" if @content % 2 != 0; |
76
|
338
|
|
|
|
|
1058
|
foreach my $i (0 .. (@content / 2 - 1)) { |
77
|
703
|
|
|
|
|
1592
|
my ($key, $value) = @content[2*$i, 2*$i+1]; |
78
|
703
|
100
|
|
|
|
1677
|
croak "undefined key in content" if not defined $key; |
79
|
701
|
|
|
|
|
2125
|
$self->{pkl}->set($key, $value); |
80
|
|
|
|
|
|
|
} |
81
|
336
|
|
|
|
|
795
|
$self->_validate(); |
82
|
331
|
|
|
|
|
1036
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub clone { |
86
|
154
|
|
|
154
|
1
|
3051
|
my ($self) = @_; |
87
|
154
|
|
|
|
|
693
|
my $clone = ref($self)->new(separator => $self->{separator}, filter => $self->{filter}); |
88
|
154
|
|
|
|
|
651
|
$clone->{pkl}->merge($self->{pkl}); |
89
|
154
|
|
|
|
|
705
|
$clone->{validator} = $self->{validator}; |
90
|
154
|
|
|
|
|
415
|
return $clone; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub delete { |
94
|
8
|
|
|
8
|
1
|
5529
|
my ($self, @keys) = @_; |
95
|
8
|
|
|
|
|
30
|
my $clone = $self->clone; |
96
|
8
|
|
|
|
|
23
|
$clone->{pkl}->delete($_) foreach grep { defined($_) } @keys; |
|
11
|
|
|
|
|
72
|
|
97
|
8
|
|
|
|
|
40
|
$clone->_validate(); |
98
|
8
|
|
|
|
|
29
|
return $clone; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub separator { |
102
|
14
|
|
|
14
|
1
|
9478
|
my ($self) = @_; |
103
|
14
|
|
|
|
|
106
|
return $self->{separator}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |