blib/lib/Qhull/Options.pm

filter: Statementstmt 34.5% 37 / 107 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 39.2% 11 / 28 Podpod 100% 13 / 13 totaltotal 31.2% 61 / 195 CC 24 SCAR 28.4
CC
24
Cov
25%
filter_args
72.0
by_category
20.0
qhull_opts
12.0
CRAP 17.0
« blib/lib/Qhull/Util/Options.pm ↑ Summary blib/lib/Qhull/Util.pm »
1 package Qhull::Options;
2  
3 # ABSTRACT: A container for Qhull to minimize re-parsing
4  
5 3 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use experimental 'signatures', 'declared_refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = '0.07';
14  
15 3 ▶use Readonly::Tiny 'readonly', 'readwrite';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Qhull::Util::Options 'parse_options', -categories, -options;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Qhull::Util 'supported_output_format';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 our @CARP_NOT = qw( Qhull::PP Qhull::Util::Options );
22  
23 my sub croak {
24 0 ▶ require Carp;
Subroutine croak: not called CC=1 SCAR=6.9
25 0 goto \&Carp::croak;
26 }
27  
28 ▶my sub _new ( $class, $attr ) {
Subroutine _new: not called CC=1 SCAR=6.9
29 0 my $self = bless $attr, $class;
30 0 readonly \$self;
31 0 return $self;
32 }
33  
34  
35  
36  
37  
38  
39  
40  
41  
42 ▶sub new_from_options ( $class, $user_options ) {
Subroutine new_from_options: not called CC=1 SCAR=6.9
Pod documented
43 0 return _new( $class, { by_position => parse_options( $user_options ) } );
44 }
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56 0 ▶sub new_from_specs ( $class, $specs = [] ) {
Subroutine new_from_specs: not called CC=2 SCAR=17.9
Pod documented
57 0 readonly $specs;
58 0 return _new( $class, { by_position => $specs } );
59 }
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70 0 ▶sub clone_with_specs ( $self, $added_specs = [] ) {
Subroutine clone_with_specs: not called CC=2 SCAR=17.9
Pod documented
71  
72 0 require Storable;
73 0 my @old_specs = readwrite( dclone $self->{by_position} )->@*;
74  
75 0 my %specs;
76 0 @specs{ map { $_->[0] } $added_specs->@* } = ();
77  
78 0 my @new_specs = grep { !exists $specs{ $_->[0] } } @old_specs;
79 0 push @new_specs, $added_specs->@*;
80 0 return blessed( $self )->new_from_specs( \@new_specs );
81 }
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92 0 ▶sub clone_with_options ( $self, $options = [] ) {
Subroutine clone_with_options: not called CC=2 SCAR=17.9
Pod documented
93 0 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 ▶sub filter_args ( $self, %opts ) {
Subroutine filter_args: not called CC=8 SCAR=42.8
Pod documented
129  
130 0 my %passthrough;
131 0 ▶ @passthrough{ ( $opts{passthrough} // [] )->@* } = ();
Condition0%0/2
$opts{"passthrough"} // []
l!l
00
MC/DC0%0/1
$opts{"passthrough"} // []
$opts{"passthrough"}
Truth table0%0/2
A
A= $opts{"passthrough"}
Aresult
11
00
132  
133 # always pass through TI and TO
134 0 @passthrough{ 'TI', 'TO' } = ();
135  
136 0 state %strip;
137 0 @strip{ CAT_INPUT, CAT_INPUT_FORMAT, CAT_OUTPUT, CAT_OUTPUT_GEOM } = ();
138  
139 0 my @opts;
140 0 my %stripped = map { $_ => [] } keys %strip;
141 0 for my $opt ( $self->{by_position}->@* ) {
142 0 my $option = $opt->[1];
143 0 ▶ next if $option->{strip};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"strip"} 0 0 0
144 0 ▶ if ( exists $passthrough{ $option->{name} } ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $passthrough{$option->{'name'}}) { } 0 0 0
elsif (exists $strip{$option->{'category'}}) { } 0 0 0
elsif ($option->{'category'} eq 'output_format') { } 0 0 0
145 0 push @opts, $opt;
146 }
147 elsif ( exists $strip{ $option->{category} } ) {
148 0 push $stripped{ $option->{category} }->@*, $opt;
149 }
150 elsif ( $option->{category} eq CAT_OUTPUT_FORMAT ) {
151 croak( "unsupported output format: $option->{name}" )
152 0 ▶ unless supported_output_format( $option->{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless supported_output_format($option->{"name"}) 0 0 0
153 0 push @opts, $opt;
154 }
155 else {
156 0 push @opts, $opt;
157 }
158 }
159  
160 0 return blessed( $self )->new_from_specs( \@opts );
161 }
162  
163  
164  
165  
166  
167  
168  
169  
170  
171 ▶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 ▶sub qhull_opts ( $self ) {
Subroutine qhull_opts: not called CC=3 SCAR=24.8
Pod documented
185  
186 $self->{qhull_opts}
187 0 ▶ //= readonly [ map { $_->@[ 0, $_->@* == 3 ? 2 : () ]; } $self->{by_position}->@*, ];
Branch: 1 branch
BranchTrueFalseTotal
@$_ == 3 ? : 0 0 0
Condition0%0/3
$self->{"qhull_opts"} //= readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
l!l&&r!l&&!r
000
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 table0%0/3
A //= B
A= $self->{"qhull_opts"}B= readonly([map({@$_[0, @$_ == 3 ? 2 : ()];} @{$$self{"by_position"}})])
ABresult
1X1
011
000
188  
189 0 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 ▶sub by_category ( $self ) {
Subroutine by_category: not called CC=4 SCAR=30.0
Pod documented
220  
221 0 ▶ if ( !defined $self->{by_category} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"by_category"}) 0 0 0
222 0 my %by_category;
223 0 for my $spec ( $self->{by_position}->@* ) {
224 0 my $option = $spec->[1];
225 0 ▶ my $category = $by_category{ $option->{category} } //= { by_name => {}, by_position => [] };
Condition0%0/2
$by_category{$option->{"category"}} //= {"by_name", {}, "by_position", []}
l!l
00
MC/DC0%0/1
$by_category{$option->{"category"}} //= {"by_name", {}, "by_position", []}
$by_category{$option->{"category"}}
Truth table0%0/2
A
A= $by_category{$option->{"category"}}
Aresult
11
00
226 0 $category->{by_name}{ $option->{name} } = $spec;
227 0 push $category->{by_position}->@*, $spec;
228 }
229 0 $self->{by_category} = \%by_category;
230 0 readonly $self->{by_category};
231 }
232  
233 0 return $self->{by_category};
234  
235 }
236  
237  
238  
239  
240  
241  
242  
243  
244  
245 ▶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 ▶my sub extract_Tx ( $self, $Tx ) {
Subroutine extract_Tx: not called CC=2 SCAR=17.9
257 0 ▶ my $entry = first { $_->[0] eq $Tx } $self->{by_position}->@*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
258 0 ▶ return defined $entry ? $entry->[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $entry ? : 0 0 0
259 }
260  
261  
262  
263  
264  
265  
266  
267  
268  
269 ▶sub TI ( $self ) {
Subroutine TI: not called CC=2 SCAR=17.9
Pod documented
270 return exists $self->{ +OPTION_TI }
271 ? $self->{ +OPTION_TI }
272 0 ▶ : $self->{ +OPTION_TI } = extract_Tx( $self, OPTION_TI );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'TI'} ? : 0 0 0
273 }
274 sub input;
275 3 *input = \&TI;
276  
277  
278  
279  
280  
281  
282  
283  
284  
285 ▶sub TO ( $self ) {
Subroutine TO: not called CC=2 SCAR=17.9
Pod documented
286 return exists $self->{ +OPTION_TO }
287 ? $self->{ +OPTION_TO }
288 0 ▶ : $self->{ +OPTION_TO } = extract_Tx( $self, OPTION_TO );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'TO'} ? : 0 0 0
289 }
290 sub output;
291 3 *output = \*TO;
292  
293  
294  
295  
296  
297  
298  
299  
300 ▶sub has_compute ( $self ) {
Subroutine has_compute: not called CC=3 SCAR=24.8
Pod documented
301 0 ▶ return !!0 unless exists $self->by_category->{ +CAT_COMPUTE };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->by_category->{"compute"} 0 0 0
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 ▶sub has_output_format ( $self ) {
Subroutine has_output_format: not called CC=3 SCAR=24.8
Pod documented
313 0 ▶ return !!0 unless exists $self->by_category->{ +CAT_OUTPUT_FORMAT };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->by_category->{"output_format"} 0 0 0
314 0 my $compute = $self->by_category->{ +CAT_OUTPUT_FORMAT };
315 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
316 }
317  
318  
319 3 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__
331  
332 =pod
333  
334 =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory passthrough qhull
335 readonly
336  
337 =head1 NAME
338  
339 Qhull::Options - A container for Qhull to minimize re-parsing
340  
341 =head1 VERSION
342  
343 version 0.07
344  
345 =head1 SYNOPSIS
346  
347 =head1 CONSTRUCTORS
348  
349 =head2 new_from_options
350  
351 $obj = Qhull::Options->new_from_options( \@qhull_options );
352  
353 Parse a list of B<qhull> options and return an B<Qhull::Options> object.
354  
355 =head2 new_from_specs
356  
357 $obj = Qhull::Options->new_from_specs( \@qhull_specs );
358  
359 Create a B<Qhull::Options> object from a list of specifications in
360 the same format returned by L<Qhull::Util::Options/parse_options>.
361 The specifications are used directly and made readonly.
362  
363 =head1 METHODS
364  
365 =head2 clone_with_specs
366  
367 $new_obj = $obj->clone_with_specs( \@new_specs );
368  
369 Clone B<$obj> appending the specified specs. If an existing option is
370 also specified in @new_specs, it is removed from the existing specs.
371  
372 =head2 clone_with_options
373  
374 $new_obj = $obj->clone_with_specs( \@new_options );
375  
376 Clone B<$obj> appending the specified options. If an existing option
377 is also specified in B<@new_options>, it is removed.
378  
379 =head2 filter_args
380  
381 $new_obj = $obj->filter_args( %options );
382  
383 Filter out B<qhull> arguments in the categories
384  
385 CAT_INPUT
386 CAT_INPUT_FORMAT
387 CAT_OUTPUT
388 CAT_OUTPUT_GEOM
389  
390 as they will break input or output parsing and don't add anything we need.
391  
392 Note that the B<TI> and B<TO> options are I<never> filtered out, as they
393 are handled explicitly.
394  
395 B<%options> can have any of the following entries:
396  
397 =over
398  
399 =item *
400  
401 passthrough
402  
403 An arrayref of B<qhull> options to pass through. Be careful, as
404 they may break output parsing.
405  
406 =back
407  
408 =head2 specs
409  
410 \@specs = $obj->specs;
411  
412 Return the list of option specs; these are immutable.
413  
414 =head2 qhull_opts
415  
416 \@options = $obj->qhull_opts;
417  
418 Return a list of options in a form that B<qhull> will recognize
419  
420 =head2 by_category
421  
422 \%by_category = $obj->by_category;
423  
424 Return a hash containing the options specified in the C<$obj> object. The hash is keyed off of the
425 category name. Each value is a hash with two entries:
426  
427 =over
428  
429 =item *
430  
431 by_name
432  
433 A hashref keyed off of the option names. Values are the option specifications.
434  
435 =item *
436  
437 by_position
438  
439 An arrayref holding the option specifications for this category in the
440 order they were passed to the object constructor.
441  
442 =back
443  
444 =head2 by_name
445  
446 \%hash = $obj->by_name;
447  
448 Return a hash of option specs keyed off of option names.
449  
450 =head2 TI
451  
452 =head2 input
453  
454 Returns I<undef> if the B<TI> option was not specified, otherwise its value.
455  
456 =head2 TO
457  
458 =head2 output
459  
460 Returns I<undef> if the B<TO> option was not specified, otherwise its value.
461  
462 =head2 has_compute
463  
464 Returns true if a CAT_COMPUTE option was specified
465  
466 =head2 has_output_format
467  
468 Returns true if a CAT_OUTPUT_FORMAT option was specified
469  
470 =head1 SUPPORT
471  
472 =head2 Bugs
473  
474 Please report any bugs or feature requests to bug-qhull@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=Qhull>
475  
476 =head2 Source
477  
478 Source is available at
479  
480 https://gitlab.com/djerius/p5-qhull
481  
482 and may be cloned from
483  
484 https://gitlab.com/djerius/p5-qhull.git
485  
486 =head1 SEE ALSO
487  
488 Please see those modules/websites for more information related to this module.
489  
490 =over 4
491  
492 =item *
493  
494 L<Qhull|Qhull>
495  
496 =back
497  
498 =head1 AUTHOR
499  
500 Diab Jerius <djerius@cpan.org>
501  
502 =head1 COPYRIGHT AND LICENSE
503  
504 This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
505  
506 This is free software, licensed under:
507  
508 The GNU General Public License, Version 3, June 2007
509  
510 =cut
« blib/lib/Qhull/Util/Options.pm ↑ Summary blib/lib/Qhull/Util.pm »