line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::Dataset; |
2
|
26
|
|
|
26
|
|
411464
|
use strict; |
|
26
|
|
|
|
|
55
|
|
|
26
|
|
|
|
|
774
|
|
3
|
26
|
|
|
26
|
|
129
|
use warnings; |
|
26
|
|
|
|
|
43
|
|
|
26
|
|
|
|
|
684
|
|
4
|
26
|
|
|
26
|
|
10745
|
use Gnuplot::Builder::PrototypedData; |
|
26
|
|
|
|
|
127
|
|
|
26
|
|
|
|
|
798
|
|
5
|
26
|
|
|
26
|
|
144
|
use Scalar::Util qw(weaken blessed); |
|
26
|
|
|
|
|
43
|
|
|
26
|
|
|
|
|
1532
|
|
6
|
26
|
|
|
26
|
|
132
|
use Carp; |
|
26
|
|
|
|
|
49
|
|
|
26
|
|
|
|
|
1541
|
|
7
|
26
|
|
|
26
|
|
28738
|
use overload '""' => 'to_string'; |
|
26
|
|
|
|
|
20473
|
|
|
26
|
|
|
|
|
161
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
124
|
|
|
124
|
1
|
30671
|
my ($class, $source, @set_option_args) = @_; |
11
|
124
|
|
|
|
|
488
|
my $self = bless { |
12
|
|
|
|
|
|
|
pdata => undef, |
13
|
|
|
|
|
|
|
pdata_join => undef, ## deprecated. should be removed in the future. |
14
|
|
|
|
|
|
|
parent => undef, |
15
|
|
|
|
|
|
|
}, $class; |
16
|
124
|
|
|
|
|
374
|
$self->_init_pdata(); |
17
|
124
|
100
|
|
|
|
319
|
if(defined $source) { |
18
|
33
|
|
|
|
|
79
|
$self->set_source($source); |
19
|
|
|
|
|
|
|
} |
20
|
124
|
100
|
|
|
|
329
|
if(@set_option_args) { |
21
|
7
|
|
|
|
|
25
|
$self->set_option(@set_option_args); |
22
|
|
|
|
|
|
|
} |
23
|
124
|
|
|
|
|
373
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new_file { |
27
|
18
|
|
|
18
|
1
|
4477
|
my ($class, $filename, @set_option_args) = @_; |
28
|
18
|
|
|
|
|
61
|
return $class->new->set_file($filename)->set_option(@set_option_args); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new_data { |
32
|
10
|
|
|
10
|
1
|
1295
|
my ($class, $data_provider, @set_option_args) = @_; |
33
|
10
|
|
|
|
|
32
|
return $class->new->set_file('-')->set_data($data_provider)->set_option(@set_option_args); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init_pdata { |
37
|
124
|
|
|
124
|
|
218
|
my ($self) = @_; |
38
|
124
|
|
|
|
|
362
|
weaken $self; |
39
|
|
|
|
|
|
|
$self->{pdata} = Gnuplot::Builder::PrototypedData->new( |
40
|
|
|
|
|
|
|
entry_evaluator => sub { |
41
|
49
|
|
|
49
|
|
75
|
my ($key, $coderef) = @_; |
42
|
49
|
|
|
|
|
121
|
return $coderef->($self, $key); |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
attribute_evaluator => { source => sub { |
45
|
11
|
|
|
11
|
|
20
|
my ($key, $coderef) = @_; |
46
|
11
|
|
|
|
|
27
|
return $coderef->($self); |
47
|
|
|
|
|
|
|
} }, |
48
|
124
|
|
|
|
|
1104
|
); |
49
|
124
|
|
|
|
|
397
|
$self->{pdata_join} = Gnuplot::Builder::PrototypedData->new(); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub to_string { |
53
|
119
|
|
|
119
|
1
|
3305
|
my ($self) = @_; |
54
|
119
|
|
|
|
|
201
|
my @words = (); |
55
|
119
|
|
|
|
|
276
|
push @words, $self->get_source; |
56
|
|
|
|
|
|
|
$self->{pdata}->each_resolved_entry(sub { |
57
|
198
|
|
|
198
|
|
1280
|
my ($name, $values_arrayref) = @_; |
58
|
198
|
|
|
|
|
332
|
my @values = grep { defined($_) } @$values_arrayref; |
|
259
|
|
|
|
|
684
|
|
59
|
198
|
100
|
|
|
|
563
|
return if !@values; |
60
|
170
|
|
|
|
|
547
|
my $join = $self->{pdata_join}->get_resolved_attribute($name); |
61
|
170
|
100
|
|
|
|
336
|
if(defined $join) { |
62
|
22
|
|
|
|
|
148
|
push @words, $name, join($join, @values); |
63
|
|
|
|
|
|
|
}else { |
64
|
148
|
|
|
|
|
947
|
push @words, $name, @values; |
65
|
|
|
|
|
|
|
} |
66
|
119
|
|
|
|
|
765
|
}); |
67
|
119
|
100
|
|
|
|
895
|
return join " ", grep { defined($_) && "$_" ne "" } @words; |
|
492
|
|
|
|
|
2595
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
*params_string = *to_string; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub set_source { |
73
|
42
|
|
|
42
|
1
|
114
|
my ($self, $source) = @_; |
74
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
75
|
42
|
|
|
|
|
153
|
key => "source", value => $source |
76
|
|
|
|
|
|
|
); |
77
|
42
|
|
|
|
|
86
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub setq_source { |
81
|
36
|
|
|
36
|
1
|
96
|
my ($self, $source) = @_; |
82
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
83
|
36
|
|
|
|
|
154
|
key => "source", value => $source, quote => 1, |
84
|
|
|
|
|
|
|
); |
85
|
36
|
|
|
|
|
114
|
return $self; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
*set_file = *setq_source; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_source { |
91
|
138
|
|
|
138
|
1
|
962
|
my ($self) = @_; |
92
|
138
|
|
|
|
|
495
|
return $self->{pdata}->get_resolved_attribute("source"); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub delete_source { |
96
|
5
|
|
|
5
|
1
|
10
|
my ($self) = @_; |
97
|
5
|
|
|
|
|
19
|
$self->{pdata}->delete_attribute("source"); |
98
|
5
|
|
|
|
|
21
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub set_option { |
102
|
93
|
|
|
93
|
1
|
389
|
my ($self, @options) = @_; |
103
|
|
|
|
|
|
|
$self->{pdata}->set_entry( |
104
|
93
|
|
|
|
|
370
|
entries => \@options, |
105
|
|
|
|
|
|
|
quote => 0, |
106
|
|
|
|
|
|
|
); |
107
|
93
|
|
|
|
|
614
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
*set = *set_option; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub setq_option { |
113
|
25
|
|
|
25
|
1
|
126
|
my ($self, @options) = @_; |
114
|
|
|
|
|
|
|
$self->{pdata}->set_entry( |
115
|
25
|
|
|
|
|
89
|
entries => \@options, |
116
|
|
|
|
|
|
|
quote => 1, |
117
|
|
|
|
|
|
|
); |
118
|
25
|
|
|
|
|
171
|
return $self; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
*setq = *setq_option; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub unset { |
124
|
2
|
|
|
2
|
1
|
10
|
my ($self, @opt_names) = @_; |
125
|
2
|
|
|
|
|
5
|
return $self->set_option(map {$_ => undef} @opt_names); |
|
3
|
|
|
|
|
8
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub get_option { |
129
|
92
|
|
|
92
|
1
|
4290
|
my ($self, $name) = @_; |
130
|
92
|
|
|
|
|
317
|
return $self->{pdata}->get_resolved_entry($name); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub delete_option { |
134
|
2
|
|
|
2
|
1
|
7
|
my ($self, @names) = @_; |
135
|
2
|
|
|
|
|
7
|
foreach my $name (@names) { |
136
|
2
|
|
|
|
|
11
|
$self->{pdata}->delete_entry($name); |
137
|
|
|
|
|
|
|
} |
138
|
2
|
|
|
|
|
21
|
return $self; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub set_parent { |
142
|
13
|
|
|
13
|
1
|
1335
|
my ($self, $parent) = @_; |
143
|
13
|
50
|
|
|
|
42
|
if(!defined($parent)) { |
144
|
0
|
|
|
|
|
0
|
$self->{parent} = undef; |
145
|
0
|
|
|
|
|
0
|
$self->{pdata}->set_parent(undef); |
146
|
0
|
|
|
|
|
0
|
$self->{pdata_join}->set_parent(undef); |
147
|
0
|
|
|
|
|
0
|
return $self; |
148
|
|
|
|
|
|
|
} |
149
|
13
|
50
|
33
|
|
|
179
|
if(!blessed($parent) || !$parent->isa("Gnuplot::Builder::Dataset")) { |
150
|
0
|
|
|
|
|
0
|
croak "parent must be a Gnuplot::Builder::Dataset"; |
151
|
|
|
|
|
|
|
} |
152
|
13
|
|
|
|
|
40
|
$self->{parent} = $parent; |
153
|
13
|
|
|
|
|
67
|
$self->{pdata}->set_parent($parent->{pdata}); |
154
|
13
|
|
|
|
|
42
|
$self->{pdata_join}->set_parent($parent->{pdata_join}); |
155
|
13
|
|
|
|
|
37
|
return $self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
5
|
|
|
5
|
1
|
35
|
sub get_parent { return $_[0]->{parent} } |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
*parent = *get_parent; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub new_child { |
163
|
11
|
|
|
11
|
1
|
49
|
my ($self) = @_; |
164
|
11
|
|
|
|
|
33
|
return Gnuplot::Builder::Dataset->new->set_parent($self); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub set_data { |
168
|
24
|
|
|
24
|
1
|
2143
|
my ($self, $data_provider) = @_; |
169
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
170
|
24
|
|
|
|
|
104
|
key => "data", value => $data_provider |
171
|
|
|
|
|
|
|
); |
172
|
24
|
|
|
|
|
70
|
return $self; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub write_data_to { |
176
|
41
|
|
|
41
|
1
|
1485
|
my ($self, $writer) = @_; |
177
|
41
|
|
|
|
|
179
|
my $data_provider = $self->{pdata}->get_resolved_attribute("data"); |
178
|
41
|
100
|
|
|
|
135
|
return $self if not defined $data_provider; |
179
|
24
|
100
|
|
|
|
63
|
if(ref($data_provider) eq "CODE") { |
180
|
10
|
|
|
|
|
28
|
$data_provider->($self, $writer); |
181
|
|
|
|
|
|
|
}else { |
182
|
14
|
|
|
|
|
43
|
$writer->($data_provider); |
183
|
|
|
|
|
|
|
} |
184
|
24
|
|
|
|
|
1036
|
return $self; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub delete_data { |
188
|
6
|
|
|
6
|
1
|
5437
|
my ($self) = @_; |
189
|
6
|
|
|
|
|
25
|
$self->{pdata}->delete_attribute("data"); |
190
|
6
|
|
|
|
|
33
|
return $self; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _deprecated { |
194
|
26
|
|
|
26
|
|
36
|
my ($msg) = @_; |
195
|
26
|
|
|
|
|
141
|
my $method = (caller(1))[3]; |
196
|
26
|
|
|
|
|
2607
|
carp "$method is deprecated. $msg"; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub set_join { |
200
|
24
|
|
|
24
|
0
|
126
|
my ($self, %joins) = @_; |
201
|
24
|
|
|
|
|
50
|
_deprecated("Use Gnuplot::Builder::JoinDict."); |
202
|
24
|
|
|
|
|
1196
|
foreach my $name (keys %joins) { |
203
|
|
|
|
|
|
|
$self->{pdata_join}->set_attribute( |
204
|
28
|
|
|
|
|
103
|
key => $name, value => $joins{$name}, quote => 0 |
205
|
|
|
|
|
|
|
); |
206
|
|
|
|
|
|
|
} |
207
|
24
|
|
|
|
|
96
|
return $self; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub delete_join { |
211
|
2
|
|
|
2
|
0
|
5
|
my ($self, @names) = @_; |
212
|
2
|
|
|
|
|
5
|
_deprecated("Use Gnuplot::Builder::JoinDict."); |
213
|
2
|
|
|
|
|
83
|
foreach my $name (@names) { |
214
|
2
|
|
|
|
|
9
|
$self->{pdata_join}->delete_attribute($name); |
215
|
|
|
|
|
|
|
} |
216
|
2
|
|
|
|
|
11
|
return $self; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
__END__ |