blib/lib/CXC/Gnuplot/V0/Label.pm

filter: Statementstmt 55.1% 43 / 78 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 56.2% 9 / 16 Podpod 100% 5 / 5 totaltotal 34.5% 57 / 165 CC 31 SCAR 50.7
CC
31
Cov
31%
opts
272.0
to_hash
210.0
coerce_attrs
12.0
CRAP 159.7
« blib/lib/CXC/Gnuplot/V0/AxisTics.pm ↑ Summary blib/lib/CXC/Gnuplot/V1.pm »
1 package CXC::Gnuplot::V0::Label;
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 Feature::Compat::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 'v0.29.3';
8  
9 class CXC::Gnuplot::V0::Label;
10  
11 1 ▶no namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Ref::Util 'is_ref', 'is_plain_arrayref';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use builtin 'is_bool', 'true';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 use CXC::Gnuplot::V0::Types -lexical, qw(
19 is_NonEmptyStr
20 is_Num
21  
22 ArrayRef
23 CoordPosition3D
24 Dict
25 Enum
26 NonEmptyStr
27 Num
28 Optional
29 PerlBool
30 PerlBoolFalse
31 PositiveInt
32 PositiveNum
33 SetFormats
34  
35 signature_for
36 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 use CXC::Gnuplot::V0::Util -lexical, 'maybe_quote', 'assert_coerce_object',
39 'clone_object',
40 1 ▶ 'pvalidate', 'to_hash_r', 'render_opts', 'render_set';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 my sub croak {
43 0 ▶ require Carp;
Subroutine croak: not called CC=1 SCAR=6.9
44 0 goto \&Carp::croak;
45 }
46  
47 # set label {<tag>} {"<label text>"} {at <position>}
48 # {left | center | right}
49 # {norotate | rotate {by <degrees>}}
50 # {font "<name>{,<size>}"}
51 # {noenhanced}
52 # {front | back}
53 # {textcolor <colorspec>}
54 # {point <pointstyle> | nopoint}
55 # {offset <offset>}
56 # {nobox} {boxed {bs <boxstyle>}}
57 # {hypertext}
58  
59  
60 #<<< notidy
61 1 field $tag :param :reader = undef;
62 1 field $text :param :reader = undef;
63 1 field $at :param :reader = undef;
64 1 field $justify :param :reader = undef;
65 1 field $rotate :param :reader = undef;
66 1 field $font :param :reader = undef;
67 1 field $enhanced :param :reader = undef;
68 1 field $layer :param :reader = undef;
69 1 field $textcolor :param :reader = undef;
70 1 field $point :param :reader = undef;
71 1 field $offset :param :reader = undef;
72 1 field $boxed :param :reader = undef;
73 1 field $hypertext :param :reader = undef;
74 #>>>
75  
76  
77  
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 ADJUST {
111  
112 0 ▶ pvalidate( tag => PositiveInt, \$tag );
Subroutine __ANON__: not called CC=1 SCAR=6.9
113  
114 0 pvalidate( text => NonEmptyStr, \$text );
115  
116 0 pvalidate( at => CoordPosition3D, \$at );
117  
118 0 pvalidate( justify => Enum->of( 'left', 'right', 'center' ), \$justify );
119  
120 0 pvalidate( rotate => Num | PerlBool, \$rotate );
121  
122 0 pvalidate( font => Font => \$font );
123  
124 0 pvalidate( enhanced => PerlBool, \$enhanced );
125  
126 0 pvalidate( layer => Enum->of( 'front', 'back' ), \$layer );
127  
128 0 pvalidate( textcolor => ColorSpec => \$textcolor );
129  
130 0 pvalidate(
131 point => PerlBoolFalse | Dict [
132 line => Optional [PositiveInt],
133 type => PositiveInt | NonEmptyStr,
134 size => Optional [PositiveNum],
135 color => Optional [NonEmptyStr], # TODO: convert this to a ColorSpec object
136 ],
137 \$point,
138 );
139  
140 0 pvalidate( offset => CoordOffset3D => \$offset );
141  
142 0 pvalidate( boxed => PerlBool | PositiveNum, \$boxed );
143  
144 0 pvalidate( hypertext => PerlBool, \$hypertext );
145 }
146  
147  
148  
149  
150  
151 method to_hash {
152  
153 0 ▶ to_hash_r( {
Subroutine to_hash: not called CC=14 SCAR=53.5
Pod documented
Branch: 13 branches
BranchTrueFalseTotal
defined $tag ? : 0 0 0
defined $text ? : 0 0 0
defined $at ? : 0 0 0
defined $justify ? : 0 0 0
defined $rotate ? : 0 0 0
defined $font ? : 0 0 0
defined $enhanced ? : 0 0 0
defined $layer ? : 0 0 0
defined $textcolor ? : 0 0 0
defined $point ? : 0 0 0
defined $offset ? : 0 0 0
defined $boxed ? : 0 0 0
defined $hypertext ? : 0 0 0
154 ( defined $tag ? ( tag => $tag ) : () ),
155 ( defined $text ? ( text => $text ) : () ),
156 ( defined $at ? ( at => $at ) : () ),
157 ( defined $justify ? ( justify => $justify ) : () ),
158 ( defined $rotate ? ( rotate => $rotate ) : () ),
159 ( defined $font ? ( font => $font ) : () ),
160 ( defined $enhanced ? ( enhanced => $enhanced ) : () ),
161 ( defined $layer ? ( layer => $layer ) : () ),
162 ( defined $textcolor ? ( textcolor => $textcolor ) : () ),
163 ( defined $point ? ( point => $point ) : () ),
164 ( defined $offset ? ( offset => $offset ) : () ),
165 ( defined $boxed ? ( boxed => $boxed ) : () ),
166 ( defined $hypertext ? ( hypertext => $hypertext ) : () ),
167 } );
168  
169 }
170  
171  
172  
173  
174  
175 ▶sub assert_coerce( $class, $args ) {
Subroutine assert_coerce: not called CC=1 SCAR=6.9
Pod documented
176 0 assert_coerce_object( $class, $args );
177 }
178  
179  
180  
181  
182  
183 ▶method clone ( %args ) {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
184 0 return clone_object( $self, \%args );
185 }
186  
187  
188  
189  
190  
191  
192 ▶sub coerce_attrs ( $class, @attrs ) {
Subroutine coerce_attrs: not called CC=3 SCAR=24.8
Pod documented
193 0 ▶ return @attrs == 1 && !is_ref( $attrs[0] )
Branch: 1 branch
BranchTrueFalseTotal
@attrs == 1 && !Ref::Util::XS::is_ref($attrs[0]) ? : 0 0 0
Condition0%0/3
@attrs == 1 and not Ref::Util::XS::is_ref($attrs[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@attrs == 1 and not Ref::Util::XS::is_ref($attrs[0])
@attrs == 1 not Ref::Util::XS::is_ref($attrs[0])
Truth table0%0/3
A and not(B)
A= @attrs == 1B= not Ref::Util::XS::is_ref($attrs[0])
ABresult
0X0
100
111
194 ? { text => $attrs[0] }
195 : undef;
196 }
197  
198  
199  
200  
201  
202 1 my %PointMap = (
203 line => 'lt',
204 type => 'pt',
205 size => 'ps',
206 color => 'lc',
207 );
208  
209  
210 method opts {
211 0 ▶ my @opts;
Subroutine opts: not called CC=16 SCAR=56.1
Pod documented
212  
213 0 ▶ defined $tag
Branch: 1 branch
BranchTrueFalseTotal
defined $tag and push @opts, $tag 0 0 0
214 and push @opts, $tag;
215  
216 0 ▶ defined $text
Branch: 1 branch
BranchTrueFalseTotal
defined $text and push @opts, maybe_quote($text) 0 0 0
217 and push @opts, maybe_quote( $text );
218  
219 0 push @opts, render_opts( at => $at );
220  
221 0 ▶ defined $justify
Branch: 1 branch
BranchTrueFalseTotal
defined $justify and push @opts, $justify 0 0 0
222 and push @opts, $justify;
223  
224 # rotate is either a false boolean or a number
225 0 ▶ defined $rotate
Branch: 3 branches
BranchTrueFalseTotal
defined $rotate and push @opts, builtin::is_bool($rotate) ? $rotate ? "rotate" : "norotate" : ["rotate by", $rotate] 0 0 0
builtin::is_bool($rotate) ? : 0 0 0
$rotate ? : 0 0 0
226 and push @opts, is_bool( $rotate )
227 ? ( $rotate ? 'rotate' : 'norotate' )
228 : [ 'rotate by' => $rotate ];
229  
230 0 push @opts, render_opts( font => $font );
231  
232 0 ▶ defined $enhanced
Branch: 2 branches
BranchTrueFalseTotal
defined $enhanced and push @opts, $enhanced ? "enhanced" : "noenhanced" 0 0 0
$enhanced ? : 0 0 0
233 and push @opts, ( $enhanced ? 'enhanced' : 'noenhanced' );
234  
235 0 ▶ defined $layer
Branch: 1 branch
BranchTrueFalseTotal
defined $layer and push @opts, $layer 0 0 0
236 and push @opts, $layer;
237  
238 0 push @opts, render_opts( textcolor => $textcolor );
239  
240 0 ▶ defined $hypertext && $hypertext
Branch: 1 branch
BranchTrueFalseTotal
defined $hypertext and $hypertext and push @opts, "hypertext" 0 0 0
Condition0%0/3
defined $hypertext and $hypertext
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hypertext and $hypertext
defined $hypertext $hypertext
Truth table0%0/3
A and B
A= defined $hypertextB= $hypertext
ABresult
0X0
100
111
241 and push @opts, 'hypertext';
242  
243 defined $point
244 0 ▶ and push @opts, [ point => map { $PointMap{$_} => $point->{$_} } sort keys $point->%* ];
Branch: 1 branch
BranchTrueFalseTotal
defined $point and push @opts, ["point", map({$PointMap{$_}, $point->{$_};} sort(keys %$point))] 0 0 0
245  
246 0 push @opts, render_opts( offset => $offset );
247  
248 0 ▶ defined $boxed
Branch: 3 branches
BranchTrueFalseTotal
defined $boxed and push @opts, builtin::is_bool($boxed) ? $boxed ? "boxed" : "noboxed" : ("boxed", "boxstyle", $boxed) 0 0 0
builtin::is_bool($boxed) ? : 0 0 0
$boxed ? : 0 0 0
249 and push @opts, is_bool( $boxed )
250 ? ( $boxed ? 'boxed' : 'noboxed' )
251 : ( boxed => boxstyle => $boxed );
252  
253 0 return @opts;
254 }
255  
256  
257  
258  
259  
260  
261 1 signature_for set => (
262 method => 1,
263 named => [
264 as => SetFormats,
265 { default => 'string' },
266 ],
267 );
268  
269 method set ( $opt ) {
270 return render_set( [ render_opts( [ set => 'label' ], $self ) ], $opt->as );
271 }
272  
273 1 1;
274  
275 #
276 # This file is part of CXC-Gnuplot
277 #
278 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
279 #
280 # This is free software, licensed under:
281 #
282 # The GNU General Public License, Version 3, June 2007
283 #
284  
285 __END__
« blib/lib/CXC/Gnuplot/V0/AxisTics.pm ↑ Summary blib/lib/CXC/Gnuplot/V1.pm »