Builder/Script.pm

filter: Statementstmt 95.9% 236 / 246 Branchbran 80.9% 68 / 84 Conditioncond 71.4% 15 / 21 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 98.1% 53 / 54 Podpod 96.3% 26 / 27 totaltotal 91.0% 406 / 446 CC 58 SCAR 12.4
CC
58
Cov
91%
run_with
9.5
_create_statement
6.0
__ANON__
6.0
CRAP 3.5
« Builder/Tap.pm ↑ Summary Builder/JoinDict.pm »
1 package Gnuplot::Builder::Script;
2 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use Gnuplot::Builder::PrototypedData;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use Gnuplot::Builder::Util qw(quote_gnuplot_str);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 37 ▶use Gnuplot::Builder::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 37 ▶use Scalar::Util qw(weaken blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 37 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 37 ▶use overload '""' => "to_string";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1177 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 1177 my ($class, @set_args) = @_;
13 1177 my $self = bless {
14 pdata => undef,
15 parent => undef,
16 };
17 1177 $self->_init_pdata();
18 1177 ▶ if(@set_args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set_args) 19 1158 1177
19 19 $self->set(@set_args);
20 }
21 1177 return $self;
22 }
23  
24 1177 ▶sub _init_pdata {
Subroutine _init_pdata: called CC=1 SCAR=0.0
25 1177 my ($self) = @_;
26 1177 weaken $self;
27 $self->{pdata} = Gnuplot::Builder::PrototypedData->new(
28 41 ▶ entry_evaluator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
29 41 my ($key, $value_code) = @_;
30 41 ▶ if(defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 38 3 41
31 38 return $value_code->($self, substr($key, 1));
32 }else {
33 3 return $value_code->($self);
34 }
35 }
36 1177 );
37 }
38  
39 15 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod documented
40 15 my ($self, @sentences) = @_;
41 15 foreach my $sentence (@sentences) {
42 20 $self->{pdata}->add_entry($sentence);
43 }
44 15 return $self;
45 }
46  
47 113 ▶sub _set_entry {
Subroutine _set_entry: called CC=1 SCAR=0.0
48 113 my ($self, $prefix, $quote, @pairs) = @_;
49 $self->{pdata}->set_entry(
50 113 entries => \@pairs,
51 key_prefix => $prefix,
52 quote => $quote,
53 );
54 113 return $self;
55 }
56  
57 77 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod documented
58 77 my ($self, @pairs) = @_;
59 77 return $self->_set_entry("o", 0, @pairs);
60 }
61  
62 37 *set_option = *set;
63  
64 21 ▶sub setq {
Subroutine setq: called CC=1 SCAR=0.0
Pod documented
65 21 my ($self, @pairs) = @_;
66 21 return $self->_set_entry("o", 1, @pairs);
67 }
68  
69 37 *setq_option = *setq;
70  
71 2 ▶sub unset {
Subroutine unset: called CC=1 SCAR=0.0
Pod documented
72 2 my ($self, @names) = @_;
73 2 return $self->set(map { $_ => undef } @names);
74 }
75  
76 75 ▶sub _get_entry {
Subroutine _get_entry: called CC=2 SCAR=7.1
77 75 my ($self, $prefix, $name) = @_;
78 75 ▶ croak "name cannot be undef" if not defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 75 75
79 75 return $self->{pdata}->get_resolved_entry("$prefix$name");
80 }
81  
82 62 ▶sub get_option {
Subroutine get_option: called CC=1 SCAR=0.0
Pod documented
83 62 my ($self, $name) = @_;
84 62 return $self->_get_entry("o", $name);
85 }
86  
87 9 ▶sub _delete_entry {
Subroutine _delete_entry: called CC=3 SCAR=11.1
88 9 my ($self, $prefix, @names) = @_;
89 9 foreach my $name (@names) {
90 11 ▶ croak "name cannot be undef" if not defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 11 11
91 11 $self->{pdata}->delete_entry("$prefix$name");
92 }
93 9 return $self;
94 }
95  
96 5 ▶sub delete_option {
Subroutine delete_option: called CC=1 SCAR=0.0
Pod documented
97 5 my ($self, @names) = @_;
98 5 return $self->_delete_entry("o", @names);
99 }
100  
101 262 ▶sub _create_statement {
Subroutine _create_statement: called CC=6 SCAR=18.0
102 262 my ($raw_key, $value) = @_;
103 262 ▶ return $value if !defined $raw_key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_key 45 217 262
104 217 my ($prefix, $name) = (substr($raw_key, 0, 1), substr($raw_key, 1));
105 217 my @words = ();
106 217 ▶ if($prefix eq "o") {
Branch: 2 branches
BranchTrueFalseTotal
if ($prefix eq 'o') { } 181 36 217
elsif ($prefix eq 'd') { } 36 0 36
107 181 ▶ @words = defined($value) ? ("set", $name, $value) : ("unset", $name);
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 162 19 181
108 }elsif($prefix eq "d") {
109 36 ▶ @words = defined($value) ? ($name, "=", $value) : ("undefine", $name);
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 27 9 36
110 }else {
111 0 confess "Unknown key prefix: $prefix";
112 }
113 217 return join(" ", grep { "$_" ne "" } @words);
114 }
115  
116 234 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
117 234 my ($self) = @_;
118 234 my $result = "";
119 250 ▶ $self->{pdata}->each_resolved_entry(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
120 250 my ($raw_key, $values) = @_;
121 250 foreach my $value (@$values) {
122 262 my $statement = _create_statement($raw_key, $value);
123 262 $result .= $statement;
124 262 ▶ $result .= "\n" if $statement !~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $statement =~ /\n$/ 256 6 262
125 }
126 234 });
127 234 return $result;
128 }
129  
130 15 ▶sub define {
Subroutine define: called CC=1 SCAR=0.0
Pod documented
131 15 my ($self, @pairs) = @_;
132 15 return $self->_set_entry("d", 0, @pairs);
133 }
134  
135 37 *set_definition = *define;
136  
137 1 ▶sub undefine {
Subroutine undefine: called CC=1 SCAR=0.0
Pod documented
138 1 my ($self, @names) = @_;
139 1 return $self->define(map { $_ => undef } @names);
140 }
141  
142 13 ▶sub get_definition {
Subroutine get_definition: called CC=1 SCAR=0.0
Pod documented
143 13 my ($self, $name) = @_;
144 13 return $self->_get_entry("d", $name);
145 }
146  
147 4 ▶sub delete_definition {
Subroutine delete_definition: called CC=1 SCAR=0.0
Pod documented
148 4 my ($self, @names) = @_;
149 4 return $self->_delete_entry("d", @names);
150 }
151  
152 1012 ▶sub set_parent {
Subroutine set_parent: called CC=4 SCAR=14.4
Pod documented
153 1012 my ($self, $parent) = @_;
154 1012 ▶ if(!defined($parent)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 1 1011 1012
155 1 $self->{parent} = undef;
156 1 $self->{pdata}->set_parent(undef);
157 1 return $self;
158 }
159 1011 ▶ if(!blessed($parent) || !$parent->isa("Gnuplot::Builder::Script")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Script")) 0 1011 1011
Condition33%1/3
builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Script")
!ll&&!rl&&r
001011
MC/DC0%0/2
builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Script")
builtin::blessed($parent) $parent->isa("Gnuplot::Builder::Script")
Truth table33%1/3
A and B
A= builtin::blessed($parent)B= $parent->isa("Gnuplot::Builder::Script")
ABresult
0X0
100
111
160 0 croak "parent must be a Gnuplot::Builder::Script"
161 }
162 1011 $self->{parent} = $parent;
163 1011 $self->{pdata}->set_parent($parent->{pdata});
164 1011 return $self;
165 }
166  
167 5 ▶sub get_parent { return $_[0]->{parent} }
Subroutine get_parent: called CC=1 SCAR=0.0
Pod documented
168  
169 37 *parent = *get_parent;
170  
171 1009 ▶sub new_child {
Subroutine new_child: called CC=1 SCAR=0.0
Pod documented
172 1009 my ($self) = @_;
173 1009 return Gnuplot::Builder::Script->new->set_parent($self);
174 }
175  
176 76 ▶sub _collect_dataset_params {
Subroutine _collect_dataset_params: called CC=5 SCAR=16.5
177 76 my ($dataset_arrayref) = @_;
178 76 my @params_str = ();
179 76 my @dataset_objects = ();
180 76 foreach my $dataset (@$dataset_arrayref) {
181 91 my $ref = ref($dataset);
182 91 ▶ if(!$ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ref) { } 72 19 91
183 72 push(@params_str, $dataset);
184 }else {
185 19 ▶ if(!$dataset->can("params_string") || !$dataset->can("write_data_to")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset->can("params_string") and $dataset->can("write_data_to")) 0 19 19
Condition33%1/3
$dataset->can("params_string") and $dataset->can("write_data_to")
!ll&&!rl&&r
0019
MC/DC0%0/2
$dataset->can("params_string") and $dataset->can("write_data_to")
$dataset->can("params_string") $dataset->can("write_data_to")
Truth table33%1/3
A and B
A= $dataset->can("params_string")B= $dataset->can("write_data_to")
ABresult
0X0
100
111
186 0 croak "You cannot use $ref object as a dataset.";
187 }
188 19 my ($param_str) = $dataset->params_string();
189 19 push(@params_str, $param_str);
190 19 push(@dataset_objects, $dataset);
191 }
192 }
193 76 return (\@params_str, \@dataset_objects);
194 }
195  
196 106 ▶sub _wrap_writer_to_detect_empty_data {
Subroutine _wrap_writer_to_detect_empty_data: called CC=1 SCAR=0.0
197 106 my ($writer) = @_;
198 106 my $ended_with_newline = 0;
199 106 my $data_written = 0;
200 38 ▶ my $wrapped_writer = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
201 38 ▶ my @nonempty_data = grep { defined($_) && $_ ne "" } @_;
Condition100%3/3
defined $_ && $_ ne ''
!ll&&!rl&&r
2331
MC/DC100%2/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table100%3/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
202 38 ▶ return if !@nonempty_data;
Branch: 1 branch
BranchTrueFalseTotal
unless @nonempty_data 7 31 38
203 31 $data_written = 1;
204 31 $ended_with_newline = ($nonempty_data[-1] =~ /\n$/);
205 31 $writer->(join("", @nonempty_data));
206 106 };
207 106 return ($wrapped_writer, \$data_written, \$ended_with_newline);
208 }
209  
210 76 ▶sub _write_inline_data {
Subroutine _write_inline_data: called CC=4 SCAR=13.9
211 76 my ($writer, $dataset_objects_arrayref) = @_;
212 76 my ($wrapped_writer, $data_written_ref, $ended_with_newline_ref) =
213 _wrap_writer_to_detect_empty_data($writer);
214 76 foreach my $dataset (@$dataset_objects_arrayref) {
215 19 $$data_written_ref = $$ended_with_newline_ref = 0;
216 19 $dataset->write_data_to($wrapped_writer);
217 19 ▶ next if !$$data_written_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $$data_written_ref 8 11 19
218 11 ▶ $writer->("\n") if !$$ended_with_newline_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $$ended_with_newline_ref 5 6 11
219 11 $writer->("e\n");
220 }
221 }
222  
223 159 ▶sub _wrap_commands_with_output {
Subroutine _wrap_commands_with_output: called CC=2 SCAR=6.9
224 159 my ($commands_ref, $output_filename) = @_;
225 159 ▶ if(defined($output_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_filename) 12 147 159
226 12 unshift @$commands_ref, "set output " . quote_gnuplot_str($output_filename);
227 12 push @$commands_ref, "set output";
228 }
229 }
230  
231 76 ▶sub _draw_with {
Subroutine _draw_with: called CC=4 SCAR=13.9
232 76 my ($self, %args) = @_;
233 76 my $plot_command = $args{command};
234 76 my $dataset = $args{dataset};
235 76 ▶ croak "dataset parameter is mandatory" if not defined $dataset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dataset 0 76 76
236 76 ▶ if(ref($dataset) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dataset ne "ARRAY") 19 57 76
237 19 $dataset = [$dataset];
238 }
239 76 ▶ croak "at least one dataset is required" if !@$dataset;
Branch: 1 branch
BranchTrueFalseTotal
unless @$dataset 0 76 76
240  
241 76 ▶ my $plotter = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
242 76 my $writer = shift;
243 76 my ($params, $dataset_objects) = _collect_dataset_params($dataset);
244 76 $writer->("$plot_command " . join(",", @$params) . "\n");
245 76 _write_inline_data($writer, $dataset_objects);
246 76 };
247 76 my @commands = ($plotter);
248 76 return $self->run_with(
249 do => \@commands,
250 _pair_slice(\%args, qw(writer async output no_stderr on_exit))
251 );
252 }
253  
254 106 ▶sub _pair_slice {
Subroutine _pair_slice: called CC=2 SCAR=6.9
255 106 my ($hash_ref, @keys) = @_;
256 106 ▶ return map { exists($hash_ref->{$_}) ? ($_ => $hash_ref->{$_}) : () } @keys;
Branch: 1 branch
BranchTrueFalseTotal
exists $hash_ref->{$_} ? : 65 465 530
257 }
258  
259 21 ▶sub plot_with {
Subroutine plot_with: called CC=1 SCAR=0.0
Pod documented
260 21 my ($self, %args) = @_;
261 21 return $self->_draw_with(%args, command => "plot");
262 }
263  
264 6 ▶sub splot_with {
Subroutine splot_with: called CC=1 SCAR=0.0
Pod documented
265 6 my ($self, %args) = @_;
266 6 return $self->_draw_with(%args, command => "splot");
267 }
268  
269 46 ▶sub plot {
Subroutine plot: called CC=1 SCAR=0.0
Pod documented
270 46 my ($self, @dataset) = @_;
271 46 return $self->_draw_with(command => "plot", dataset => \@dataset);
272 }
273  
274 3 ▶sub splot {
Subroutine splot: called CC=1 SCAR=0.0
Pod documented
275 3 my ($self, @dataset) = @_;
276 3 return $self->_draw_with(command => "splot", dataset => \@dataset);
277 }
278  
279 30 ▶sub multiplot_with {
Subroutine multiplot_with: called CC=5 SCAR=16.1
Pod documented
280 30 my ($self, %args) = @_;
281 30 my $do = $args{do};
282 30 ▶ croak "do parameter is mandatory" if not defined $do;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $do 0 30 30
283 30 ▶ croak "do parameter must be a code-ref" if ref($do) ne "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $do ne "CODE" 0 30 30
284 30 ▶ my $wrapped_do = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
285 30 my $writer = shift;
286 30 my ($wrapped_writer, $data_written_ref, $ended_with_newline_ref) =
287 _wrap_writer_to_detect_empty_data($writer);
288 30 $do->($wrapped_writer);
289 29 ▶ if($$data_written_ref && !$$ended_with_newline_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$data_written_ref and not $$ended_with_newline_ref) 1 28 29
Condition100%3/3
$$data_written_ref and not $$ended_with_newline_ref
!ll&&!rl&&r
2261
MC/DC100%2/2
$$data_written_ref and not $$ended_with_newline_ref
$$data_written_ref not $$ended_with_newline_ref
Truth table100%3/3
A and not(B)
A= $$data_written_refB= not $$ended_with_newline_ref
ABresult
0X0
100
111
290 1 $writer->("\n");
291 }
292 30 };
293 my $multiplot_command =
294 30 ▶ (defined($args{option}) && $args{option} ne "")
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'option'} && $args{'option'} ne '' ? : 9 21 30
Condition100%3/3
defined $args{"option"} and $args{"option"} ne ""
!ll&&!rl&&r
1929
MC/DC100%2/2
defined $args{"option"} and $args{"option"} ne ""
defined $args{"option"} $args{"option"} ne ""
Truth table100%3/3
A and B
A= defined $args{"option"}B= $args{"option"} ne ""
ABresult
0X0
100
111
295 ? "set multiplot $args{option}" : "set multiplot";
296 30 my @commands = ($multiplot_command, $wrapped_do, "unset multiplot");
297 30 return $self->run_with(
298 do => \@commands,
299 _pair_slice(\%args, qw(writer async output no_stderr on_exit))
300 );
301 }
302  
303 3 ▶sub multiplot {
Subroutine multiplot: called CC=4 SCAR=14.0
Pod documented
304 3 my ($self, $option, $code) = @_;
305 3 ▶ if(@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 2 1 3
306 2 $code = $option;
307 2 $option = "";
308 }
309 3 ▶ croak "code parameter is mandatory" if not defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 3 3
310 3 ▶ croak "code parameter must be a code-ref" if ref($code) ne "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 3 3
311 3 return $self->multiplot_with(do => $code, option => $option);
312 }
313  
314 37 our $_context_writer = undef;
315  
316 159 ▶sub run_with {
Subroutine run_with: called CC=9 SCAR=22.5
Pod documented
317 159 my ($self, %args) = @_;
318 159 my $commands = $args{do};
319 159 ▶ if(!defined($commands)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $commands) { } 2 157 159
elsif (ref $commands ne 'ARRAY') { } 28 129 157
320 2 $commands = [];
321 }elsif(ref($commands) ne "ARRAY") {
322 28 $commands = [$commands];
323 }
324 159 my $on_exit = $args{on_exit};
325 159 ▶ if(defined($on_exit) && ref($on_exit) ne "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $on_exit and ref $on_exit ne "CODE") 0 159 159
Condition33%1/3
defined $on_exit and ref $on_exit ne "CODE"
!ll&&!rl&&r
15900
MC/DC0%0/2
defined $on_exit and ref $on_exit ne "CODE"
defined $on_exit ref $on_exit ne "CODE"
Truth table33%1/3
A and B
A= defined $on_exitB= ref $on_exit ne "CODE"
ABresult
0X0
100
111
326 0 croak "on_exit must be a CODE-REF";
327 }
328 159 _wrap_commands_with_output($commands, $self->_plotting_option(\%args, "output"));
329 159 ▶ my $do = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
330 159 my $writer = shift;
331 159 ▶ (!defined($_context_writer) || refaddr($_context_writer) != refaddr($writer))
Branch: 1 branch
BranchTrueFalseTotal
!defined($Gnuplot::Builder::Script::_context_writer) || builtin::refaddr($Gnuplot::Builder::Script::_context_writer) != builtin::refaddr($writer) and local $Gnuplot::Builder::Script::_context_writer = $writer 96 63 159
Condition100%3/3
not defined $Gnuplot::Builder::Script::_context_writer or builtin::refaddr($Gnuplot::Builder::Script::_context_writer) != builtin::refaddr($writer)
l!l&&r!l&&!r
831363
MC/DC100%2/2
not defined $Gnuplot::Builder::Script::_context_writer or builtin::refaddr($Gnuplot::Builder::Script::_context_writer) != builtin::refaddr($writer)
not defined $Gnuplot::Builder::Script::_context_writer builtin::refaddr($Gnuplot::Builder::Script::_context_writer) != builtin::refaddr($writer)
Truth table100%3/3
not(A) or B
A= not defined $Gnuplot::Builder::Script::_context_writerB= builtin::refaddr($Gnuplot::Builder::Script::_context_writer) != builtin::refaddr($writer)
ABresult
1X1
011
000
332 and local $_context_writer = $writer;
333
334 159 $writer->($self->to_string);
335 159 foreach my $command (@$commands) {
336 264 ▶ if(ref($command) eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $command eq 'CODE') { } 155 109 264
337 155 $command->($writer);
338 }else {
339 109 $command = "$command";
340 109 $writer->($command);
341 109 ▶ $writer->("\n") if $command !~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $command =~ /\n$/ 106 3 109
342 }
343 }
344 159 };
345  
346 159 my $result = "";
347 159 my $got_writer = $self->_plotting_option(\%args, "writer");
348 159 ▶ if(defined($got_writer)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $got_writer) { } 96 63 159
elsif (defined $Gnuplot::Builder::Script::_context_writer) { } 63 0 63
349 96 ▶ if(defined($on_exit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $on_exit) 0 96 96
350 0 croak "on_exit should not be set if writer is set";
351 }
352 96 $do->($got_writer);
353 }elsif(defined($_context_writer)) {
354 63 ▶ if(defined($on_exit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $on_exit) 0 63 63
355 0 croak "on_exit should not be set if there is a writer in the context"
356 }
357 63 $do->($_context_writer);
358 }else {
359 0 $result = Gnuplot::Builder::Process->with_new_process(
360 async => $self->_plotting_option(\%args, "async"),
361 do => $do,
362 no_stderr => $self->_plotting_option(\%args, "no_stderr"),
363 on_exit => $on_exit,
364 );
365 }
366 155 return $result;
367 }
368  
369 318 ▶sub _plotting_option {
Subroutine _plotting_option: called CC=2 SCAR=6.9
370 318 my ($self, $given_args_ref, $key) = @_;
371 return (exists $given_args_ref->{$key})
372 318 ▶ ? $given_args_ref->{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $given_args_ref->{$key} ? : 105 213 318
373 : $self->get_plot($key);
374 }
375  
376 13 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
377 13 my ($self, @commands) = @_;
378 13 return $self->run_with(do => \@commands);
379 }
380  
381 37 my %KNOWN_PLOTTING_OPTIONS = map { ($_ => 1) } qw(output no_stderr writer async);
382  
383 266 ▶sub _check_plotting_option {
Subroutine _check_plotting_option: called CC=2 SCAR=6.9
384 266 my ($arg_name) = @_;
385 266 ▶ croak "Unknown plotting option: $arg_name" if !$KNOWN_PLOTTING_OPTIONS{$arg_name};
Branch: 1 branch
BranchTrueFalseTotal
if not $KNOWN_PLOTTING_OPTIONS{$arg_name} 3 263 266
386 }
387  
388 13 ▶sub set_plot {
Subroutine set_plot: called CC=2 SCAR=6.9
Pod documented
389 13 my ($self, %opts) = @_;
390 13 foreach my $key (keys %opts) {
391 16 _check_plotting_option($key);
392 $self->{pdata}->set_attribute(
393 key => $key,
394 15 value => $opts{$key}
395 );
396 }
397 12 return $self;
398 }
399  
400 242 ▶sub get_plot {
Subroutine get_plot: called CC=2 SCAR=7.0
Pod documented
401 242 my ($self, $arg_name) = @_;
402 242 _check_plotting_option($arg_name);
403 241 ▶ croak "arg_name cannot be undef" if not defined $arg_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg_name 0 241 241
404 241 return $self->{pdata}->get_resolved_attribute($arg_name);
405 }
406  
407 6 ▶sub delete_plot {
Subroutine delete_plot: called CC=2 SCAR=6.9
Pod documented
408 6 my ($self, @arg_names) = @_;
409 6 foreach my $arg_name (@arg_names) {
410 8 _check_plotting_option($arg_name);
411 7 $self->{pdata}->delete_attribute($arg_name)
412 }
413 5 return $self;
414 }
415  
416 0 ▶sub Lens {
Subroutine Lens: not called CC=1 SCAR=6.9
Pod undocumented
417 0 my ($self, $key) = @_;
418 0 require Gnuplot::Builder::Lens;
419 0 return Gnuplot::Builder::Lens->new(
420 "get_option", "set_option", $key
421 );
422 }
423  
424 37 1;
425  
426 __END__
« Builder/Tap.pm ↑ Summary Builder/JoinDict.pm »