Builder/Dataset.pm

filter: Statementstmt 93.7% 120 / 128 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 96.9% 32 / 33 Podpod 86.3% 19 / 22 totaltotal 91.3% 191 / 209 CC 14 SCAR 6.9
CC
14
Cov
92%
set_parent
5.7
new
3.0
__ANON__
3.0
CRAP 2.0
« Builder/Lens.pm ↑ Summary Builder.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 124 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
10 124 my ($class, $source, @set_option_args) = @_;
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 18 ▶sub new_file {
Subroutine new_file: called CC=1 SCAR=0.0
Pod documented
27 18 my ($class, $filename, @set_option_args) = @_;
28 18 return $class->new->set_file($filename)->set_option(@set_option_args);
29 }
30  
31 10 ▶sub new_data {
Subroutine new_data: called CC=1 SCAR=0.0
Pod documented
32 10 my ($class, $data_provider, @set_option_args) = @_;
33 10 return $class->new->set_file('-')->set_data($data_provider)->set_option(@set_option_args);
34 }
35  
36 124 ▶sub _init_pdata {
Subroutine _init_pdata: called CC=1 SCAR=0.0
37 124 my ($self) = @_;
38 124 weaken $self;
39 $self->{pdata} = Gnuplot::Builder::PrototypedData->new(
40 49 ▶ entry_evaluator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 49 my ($key, $coderef) = @_;
42 49 return $coderef->($self, $key);
43 },
44 11 ▶ attribute_evaluator => { source => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 11 my ($key, $coderef) = @_;
46 11 return $coderef->($self);
47 } },
48 124 );
49 124 $self->{pdata_join} = Gnuplot::Builder::PrototypedData->new();
50 }
51  
52 119 ▶sub to_string {
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
53 119 my ($self) = @_;
54 119 my @words = ();
55 119 push @words, $self->get_source;
56 198 ▶ $self->{pdata}->each_resolved_entry(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
57 198 my ($name, $values_arrayref) = @_;
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;
Condition100%3/3
defined $_ && "$_" ne ''
!ll&&!rl&&r
3913440
MC/DC100%2/2
defined $_ && "$_" ne ''
defined $_ "$_" ne ''
Truth table100%3/3
A && B
A= defined $_B= "$_" ne ''
ABresult
0X0
100
111
68 }
69  
70 27 *params_string = *to_string;
71  
72 42 ▶sub set_source {
Subroutine set_source: called CC=1 SCAR=0.0
Pod documented
73 42 my ($self, $source) = @_;
74 $self->{pdata}->set_attribute(
75 42 key => "source", value => $source
76 );
77 42 return $self;
78 }
79  
80 36 ▶sub setq_source {
Subroutine setq_source: called CC=1 SCAR=0.0
Pod documented
81 36 my ($self, $source) = @_;
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 138 ▶sub get_source {
Subroutine get_source: called CC=1 SCAR=0.0
Pod documented
91 138 my ($self) = @_;
92 138 return $self->{pdata}->get_resolved_attribute("source");
93 }
94  
95 5 ▶sub delete_source {
Subroutine delete_source: called CC=1 SCAR=0.0
Pod documented
96 5 my ($self) = @_;
97 5 $self->{pdata}->delete_attribute("source");
98 5 return $self;
99 }
100  
101 93 ▶sub set_option {
Subroutine set_option: called CC=1 SCAR=0.0
Pod documented
102 93 my ($self, @options) = @_;
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 25 ▶sub setq_option {
Subroutine setq_option: called CC=1 SCAR=0.0
Pod documented
113 25 my ($self, @options) = @_;
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 2 ▶sub unset {
Subroutine unset: called CC=1 SCAR=0.0
Pod documented
124 2 my ($self, @opt_names) = @_;
125 2 return $self->set_option(map {$_ => undef} @opt_names);
126 }
127  
128 92 ▶sub get_option {
Subroutine get_option: called CC=1 SCAR=0.0
Pod documented
129 92 my ($self, $name) = @_;
130 92 return $self->{pdata}->get_resolved_entry($name);
131 }
132  
133 2 ▶sub delete_option {
Subroutine delete_option: called CC=2 SCAR=6.9
Pod documented
134 2 my ($self, @names) = @_;
135 2 foreach my $name (@names) {
136 2 $self->{pdata}->delete_entry($name);
137 }
138 2 return $self;
139 }
140  
141 13 ▶sub set_parent {
Subroutine set_parent: called CC=4 SCAR=17.4
Pod documented
142 13 my ($self, $parent) = @_;
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 11 ▶sub new_child {
Subroutine new_child: called CC=1 SCAR=0.0
Pod documented
163 11 my ($self) = @_;
164 11 return Gnuplot::Builder::Dataset->new->set_parent($self);
165 }
166  
167 24 ▶sub set_data {
Subroutine set_data: called CC=1 SCAR=0.0
Pod documented
168 24 my ($self, $data_provider) = @_;
169 $self->{pdata}->set_attribute(
170 24 key => "data", value => $data_provider
171 );
172 24 return $self;
173 }
174  
175 41 ▶sub write_data_to {
Subroutine write_data_to: called CC=3 SCAR=11.0
Pod documented
176 41 my ($self, $writer) = @_;
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 6 ▶sub delete_data {
Subroutine delete_data: called CC=1 SCAR=0.0
Pod documented
188 6 my ($self) = @_;
189 6 $self->{pdata}->delete_attribute("data");
190 6 return $self;
191 }
192  
193 26 ▶sub _deprecated {
Subroutine _deprecated: called CC=1 SCAR=0.0
194 26 my ($msg) = @_;
195 26 my $method = (caller(1))[3];
196 26 carp "$method is deprecated. $msg";
197 }
198  
199 24 ▶sub set_join {
Subroutine set_join: called CC=2 SCAR=6.9
Pod undocumented
200 24 my ($self, %joins) = @_;
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 2 ▶sub delete_join {
Subroutine delete_join: called CC=2 SCAR=6.9
Pod undocumented
211 2 my ($self, @names) = @_;
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 0 ▶sub Lens {
Subroutine Lens: not called CC=1 SCAR=6.9
Pod undocumented
220 0 my ($self, $key) = @_;
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__
« Builder/Lens.pm ↑ Summary Builder.pm »