blib/lib/CXC/Gnuplot/V1/Key.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/CXC/Gnuplot/V1/Font.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/Key/Title.pm »
1 package CXC::Gnuplot::V1::Key;
2  
3 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use experimental 'builtin', 'declared_refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Object::Pad 0.821;
Subroutine BEGIN: called CC=1 SCAR=2.6
6  
7 our $VERSION = 'v0.29.3';
8  
9 class CXC::Gnuplot::V1::Key : isa(CXC::Gnuplot::V1::Base) does( CXC::Gnuplot::V1::Role::Clone );
10  
11 use CXC::Gnuplot::V1::Util
12 -lexical => 'pvalidate',
13 'to_hash_r', 'render_opts', 'render_set';
14  
15 use CXC::Gnuplot::V1::Types -lexical => qw(
16 ArrayRef
17 CoordPosition2D
18 Enum
19 NonEmptyStr
20 Num
21 PositiveInt
22 PositiveNum
23 PositiveOrZeroNum
24 SetFormats
25 Str
26 Tuple
27 is_NonEmptyStr
28 is_PositiveInt
29 is_PositiveNum
30  
31 signature_for
32 );
33  
34 use builtin 'true', 'is_bool';
35  
36 no namespace::clean;
37  
38 use Ref::Util 'is_plain_arrayref';
39  
40 use namespace::clean;
41  
42 my sub croak {
43 require Carp;
44 goto \&Carp::croak;
45 }
46  
47 #<<< no tidy
48 field $on :param :reader = undef;
49 field $default :param :reader = true;
50 field $font :param :reader = undef;
51 field $enhanced :param :reader = undef;
52 field $title :param :reader = undef;
53 field $autotitle :param :reader = undef;
54 field $box :param :reader = undef;
55 field $opaque :param :reader = undef;
56 field $width :param :reader = undef;
57 field $height :param :reader = undef;
58  
59 field $region :param :reader = undef;
60 field $margin :param :reader = undef;
61 field $horiz :param :reader = undef;
62 field $vert :param :reader = undef;
63 field $at :param :reader = undef;
64 field $offset :param :reader = undef;
65  
66 field $layout :param :reader = undef;
67 field $maxcols :param :reader = undef;
68 field $maxrows :param :reader = undef;
69 field $columns :param :reader = undef;
70 field $keywidth :param :reader = undef;
71 field $justifyentrytext :param :reader = undef;
72  
73 field $reverse :param :reader = undef;
74 field $invert :param :reader = undef;
75 field $samplen :param :reader = undef;
76 field $spacing :param :reader = undef;
77 field $textcolor :param :reader = undef;
78 #>>>
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
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  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142 ADJUST {
143  
144 my $e;
145  
146 # this is equivalent to 'set/unset key'
147 # {on|off}
148 # $on => Bool
149 defined $on
150 and !is_bool( $on )
151 and croak q{invalid value for "on" parameter: must be bool};
152  
153 # {default}
154 # $default => Bool
155 defined $default
156 and !is_bool( $default )
157 and croak q{invalid value for "default" parameter: must be bool};
158  
159 #------------------------------------------------------
160 # general font parameters, which affect all of the entries
161 # in the key.
162  
163 # {font "<face>,<size>"}
164 # $font => Font|ArrayRef
165 pvalidate( font => Font => \$font );
166  
167 # {{no}enhanced}
168 # $enhanced => Bool
169 defined $enhanced
170 and !is_bool( $enhanced )
171 and croak( q{invalid value for "enhanced" parameter; must be bool} );
172  
173 pvalidate( title => 'Key::Title' => \$title );
174  
175 # we can accept traditional bools here, as the only possible
176 # values are boolean or 'columnheader'
177 # {{no}autotitle {columnheader}}
178 defined $autotitle
179 and !is_bool( $autotitle )
180 and $autotitle ne 'columnheader'
181 and croak( q{invalid value for "autotitle" parameter} );
182  
183 # this doesn't validate the line properties
184 # {{no}box {<line properties>}}
185 # box => Bool | ArrayRef[Str]
186 defined $box
187 and !is_bool( $box )
188 and defined( $e = ArrayRef->of( Str )->validate( $box ) )
189 and croak( q{invalid value for "box" parameter: must be bool or ArrayRef} );
190  
191 # {{no}opaque {fc <colorspec>}}
192 # * not future proof; this hardwires 'fc'
193 # * doesn't validate that 'fc' is always follwed by a colorspec.
194 defined $opaque
195 and !is_bool( $opaque )
196 and
197 defined( $e = Tuple->of( Enum->of( 'fc' ), ArrayRef->of( NonEmptyStr ) )->validate( $opaque ) )
198 and croak( q{invalid value for "opaque" parameter: must be bool or [ fc => <colorspec]} );
199  
200 # {width <width_increment>}
201 defined $width
202 and defined( $e = Num->validate( $width ) )
203 and croak( qq{invalid value for "width" parameter: $e} );
204  
205 # {height <height_increment>}
206 pvalidate( height => Num, \$height );
207  
208 pvalidate( region => Enum->of( 'inside', 'outside', 'fixed' ), \$region );
209  
210 pvalidate( margin => Enum->of( 'left', 'right', 'top', 'bottom' ), \$margin );
211  
212 pvalidate( horiz => Enum->of( 'left', 'right', 'center' ), \$horiz );
213  
214 pvalidate( vert => Enum->of( 'top', 'bottom', 'center' ), \$vert );
215  
216 pvalidate( at => CoordPosition2D, \$at );
217  
218 pvalidate( offset => CoordOffset2D => \$offset );
219  
220 pvalidate( layout => Enum [ 'vertical', 'horizontal' ], \$layout );
221  
222 pvalidate( maxcols => PositiveInt | Enum ['auto'], \$maxcols );
223  
224 pvalidate( maxrows => PositiveInt | Enum ['auto'], \$maxrows );
225  
226 pvalidate( columns => PositiveInt, \$columns );
227  
228 pvalidate(
229 keywidth => Tuple->of( Enum [ 'screen', 'graph' ], PositiveNum ) | PositiveNum,
230 \$keywidth,
231 );
232  
233 pvalidate( justifyentrytext => Enum->of( 'left', 'right' ), \$justifyentrytext );
234  
235 defined $reverse
236 and !is_bool( $reverse )
237 and croak q{invalid value for "reverse" parameter};
238  
239 defined $invert
240 and !is_bool( $invert )
241 and croak q{invalid value for "invert" parameter};
242  
243 pvalidate( samplen => PositiveOrZeroNum, \$samplen );
244  
245 pvalidate( spacing => PositiveNum, \$spacing );
246  
247 pvalidate( textcolor => ColorSpec => \$textcolor );
248 }
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269 method to_hash {
270  
271 my %hash = (
272 ( defined $default ? ( default => $default ) : () ),
273 ( defined $font ? ( font => $font ) : () ),
274 ( defined $enhanced ? ( enhanced => $enhanced ) : () ),
275 ( defined $title ? ( title => $title ) : () ),
276 ( defined $autotitle ? ( autotitle => $autotitle ) : () ),
277 ( defined $box ? ( box => $box ) : () ),
278 ( defined $opaque ? ( opaque => $opaque ) : () ),
279 ( defined $width ? ( width => $width ) : () ),
280 ( defined $height ? ( height => $height ) : () ),
281 ( defined $region ? ( region => $region ) : () ),
282 ( defined $margin ? ( margin => $margin ) : () ),
283 ( defined $horiz ? ( horiz => $horiz ) : () ),
284 ( defined $vert ? ( vert => $vert ) : () ),
285 ( defined $at ? ( at => $at ) : () ),
286 ( defined $offset ? ( offset => $offset ) : () ),
287 ( defined $layout ? ( layout => $layout ) : () ),
288 ( defined $maxcols ? ( maxcols => $maxcols ) : () ),
289 ( defined $maxrows ? ( maxrows => $maxrows ) : () ),
290 ( defined $columns ? ( columns => $columns ) : () ),
291 ( defined $keywidth ? ( keywidth => $keywidth ) : () ),
292 ( defined $justifyentrytext ? ( justifyentrytext => $justifyentrytext ) : () ),
293 ( defined $reverse ? ( reverse => $reverse ) : () ),
294 ( defined $invert ? ( invert => $invert ) : () ),
295 ( defined $samplen ? ( samplen => $samplen ) : () ),
296 ( defined $spacing ? ( spacing => $spacing ) : () ),
297 ( defined $textcolor ? ( textcolor => $textcolor ) : () ),
298 );
299  
300 return to_hash_r( \%hash );
301 }
302  
303  
304  
305  
306  
307  
308 method opts {
309  
310 state %MapMargin = (
311 left => 'lmargin',
312 right => 'rmargin',
313 top => 'tmargin',
314 bottom => 'bmargin',
315 );
316  
317 state %MapEntryJustify = (
318 left => 'Left',
319 right => 'Right',
320 );
321  
322 defined $on
323 and !$on
324 and return 'off';
325  
326 my @opts;
327  
328 defined $on
329 and $on
330 and push @opts, 'on';
331  
332 defined $default
333 and $default
334 and push @opts, 'default';
335  
336 push @opts, render_opts( font => $font );
337  
338 defined $enhanced
339 and push @opts, $enhanced ? 'enhanced' : 'noenhaced';
340  
341 defined $title
342 and push @opts, is_bool( $title ) && !$title
343 ? 'notitle'
344 : render_opts( title => $title );
345  
346 push @opts, render_opts( textcolor => $textcolor );
347  
348 push @opts,
349 $autotitle eq 'columnheader' ? [ autotitle => 'columnheader' ]
350 : $autotitle ? 'autotitle'
351 : 'noautotitle'
352 if defined $autotitle;
353  
354 push @opts,
355 !$box ? 'nobox'
356 : is_plain_arrayref( $box ) ? [ box => $box->@* ]
357 : 'box'
358 if defined $box;
359  
360 push @opts, !$opaque
361 ? 'noopaque'
362 : [ opaque => $opaque ]
363 if defined $opaque;
364  
365 push @opts, [ width => $width ]
366 if defined $width;
367  
368 push @opts, [ height => $height ]
369 if defined $height;
370  
371 push @opts, $region
372 if defined $region;
373  
374 push @opts, $MapMargin{$margin}
375 if defined $margin;
376  
377 push @opts, $horiz
378 if defined $horiz;
379  
380 push @opts, $vert
381 if defined $vert;
382  
383 push @opts, render_opts( at => $at );
384 push @opts, render_opts( offset => $offset );
385  
386 push @opts, $layout
387 if defined $layout;
388  
389 push @opts, [ maxcols => $maxcols ]
390 if defined $maxcols;
391  
392 push @opts, [ maxrows => $maxrows ]
393 if defined $maxrows;
394  
395 push @opts, [ columns => $columns ]
396 if defined $columns;
397  
398 push @opts, [ keywidth => $keywidth ]
399 if defined $keywidth;
400  
401 push @opts, $MapEntryJustify{$justifyentrytext}
402 if defined $justifyentrytext;
403  
404 push @opts, $reverse ? 'reverse' : 'noreverse'
405 if defined $reverse;
406  
407 push @opts, $invert ? 'invert' : 'noinvert'
408 if defined $invert;
409  
410 push @opts, [ samplen => $samplen ]
411 if defined $samplen;
412  
413 push @opts, [ spacing => $spacing ]
414 if defined $spacing;
415  
416 return @opts;
417 }
418  
419  
420  
421  
422  
423 signature_for set => (
424 method => 1,
425 named => [
426 as => SetFormats,
427 { default => 'string' },
428 ],
429 );
430  
431 method set ( $opt ) {
432 return render_set( [ render_opts( [ set => 'key' ], $self ) ], $opt->as );
433 }
434  
435  
436 1;
437  
438 #
439 # This file is part of CXC-Gnuplot
440 #
441 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
442 #
443 # This is free software, licensed under:
444 #
445 # The GNU General Public License, Version 3, June 2007
446 #
447  
448 __END__
« blib/lib/CXC/Gnuplot/V1/Font.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/Key/Title.pm »