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

filter: Statementstmt 98.1% 103 / 105 Branchbran 83.3% 5 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 92.3% 24 / 26 Podpod n/a totaltotal 92.4% 135 / 146 CC 6 SCAR 5.3
CC
6
Cov
95%
__ANON__
4.0
__ANON__
3.5
__ANON__
2.0
CRAP 1.7
« blib/lib/CXC/Gnuplot/V0/LiteralDataValue.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/AxisFormat.pm »
1 package CXC::Gnuplot::V0::Types;
2  
3 32 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use experimental 'builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 32 our $VERSION = 'v0.29.3';
7  
8 32 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use Type::Library
10 32 -extends => [ 'Types::Standard', 'Types::Common::Numeric', 'Types::Common::String', ],
11 -declare => qw(
12 ColorSpec
13 CoordOffset2D
14 CoordOffset3D
15 CoordPosition2D
16 CoordPosition3D
17 CoordSys
18 CoordValue
19 Coords
20 FormatCoordSys
21 Fraction
22 LiteralDataValue
23 MultiPlotLayout
24 Palette
25 Range
26 RGBColor
27 SetFormats
28 TicEntry
29 TicEntries
30 AddTicEntries
31 TicIncr
32 TicList
33 TicPosition
34 TicSeries
35 TicTimeIncr
36 TicTimeUnits
37 32 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 32 ▶use Type::Params 'signature_for';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 32 use Exporter::Shiny qw(
42 COORDSYS
43 FORMAT_COORD_SYS
44 signature_for
45 32 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 32 ▶use Types::Common::Numeric 'is_PositiveInt';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 ## no critic (CodeLayout::ProhibitQuotedWordLists)
51 32 ▶use constant COORDSYS => ( 'first', 'second', 'polar', 'graph', 'screen', 'character', 'char' );
Subroutine BEGIN: called CC=1 SCAR=0.0
52 32 ▶use constant FORMAT_COORD_SYS => ( 'numeric', 'timedate', 'geographic' );
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 32 declare CoordSys, as Enum [COORDSYS];
55  
56 # this is silly. would prefer to truly validate the date, but
57 # that's difficult without providing a format.
58 32 ▶use constant Date => NonEmptyStr;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 32 declare LiteralDataValue, as InstanceOf ['CXC::Gnuplot::V0::LiteralDataValue'];
61  
62 coerce LiteralDataValue,
63 from Any, via {
64 56 ▶ require CXC::Gnuplot::V0::LiteralDataValue;
Subroutine __ANON__: called CC=1 SCAR=0.0
65 56 CXC::Gnuplot::V0::LiteralDataValue->assert_coerce( $_[0] );
66 32 };
67  
68 32 declare CoordValue, as InstanceOf ['CXC::Gnuplot::V0::CoordValue'];
69  
70 coerce CoordValue, from Any, via {
71 86 ▶ require CXC::Gnuplot::V0::CoordValue;
Subroutine __ANON__: called CC=1 SCAR=0.0
72 86 CXC::Gnuplot::V0::CoordValue->assert_coerce( $_[0] );
73 32 };
74  
75 32 declare FormatCoordSys, as Enum [FORMAT_COORD_SYS];
76  
77 32 declare CoordOffset3D, as InstanceOf ['CXC::Gnuplot::V0::CoordOffset3D'];
78 coerce CoordOffset3D, from HashRef, via {
79 8 ▶ require CXC::Gnuplot::V0::CoordOffset3D;
Subroutine __ANON__: called CC=1 SCAR=0.0
80 8 CXC::Gnuplot::V0::CoordOffset3D->new( $_[0]->%* );
81 32 };
82  
83 32 declare CoordOffset2D, as InstanceOf ['CXC::Gnuplot::V0::CoordOffset2D'];
84 coerce CoordOffset2D, from HashRef, via {
85 6 ▶ require CXC::Gnuplot::V0::CoordOffset2D;
Subroutine __ANON__: called CC=1 SCAR=0.0
86 6 CXC::Gnuplot::V0::CoordOffset2D->new( $_[0]->%* );
87 32 };
88  
89 32 declare CoordPosition3D, as InstanceOf ['CXC::Gnuplot::V0::CoordPosition3D'];
90 coerce CoordPosition3D, from HashRef, via {
91 8 ▶ require CXC::Gnuplot::V0::CoordPosition3D;
Subroutine __ANON__: called CC=1 SCAR=0.0
92 8 CXC::Gnuplot::V0::CoordPosition3D->new( $_[0]->%* );
93 32 };
94  
95 32 declare CoordPosition2D, as InstanceOf ['CXC::Gnuplot::V0::CoordPosition2D'];
96 coerce CoordPosition2D, from HashRef, via {
97 8 ▶ require CXC::Gnuplot::V0::CoordPosition2D;
Subroutine __ANON__: called CC=1 SCAR=0.0
98 8 CXC::Gnuplot::V0::CoordPosition2D->new( $_[0]->%* );
99 32 };
100  
101  
102 32 declare TicTimeUnits, as Enum [qw( seconds minutes hours days weeks months years )];
103  
104 32 declare TicTimeIncr, as Dict [ multiple => PositiveNum, unit => TicTimeUnits ];
105 coerce TicTimeIncr,
106 from Tuple [ PositiveNum, TicTimeUnits ],
107 6 ▶ sub { my %incr; @incr{ 'multiple', 'unit' } = $_[0]->@*; return \%incr; };
Subroutine __ANON__: called CC=1 SCAR=0.0
108 32 declare TicIncr, as Num | TicTimeIncr, coercion => 1;
109  
110 32 declare TicPosition, as LiteralDataValue, coercion => 1;
111  
112 32 declare TicEntry, as #
113 Dict [
114 pos => TicPosition,
115 label => Optional [Str],
116 level => Optional [PositiveOrZeroInt],
117 ],
118 coercion => 1;
119  
120 8 ▶coerce TicEntry, from Num, via { { pos => TicPosition->coerce( $_[0] ) } };
Subroutine __ANON__: called CC=1 SCAR=0.0
121  
122 32 declare TicEntries, as ArrayRef [TicEntry], coercion => 1;
123 coerce TicEntries, from TicEntry->coercibles, via {
124 12 ▶ [ to_TicEntry( $_[0] ) ]
Subroutine __ANON__: called CC=1 SCAR=0.0
125 32 };
126  
127 32 declare TicSeries, as #
128 Dict [
129 start => Optional [TicPosition],
130 incr => TicIncr,
131 end => Optional [TicPosition],
132 ],
133 coercion => 1;
134  
135 32 coerce TicSeries, from TicIncr, q{ { incr => $_[0] } };
136  
137 32 declare AddTicEntries, as Tuple->of( Enum ['add'], Slurpy->of( TicEntries ) ), coercion => 1;
138  
139 32 declare TicList, as TicEntries | AddTicEntries;
140  
141 coerce TicList, from Any, via {
142 14 eval { TicEntries->assert_coerce( $_[0] ) }
143 14 ▶ // eval { AddTicEntries->assert_coerce( $_[0] ) }
Subroutine __ANON__: called CC=3 SCAR=12.5
Condition50%3/6
(eval { do { &TicEntries()->assert_coerce($_[0]) } } // eval { do { &AddTicEntries()->assert_coerce($_[0]) } }) // $_[0]
l!l&&r!l&&!r
1400
eval { do { &TicEntries()->assert_coerce($_[0]) } } // eval { do { &AddTicEntries()->assert_coerce($_[0]) } }
l!l&&r!l&&!r
1040
MC/DC0%0/3
(eval { do { &TicEntries()->assert_coerce($_[0]) } } // eval { do { &AddTicEntries()->assert_coerce($_[0]) } }) // $_[0]
eval { do { &TicEntries()->assert_coerce($_[0]) } } eval { do { &AddTicEntries()->assert_coerce($_[0]) } } $_[0]
Truth table50%2/4
A // B // C
A= eval { do { &TicEntries()->assert_coerce($_[0]) } }B= eval { do { &AddTicEntries()->assert_coerce($_[0]) } }C= $_[0]
ABCresult
1XX1
01X1
0011
0000
144 // $_[0]
145 32 };
146  
147 declare MultiPlotLayout, as Dict( [ nrows => PositiveInt, ncols => PositiveInt ] ), message {
148 27 ▶ require Data::Dump;
Subroutine __ANON__: called CC=4 SCAR=13.9
149 27 my $value = Data::Dump::pp( $_ );
150 27 ▶ is_ArrayRef( $_ )
Branch: 1 branch
BranchTrueFalseTotal
is_ArrayRef($_) and return "$value is not an array of two positive integers" 8 19 27
151 and return "$value is not an array of two positive integers";
152  
153 19 ▶ is_NonEmptyStr( $_ )
Branch: 1 branch
BranchTrueFalseTotal
is_NonEmptyStr($_) and return "$value is not a string of form <PositiveInt,PositiveInt>" 8 11 19
154 and return "$value is not a string of form <PositiveInt,PositiveInt>";
155  
156 11 ▶ is_HashRef( $_ )
Branch: 1 branch
BranchTrueFalseTotal
is_HashRef($_) and return "$value is not a hashref with keys 'nrows' and 'ncols'" 11 0 11
157 and return "$value is not a hashref with keys 'nrows' and 'ncols'";
158 32 };
159  
160 32 coerce MultiPlotLayout,
161 ArrayRef [ PositiveInt, 2, 2 ], q{ { nrows => $_[0][0], ncols => $_[0][1] } }, #
162 NonEmptyStr, <<~'EOS'
163 do {
164 use experimental 'builtin';
165 BEGIN{ builtin::export_lexically is_PositiveInt => \&Types::Common::Numeric::is_PositiveInt };
166 my ( $nrows, $ncols, $extra ) = split( qr/,/, $_[0] );
167 defined $extra || !( is_PositiveInt( $nrows ) && is_PositiveInt( $ncols ) )
168 ? $_[0]
169 : { nrows => $nrows, ncols => $ncols };
170 }
171 EOS
172 ;
173  
174 my $PerlBool = Type::Tiny->new(
175 name => 'PerlBool',
176 constraint => sub {
177 32 ▶ use builtin 'is_bool';
Subroutine BEGIN: called CC=1 SCAR=0.0
178 0 ▶ is_bool( $_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 32 } );
180  
181 32 __PACKAGE__->add_type( $PerlBool );
182  
183 __PACKAGE__->add_type(
184 Type::Tiny->new(
185 name => 'PerlBoolFalse',
186 parent => $PerlBool,
187 constraint => sub {
188 32 ▶ use builtin 'false';
Subroutine BEGIN: called CC=1 SCAR=0.0
189 0 ▶ $_ == false;
Subroutine __ANON__: not called CC=1 SCAR=6.9
190 32 } ) );
191  
192 32 declare Fraction, as NumRange [ 0, 1, 1, 1 ];
193  
194 # rgbcolor "0xRRGGBB" # string containing hexadecimal constant
195 # rgbcolor "0xAARRGGBB" # string containing hexadecimal constant
196 # rgbcolor "#RRGGBB" # string containing hexadecimal in x11 format
197 # rgbcolor "#AARRGGBB"
198  
199 32 declare RGBColor, as StrMatch [
200 qr{^
201 (?:[0][xX]|[#])
202 (?:[\da-hA-H]{2}){3,4}
203 $}x,
204 ];
205  
206 32 declare ColorSpec,
207 as RGBColor | Dict [ rgbcolor => RGBColor ] | Dict [ palette => Dict [ frac => Fraction ] ];
208  
209 32 declare Range, as InstanceOf ['CXC::Gnuplot::V0::Range'];
210 coerce Range, from HashRef, via {
211 2 ▶ require CXC::Gnuplot::V0::Range;
Subroutine __ANON__: called CC=1 SCAR=0.0
212 2 CXC::Gnuplot::V0::Range->new( $_[0]->%* );
213 32 };
214  
215 32 declare Palette, as Enum( ['z'] ) | Dict [ frac => Fraction ] | Dict [ cb => Range ], coercion => 1;
216  
217 32 declare SetFormats, as Enum [ 'array', 'flat_array', 'string' ];
218  
219 #
220 # This file is part of CXC-Gnuplot
221 #
222 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
223 #
224 # This is free software, licensed under:
225 #
226 # The GNU General Public License, Version 3, June 2007
227 #
228  
229 __END__
« blib/lib/CXC/Gnuplot/V0/LiteralDataValue.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/AxisFormat.pm »