blib/lib/Gnuplot/Builder/Dataset.pm

filter: Statementstmt 93.7% 120 / 128 Branchbran 88.8% 16 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 96.9% 32 / 33 Podpod 86.3% 19 / 22 totaltotal 91.2% 188 / 206 SCAR 26.5
CC
14
Cov
92%
set_parent
5.7
new
3.0
__ANON__
3.0
CRAP 14.1
« blib/lib/Gnuplot/Builder/JoinDict.pm ↑ Summary blib/lib/Gnuplot/Builder/Template.pm »
1 package Gnuplot::Builder::Dataset;
2 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use Gnuplot::Builder::PrototypedData;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use overload '""' => 'to_string';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 124 ▶ my ($class, $source, @set_option_args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
11 124 my $self = bless {
12 pdata => undef,
13 pdata_join => undef, ## deprecated. should be removed in the future.
14 parent => undef,
15 }, $class;
16 124 $self->_init_pdata();
17 124 ▶ if(defined $source) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source) 33 91 124
18 33 $self->set_source($source);
19 }
20 124 ▶ if(@set_option_args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@set_option_args) 7 117 124
21 7 $self->set_option(@set_option_args);
22 }
23 124 return $self;
24 }
25  
26 sub new_file {
27 18 ▶ my ($class, $filename, @set_option_args) = @_;
Subroutine new_file: called CC=1 SCAR=0.0
Pod documented
28 18 return $class->new->set_file($filename)->set_option(@set_option_args);
29 }
30  
31 sub new_data {
32 10 ▶ my ($class, $data_provider, @set_option_args) = @_;
Subroutine new_data: called CC=1 SCAR=0.0
Pod documented
33 10 return $class->new->set_file('-')->set_data($data_provider)->set_option(@set_option_args);
34 }
35  
36 sub _init_pdata {
37 124 ▶ my ($self) = @_;
Subroutine _init_pdata: called CC=1 SCAR=0.0
38 124 weaken $self;
39 $self->{pdata} = Gnuplot::Builder::PrototypedData->new(
40 entry_evaluator => sub {
41 49 ▶ my ($key, $coderef) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
42 49 return $coderef->($self, $key);
43 },
44 attribute_evaluator => { source => sub {
45 11 ▶ my ($key, $coderef) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
46 11 return $coderef->($self);
47 } },
48 124 );
49 124 $self->{pdata_join} = Gnuplot::Builder::PrototypedData->new();
50 }
51  
52 sub to_string {
53 119 ▶ my ($self) = @_;
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
54 119 my @words = ();
55 119 push @words, $self->get_source;
56 $self->{pdata}->each_resolved_entry(sub {
57 198 ▶ my ($name, $values_arrayref) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
58 198 my @values = grep { defined($_) } @$values_arrayref;
59 198 ▶ return if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 28 170 198
60 170 my $join = $self->{pdata_join}->get_resolved_attribute($name);
61 170 ▶ if(defined $join) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $join) { } 22 148 170
62 22 push @words, $name, join($join, @values);
63 }else {
64 148 push @words, $name, @values;
65 }
66 119 });
67 119 ▶ return join " ", grep { defined($_) && "$_" ne "" } @words;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and "$_" ne "" 453 39 492
68 }
69  
70 27 *params_string = *to_string;
71  
72 sub set_source {
73 42 ▶ my ($self, $source) = @_;
Subroutine set_source: called CC=1 SCAR=0.0
Pod documented
74 $self->{pdata}->set_attribute(
75 42 key => "source", value => $source
76 );
77 42 return $self;
78 }
79  
80 sub setq_source {
81 36 ▶ my ($self, $source) = @_;
Subroutine setq_source: called CC=1 SCAR=0.0
Pod documented
82 $self->{pdata}->set_attribute(
83 36 key => "source", value => $source, quote => 1,
84 );
85 36 return $self;
86 }
87  
88 27 *set_file = *setq_source;
89  
90 sub get_source {
91 138 ▶ my ($self) = @_;
Subroutine get_source: called CC=1 SCAR=0.0
Pod documented
92 138 return $self->{pdata}->get_resolved_attribute("source");
93 }
94  
95 sub delete_source {
96 5 ▶ my ($self) = @_;
Subroutine delete_source: called CC=1 SCAR=0.0
Pod documented
97 5 $self->{pdata}->delete_attribute("source");
98 5 return $self;
99 }
100  
101 sub set_option {
102 93 ▶ my ($self, @options) = @_;
Subroutine set_option: called CC=1 SCAR=0.0
Pod documented
103 $self->{pdata}->set_entry(
104 93 entries => \@options,
105 quote => 0,
106 );
107 93 return $self;
108 }
109  
110 27 *set = *set_option;
111  
112 sub setq_option {
113 25 ▶ my ($self, @options) = @_;
Subroutine setq_option: called CC=1 SCAR=0.0
Pod documented
114 $self->{pdata}->set_entry(
115 25 entries => \@options,
116 quote => 1,
117 );
118 25 return $self;
119 }
120  
121 27 *setq = *setq_option;
122  
123 sub unset {
124 2 ▶ my ($self, @opt_names) = @_;
Subroutine unset: called CC=1 SCAR=0.0
Pod documented
125 2 return $self->set_option(map {$_ => undef} @opt_names);
126 }
127  
128 sub get_option {
129 92 ▶ my ($self, $name) = @_;
Subroutine get_option: called CC=1 SCAR=0.0
Pod documented
130 92 return $self->{pdata}->get_resolved_entry($name);
131 }
132  
133 sub delete_option {
134 2 ▶ my ($self, @names) = @_;
Subroutine delete_option: called CC=2 SCAR=6.9
Pod documented
135 2 foreach my $name (@names) {
136 2 $self->{pdata}->delete_entry($name);
137 }
138 2 return $self;
139 }
140  
141 sub set_parent {
142 13 ▶ my ($self, $parent) = @_;
Subroutine set_parent: called CC=4 SCAR=17.4
Pod documented
143 13 ▶ if(!defined($parent)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 13 13
144 0 $self->{parent} = undef;
145 0 $self->{pdata}->set_parent(undef);
146 0 $self->{pdata_join}->set_parent(undef);
147 0 return $self;
148 }
149 13 ▶ if(!blessed($parent) || !$parent->isa("Gnuplot::Builder::Dataset")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Dataset")) 0 13 13
Condition33%1/3
builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Dataset")
!ll&&!rl&&r
0013
MC/DC0%0/2
builtin::blessed($parent) and $parent->isa("Gnuplot::Builder::Dataset")
builtin::blessed($parent) $parent->isa("Gnuplot::Builder::Dataset")
Truth table33%1/3
A and B
A= builtin::blessed($parent)B= $parent->isa("Gnuplot::Builder::Dataset")
ABresult
0X0
100
111
150 0 croak "parent must be a Gnuplot::Builder::Dataset";
151 }
152 13 $self->{parent} = $parent;
153 13 $self->{pdata}->set_parent($parent->{pdata});
154 13 $self->{pdata_join}->set_parent($parent->{pdata_join});
155 13 return $self;
156 }
157  
158 5 ▶sub get_parent { return $_[0]->{parent} }
Subroutine get_parent: called CC=1 SCAR=0.0
Pod documented
159  
160 27 *parent = *get_parent;
161  
162 sub new_child {
163 11 ▶ my ($self) = @_;
Subroutine new_child: called CC=1 SCAR=0.0
Pod documented
164 11 return Gnuplot::Builder::Dataset->new->set_parent($self);
165 }
166  
167 sub set_data {
168 24 ▶ my ($self, $data_provider) = @_;
Subroutine set_data: called CC=1 SCAR=0.0
Pod documented
169 $self->{pdata}->set_attribute(
170 24 key => "data", value => $data_provider
171 );
172 24 return $self;
173 }
174  
175 sub write_data_to {
176 41 ▶ my ($self, $writer) = @_;
Subroutine write_data_to: called CC=3 SCAR=11.0
Pod documented
177 41 my $data_provider = $self->{pdata}->get_resolved_attribute("data");
178 41 ▶ return $self if not defined $data_provider;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_provider 17 24 41
179 24 ▶ if(ref($data_provider) eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_provider eq 'CODE') { } 10 14 24
180 10 $data_provider->($self, $writer);
181 }else {
182 14 $writer->($data_provider);
183 }
184 24 return $self;
185 }
186  
187 sub delete_data {
188 6 ▶ my ($self) = @_;
Subroutine delete_data: called CC=1 SCAR=0.0
Pod documented
189 6 $self->{pdata}->delete_attribute("data");
190 6 return $self;
191 }
192  
193 sub _deprecated {
194 26 ▶ my ($msg) = @_;
Subroutine _deprecated: called CC=1 SCAR=0.0
195 26 my $method = (caller(1))[3];
196 26 carp "$method is deprecated. $msg";
197 }
198  
199 sub set_join {
200 24 ▶ my ($self, %joins) = @_;
Subroutine set_join: called CC=2 SCAR=6.9
Pod undocumented
201 24 _deprecated("Use Gnuplot::Builder::JoinDict.");
202 24 foreach my $name (keys %joins) {
203 $self->{pdata_join}->set_attribute(
204 28 key => $name, value => $joins{$name}, quote => 0
205 );
206 }
207 24 return $self;
208 }
209  
210 sub delete_join {
211 2 ▶ my ($self, @names) = @_;
Subroutine delete_join: called CC=2 SCAR=6.9
Pod undocumented
212 2 _deprecated("Use Gnuplot::Builder::JoinDict.");
213 2 foreach my $name (@names) {
214 2 $self->{pdata_join}->delete_attribute($name);
215 }
216 2 return $self;
217 }
218  
219 sub Lens {
220 0 ▶ my ($self, $key) = @_;
Subroutine Lens: not called CC=1 SCAR=6.9
Pod undocumented
221 0 require Gnuplot::Builder::Lens;
222 0 return Gnuplot::Builder::Lens->new(
223 "get_option", "set_option", $key
224 );
225 }
226  
227 27 1;
228  
229 __END__
« blib/lib/Gnuplot/Builder/JoinDict.pm ↑ Summary blib/lib/Gnuplot/Builder/Template.pm »