line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnuplot::Builder::Dataset; |
2
|
26
|
|
|
26
|
|
428649
|
use strict; |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
655
|
|
3
|
26
|
|
|
26
|
|
187
|
use warnings; |
|
26
|
|
|
|
|
49
|
|
|
26
|
|
|
|
|
676
|
|
4
|
26
|
|
|
26
|
|
10477
|
use Gnuplot::Builder::PrototypedData; |
|
26
|
|
|
|
|
57
|
|
|
26
|
|
|
|
|
837
|
|
5
|
26
|
|
|
26
|
|
150
|
use Scalar::Util qw(weaken blessed); |
|
26
|
|
|
|
|
43
|
|
|
26
|
|
|
|
|
1560
|
|
6
|
26
|
|
|
26
|
|
130
|
use Carp; |
|
26
|
|
|
|
|
41
|
|
|
26
|
|
|
|
|
1383
|
|
7
|
26
|
|
|
26
|
|
28688
|
use overload '""' => 'to_string'; |
|
26
|
|
|
|
|
19984
|
|
|
26
|
|
|
|
|
148
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
124
|
|
|
124
|
1
|
27745
|
my ($class, $source, @set_option_args) = @_; |
11
|
124
|
|
|
|
|
475
|
my $self = bless { |
12
|
|
|
|
|
|
|
pdata => undef, |
13
|
|
|
|
|
|
|
pdata_join => undef, ## deprecated. should be removed in the future. |
14
|
|
|
|
|
|
|
parent => undef, |
15
|
|
|
|
|
|
|
}, $class; |
16
|
124
|
|
|
|
|
375
|
$self->_init_pdata(); |
17
|
124
|
100
|
|
|
|
328
|
if(defined $source) { |
18
|
33
|
|
|
|
|
87
|
$self->set_source($source); |
19
|
|
|
|
|
|
|
} |
20
|
124
|
100
|
|
|
|
345
|
if(@set_option_args) { |
21
|
7
|
|
|
|
|
25
|
$self->set_option(@set_option_args); |
22
|
|
|
|
|
|
|
} |
23
|
124
|
|
|
|
|
362
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new_file { |
27
|
18
|
|
|
18
|
1
|
4131
|
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
|
1305
|
my ($class, $data_provider, @set_option_args) = @_; |
33
|
10
|
|
|
|
|
24
|
return $class->new->set_file('-')->set_data($data_provider)->set_option(@set_option_args); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init_pdata { |
37
|
124
|
|
|
124
|
|
192
|
my ($self) = @_; |
38
|
124
|
|
|
|
|
343
|
weaken $self; |
39
|
|
|
|
|
|
|
$self->{pdata} = Gnuplot::Builder::PrototypedData->new( |
40
|
|
|
|
|
|
|
entry_evaluator => sub { |
41
|
49
|
|
|
49
|
|
89
|
my ($key, $coderef) = @_; |
42
|
49
|
|
|
|
|
111
|
return $coderef->($self, $key); |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
attribute_evaluator => { source => sub { |
45
|
11
|
|
|
11
|
|
21
|
my ($key, $coderef) = @_; |
46
|
11
|
|
|
|
|
29
|
return $coderef->($self); |
47
|
|
|
|
|
|
|
} }, |
48
|
124
|
|
|
|
|
1082
|
); |
49
|
124
|
|
|
|
|
399
|
$self->{pdata_join} = Gnuplot::Builder::PrototypedData->new(); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub to_string { |
53
|
119
|
|
|
119
|
1
|
3530
|
my ($self) = @_; |
54
|
119
|
|
|
|
|
213
|
my @words = (); |
55
|
119
|
|
|
|
|
271
|
push @words, $self->get_source; |
56
|
|
|
|
|
|
|
$self->{pdata}->each_resolved_entry(sub { |
57
|
198
|
|
|
198
|
|
1332
|
my ($name, $values_arrayref) = @_; |
58
|
198
|
|
|
|
|
354
|
my @values = grep { defined($_) } @$values_arrayref; |
|
259
|
|
|
|
|
664
|
|
59
|
198
|
100
|
|
|
|
546
|
return if !@values; |
60
|
170
|
|
|
|
|
552
|
my $join = $self->{pdata_join}->get_resolved_attribute($name); |
61
|
170
|
100
|
|
|
|
355
|
if(defined $join) { |
62
|
22
|
|
|
|
|
156
|
push @words, $name, join($join, @values); |
63
|
|
|
|
|
|
|
}else { |
64
|
148
|
|
|
|
|
930
|
push @words, $name, @values; |
65
|
|
|
|
|
|
|
} |
66
|
119
|
|
|
|
|
773
|
}); |
67
|
119
|
100
|
|
|
|
876
|
return join " ", grep { defined($_) && "$_" ne "" } @words; |
|
492
|
|
|
|
|
2546
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
*params_string = *to_string; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub set_source { |
73
|
42
|
|
|
42
|
1
|
96
|
my ($self, $source) = @_; |
74
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
75
|
42
|
|
|
|
|
158
|
key => "source", value => $source |
76
|
|
|
|
|
|
|
); |
77
|
42
|
|
|
|
|
82
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub setq_source { |
81
|
36
|
|
|
36
|
1
|
108
|
my ($self, $source) = @_; |
82
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
83
|
36
|
|
|
|
|
152
|
key => "source", value => $source, quote => 1, |
84
|
|
|
|
|
|
|
); |
85
|
36
|
|
|
|
|
124
|
return $self; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
*set_file = *setq_source; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_source { |
91
|
138
|
|
|
138
|
1
|
848
|
my ($self) = @_; |
92
|
138
|
|
|
|
|
1276
|
return $self->{pdata}->get_resolved_attribute("source"); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub delete_source { |
96
|
5
|
|
|
5
|
1
|
11
|
my ($self) = @_; |
97
|
5
|
|
|
|
|
19
|
$self->{pdata}->delete_attribute("source"); |
98
|
5
|
|
|
|
|
19
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub set_option { |
102
|
93
|
|
|
93
|
1
|
346
|
my ($self, @options) = @_; |
103
|
|
|
|
|
|
|
$self->{pdata}->set_entry( |
104
|
93
|
|
|
|
|
341
|
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
|
176
|
my ($self, @options) = @_; |
114
|
|
|
|
|
|
|
$self->{pdata}->set_entry( |
115
|
25
|
|
|
|
|
94
|
entries => \@options, |
116
|
|
|
|
|
|
|
quote => 1, |
117
|
|
|
|
|
|
|
); |
118
|
25
|
|
|
|
|
167
|
return $self; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
*setq = *setq_option; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub unset { |
124
|
2
|
|
|
2
|
1
|
9
|
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
|
4898
|
my ($self, $name) = @_; |
130
|
92
|
|
|
|
|
312
|
return $self->{pdata}->get_resolved_entry($name); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub delete_option { |
134
|
2
|
|
|
2
|
1
|
5
|
my ($self, @names) = @_; |
135
|
2
|
|
|
|
|
5
|
foreach my $name (@names) { |
136
|
2
|
|
|
|
|
8
|
$self->{pdata}->delete_entry($name); |
137
|
|
|
|
|
|
|
} |
138
|
2
|
|
|
|
|
14
|
return $self; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub set_parent { |
142
|
13
|
|
|
13
|
1
|
1278
|
my ($self, $parent) = @_; |
143
|
13
|
50
|
|
|
|
46
|
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
|
|
|
189
|
if(!blessed($parent) || !$parent->isa("Gnuplot::Builder::Dataset")) { |
150
|
0
|
|
|
|
|
0
|
croak "parent must be a Gnuplot::Builder::Dataset"; |
151
|
|
|
|
|
|
|
} |
152
|
13
|
|
|
|
|
31
|
$self->{parent} = $parent; |
153
|
13
|
|
|
|
|
61
|
$self->{pdata}->set_parent($parent->{pdata}); |
154
|
13
|
|
|
|
|
43
|
$self->{pdata_join}->set_parent($parent->{pdata_join}); |
155
|
13
|
|
|
|
|
36
|
return $self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
5
|
|
|
5
|
1
|
32
|
sub get_parent { return $_[0]->{parent} } |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
*parent = *get_parent; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub new_child { |
163
|
11
|
|
|
11
|
1
|
46
|
my ($self) = @_; |
164
|
11
|
|
|
|
|
34
|
return Gnuplot::Builder::Dataset->new->set_parent($self); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub set_data { |
168
|
24
|
|
|
24
|
1
|
2186
|
my ($self, $data_provider) = @_; |
169
|
|
|
|
|
|
|
$self->{pdata}->set_attribute( |
170
|
24
|
|
|
|
|
94
|
key => "data", value => $data_provider |
171
|
|
|
|
|
|
|
); |
172
|
24
|
|
|
|
|
67
|
return $self; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub write_data_to { |
176
|
41
|
|
|
41
|
1
|
1395
|
my ($self, $writer) = @_; |
177
|
41
|
|
|
|
|
141
|
my $data_provider = $self->{pdata}->get_resolved_attribute("data"); |
178
|
41
|
100
|
|
|
|
128
|
return $self if not defined $data_provider; |
179
|
24
|
100
|
|
|
|
61
|
if(ref($data_provider) eq "CODE") { |
180
|
10
|
|
|
|
|
31
|
$data_provider->($self, $writer); |
181
|
|
|
|
|
|
|
}else { |
182
|
14
|
|
|
|
|
45
|
$writer->($data_provider); |
183
|
|
|
|
|
|
|
} |
184
|
24
|
|
|
|
|
775
|
return $self; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub delete_data { |
188
|
6
|
|
|
6
|
1
|
3939
|
my ($self) = @_; |
189
|
6
|
|
|
|
|
24
|
$self->{pdata}->delete_attribute("data"); |
190
|
6
|
|
|
|
|
27
|
return $self; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _deprecated { |
194
|
26
|
|
|
26
|
|
33
|
my ($msg) = @_; |
195
|
26
|
|
|
|
|
146
|
my $method = (caller(1))[3]; |
196
|
26
|
|
|
|
|
2719
|
carp "$method is deprecated. $msg"; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub set_join { |
200
|
24
|
|
|
24
|
0
|
120
|
my ($self, %joins) = @_; |
201
|
24
|
|
|
|
|
47
|
_deprecated("Use Gnuplot::Builder::JoinDict."); |
202
|
24
|
|
|
|
|
1296
|
foreach my $name (keys %joins) { |
203
|
|
|
|
|
|
|
$self->{pdata_join}->set_attribute( |
204
|
28
|
|
|
|
|
108
|
key => $name, value => $joins{$name}, quote => 0 |
205
|
|
|
|
|
|
|
); |
206
|
|
|
|
|
|
|
} |
207
|
24
|
|
|
|
|
97
|
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
|
|
|
|
|
94
|
foreach my $name (@names) { |
214
|
2
|
|
|
|
|
10
|
$self->{pdata_join}->delete_attribute($name); |
215
|
|
|
|
|
|
|
} |
216
|
2
|
|
|
|
|
9
|
return $self; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
__END__ |