Qhull/Options.pm

filter: Statementstmt 88.7% 95 / 107 Branchbran 76.9% 20 / 26 Conditioncond 30.7% 4 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 89.2% 25 / 28 Podpod 100% 13 / 13 totaltotal 80.5% 157 / 195 CC 24 SCAR 12.4
CC
24
Cov
82%
filter_args
8.3
has_compute
6.8
by_name
6.0
CRAP 3.4
« Qhull/Util.pm ↑ Summary Qhull.pm »
1 package Qhull::Options;
2  
3 # ABSTRACT: A container for Qhull to minimize re-parsing
4  
5 4 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use experimental 'signatures', 'declared_refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.08';
14  
15 4 ▶use Readonly::Tiny 'readonly', 'readwrite';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Qhull::Util::Options 'parse_options', -categories, -options;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Qhull::Util 'supported_output_format';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 our @CARP_NOT = qw( Qhull::PP Qhull::Util::Options );
22  
23 0 ▶my sub croak {
Subroutine croak: not called CC=1 SCAR=6.9
24 0 require Carp;
25 0 goto \&Carp::croak;
26 }
27  
28 22 ▶my sub _new ( $class, $attr ) {
Subroutine _new: called CC=1 SCAR=0.0
29 22 my $self = bless $attr, $class;
30 22 readonly \$self;
31 22 return $self;
32 }
33  
34  
35  
36  
37  
38  
39  
40  
41  
42 8 ▶sub new_from_options ( $class, $user_options ) {
Subroutine new_from_options: called CC=1 SCAR=0.0
Pod documented
43 8 return _new( $class, { by_position => parse_options( $user_options ) } );
44 }
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56 14 ▶sub new_from_specs ( $class, $specs = [] ) {
Subroutine new_from_specs: called CC=2 SCAR=6.9
Pod documented
57 14 readonly $specs;
58 14 return _new( $class, { by_position => $specs } );
59 }
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70 5 ▶sub clone_with_specs ( $self, $added_specs = [] ) {
Subroutine clone_with_specs: called CC=2 SCAR=6.9
Pod documented
71  
72 5 require Storable;
73 5 my @old_specs = readwrite( dclone $self->{by_position} )->@*;
74  
75 5 my %specs;
76 5 @specs{ map { $_->[0] } $added_specs->@* } = ();
77  
78 5 my @new_specs = grep { !exists $specs{ $_->[0] } } @old_specs;
79 5 push @new_specs, $added_specs->@*;
80 5 return blessed( $self )->new_from_specs( \@new_specs );
81 }
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92 5 ▶sub clone_with_options ( $self, $options = [] ) {
Subroutine clone_with_options: called CC=2 SCAR=6.9
Pod documented
93 5 return $self->clone_with_specs( parse_options( $options ) );
94 }
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128 9 ▶sub filter_args ( $self, %opts ) {
Subroutine filter_args: called CC=8 SCAR=21.2
Pod documented
129  
130 9 my %passthrough;
131 9 ▶ @passthrough{ ( $opts{passthrough} // [] )->@* } = ();
Condition50%1/2
$opts{"passthrough"} // []
l!l
90
MC/DC0%0/1
$opts{"passthrough"} // []
$opts{"passthrough"}
Truth table50%1/2
A
A= $opts{"passthrough"}
Aresult
11
00
132  
133 # always pass through TI and TO
134 9 @passthrough{ 'TI', 'TO' } = ();
135  
136 9 state %strip;
137 9 @strip{ CAT_INPUT, CAT_INPUT_FORMAT, CAT_OUTPUT, CAT_OUTPUT_GEOM } = ();
138  
139 9 my @opts;
140 9 my %stripped = map { $_ => [] } keys %strip;
141 9 for my $opt ( $self->{by_position}->@* ) {
142 19 my $option = $opt->[1];
143 19 ▶ next if $option->{strip};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"strip"} 0 19 19
144 19 ▶ if ( exists $passthrough{ $option->{name} } ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $passthrough{$option->{'name'}}) { } 11 8 19
elsif (exists $strip{$option->{'category'}}) { } 4 4 8
elsif ($option->{'category'} eq 'output_format') { } 4 0 4
145 11 push @opts, $opt;
146 }
147 elsif ( exists $strip{ $option->{category} } ) {
148 4 push $stripped{ $option->{category} }->@*, $opt;
149 }
150 elsif ( $option->{category} eq CAT_OUTPUT_FORMAT ) {
151 croak( "unsupported output format: $option->{name}" )
152 4 ▶ unless supported_output_format( $option->{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless supported_output_format($option->{"name"}) 0 4 4
153 4 push @opts, $opt;
154 }
155 else {
156 0 push @opts, $opt;
157 }
158 }
159  
160 9 return blessed( $self )->new_from_specs( \@opts );
161 }
162  
163  
164  
165  
166  
167  
168  
169  
170  
171 0 ▶sub specs ( $self ) {
Subroutine specs: not called CC=1 SCAR=6.9
Pod documented
172  
173 0 return $self->{by_position};
174 }
175  
176  
177  
178  
179  
180  
181  
182  
183  
184 9 ▶sub qhull_opts ( $self ) {
Subroutine qhull_opts: called CC=3 SCAR=11.4
Pod documented
185  
186 $self->{qhull_opts}
187 9 ▶ //= readonly [ map { $_->@[ 0, $_->@* == 3 ? 2 : () ]; } $self->{by_position}->@*, ];
Branch: 1 branch
BranchTrueFalseTotal
@$_ == 3 ? : 11 9 20
Condition33%1/3
$self->{"qhull_opts"} //= readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
l!l&&r!l&&!r
090
MC/DC0%0/2
$self->{"qhull_opts"} //= readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
$self->{"qhull_opts"} readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
Truth table33%1/3
A //= B
A= $self->{"qhull_opts"}B= readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
ABresult
1X1
011
000
188  
189 9 return $self->{qhull_opts};
190 }
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219 29 ▶sub by_category ( $self ) {
Subroutine by_category: called CC=4 SCAR=13.9
Pod documented
220  
221 29 ▶ if ( !defined $self->{by_category} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"by_category"}) 12 17 29
222 12 my %by_category;
223 12 for my $spec ( $self->{by_position}->@* ) {
224 20 my $option = $spec->[1];
225 20 ▶ my $category = $by_category{ $option->{category} } //= { by_name => {}, by_position => [] };
Condition50%1/2
$by_category{$option->{"category"}} //= {"by_name", {}, "by_position", []}
l!l
020
MC/DC0%0/1
$by_category{$option->{"category"}} //= {"by_name", {}, "by_position", []}
$by_category{$option->{"category"}}
Truth table50%1/2
A
A= $by_category{$option->{"category"}}
Aresult
11
00
226 20 $category->{by_name}{ $option->{name} } = $spec;
227 20 push $category->{by_position}->@*, $spec;
228 }
229 12 $self->{by_category} = \%by_category;
230 12 readonly $self->{by_category};
231 }
232  
233 29 return $self->{by_category};
234  
235 }
236  
237  
238  
239  
240  
241  
242  
243  
244  
245 0 ▶sub by_name ( $self ) {
Subroutine by_name: not called CC=2 SCAR=17.9
Pod documented
246  
247 0 ▶ if ( !defined $self->{by_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"by_name"}) 0 0 0
248 0 my %by_name = map { $_->[0]{name} => $_ } $self->{by_position}->@*;
249 0 $self->{by_name} = \%by_name;
250 0 readonly $self->{by_name};
251 }
252  
253 0 return $self->{by_name};
254 }
255  
256 24 ▶my sub extract_Tx ( $self, $Tx ) {
Subroutine extract_Tx: called CC=2 SCAR=6.9
257 24 ▶ my $entry = first { $_->[0] eq $Tx } $self->{by_position}->@*;
Subroutine __ANON__: called CC=1 SCAR=0.0
258 24 ▶ return defined $entry ? $entry->[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $entry ? : 15 9 24
259 }
260  
261  
262  
263  
264  
265  
266  
267  
268  
269 11 ▶sub TI ( $self ) {
Subroutine TI: called CC=2 SCAR=6.9
Pod documented
270 return exists $self->{ +OPTION_TI }
271 ? $self->{ +OPTION_TI }
272 11 ▶ : $self->{ +OPTION_TI } = extract_Tx( $self, OPTION_TI );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'TI'} ? : 2 9 11
273 }
274 sub input;
275 4 *input = \&TI;
276  
277  
278  
279  
280  
281  
282  
283  
284  
285 13 ▶sub TO ( $self ) {
Subroutine TO: called CC=2 SCAR=6.9
Pod documented
286 return exists $self->{ +OPTION_TO }
287 ? $self->{ +OPTION_TO }
288 13 ▶ : $self->{ +OPTION_TO } = extract_Tx( $self, OPTION_TO );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'TO'} ? : 4 9 13
289 }
290 sub output;
291 4 *output = \*TO;
292  
293  
294  
295  
296  
297  
298  
299  
300 9 ▶sub has_compute ( $self ) {
Subroutine has_compute: called CC=3 SCAR=19.2
Pod documented
301 9 ▶ return !!0 unless exists $self->by_category->{ +CAT_COMPUTE };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->by_category->{"compute"} 9 0 9
302 0 my $compute = exists $self->by_category->{ +CAT_COMPUTE };
303 0 ▶ return !!( defined( $compute ) && $compute->{by_position}->@* );
Condition0%0/3
defined $compute && @{$compute->{'by_position'}}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $compute && @{$compute->{'by_position'}}
defined $compute @{$compute->{'by_position'}}
Truth table0%0/3
A && B
A= defined $computeB= @{$compute->{'by_position'}}
ABresult
0X0
100
111
304 }
305  
306  
307  
308  
309  
310  
311  
312 9 ▶sub has_output_format ( $self ) {
Subroutine has_output_format: called CC=3 SCAR=11.4
Pod documented
313 9 ▶ return !!0 unless exists $self->by_category->{ +CAT_OUTPUT_FORMAT };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->by_category->{"output_format"} 5 4 9
314 4 my $compute = $self->by_category->{ +CAT_OUTPUT_FORMAT };
315 4 ▶ return !!( defined( $compute ) && $compute->{by_position}->@* );
Condition33%1/3
defined $compute && @{$compute->{'by_position'}}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $compute && @{$compute->{'by_position'}}
defined $compute @{$compute->{'by_position'}}
Truth table33%1/3
A && B
A= defined $computeB= @{$compute->{'by_position'}}
ABresult
0X0
100
111
316 }
317  
318  
319 4 1;
320 #
321 # This file is part of Qhull
322 #
323 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
324 #
325 # This is free software, licensed under:
326 #
327 # The GNU General Public License, Version 3, June 2007
328 #
329  
330 __END__
« Qhull/Util.pm ↑ Summary Qhull.pm »