File Coverage

blib/lib/Types/PGPLOT.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 28 28 100.0


line stmt bran cond sub pod time code
1             package Types::PGPLOT;
2              
3             # ABSTRACT: Type::Tiny compatible types for the PGPLOT library
4              
5 1     1   259938 use strict;
  1         9  
  1         29  
6 1     1   6 use warnings;
  1         2  
  1         59  
7              
8             our $VERSION = '0.01';
9              
10             use Type::Library
11 1         11 -base,
12             -declare => qw[
13             Angle
14             ArrowHeadFillStyle
15             CharacterHeight
16             Color
17             FillAreaStyle
18             Font
19             LineStyle
20             LineWidth
21             PlotUnits
22             Symbol
23             XAxisOptions
24             YAxisOptions
25 1     1   526 ];
  1         20518  
26              
27 1     1   3202 use Types::Common::Numeric qw[ IntRange NumRange PositiveNum ];
  1         63458  
  1         10  
28 1     1   763 use Types::Standard qw[ Str Dict ScalarRef ];
  1         3  
  1         7  
29 1     1   1461 use Type::Utils -all;
  1         5228  
  1         10  
30              
31             # Package scoped hashes are made readonly so that we can allow their
32             # use outside of this module (e.g. for testing). Note however, that
33             # the common usage of $Map{$key} // $key will throw an exception if $Map{$key}
34             # does not exist. Therefore, in code using the restricted hashes,
35             # always for check for existence before retrieving values.
36              
37 1     1   4236 use Readonly::Tiny;
  1         4732  
  1         1181  
38              
39             #pod =type Angle
40             #pod
41             #pod A real number in [-360,360].
42             #pod
43             #pod =cut
44              
45             declare Angle, as NumRange [ -360, 360 ];
46              
47              
48             #pod =type ArrowHeadFillStyle
49             #pod
50             #pod An integer in [1,2].
51             #pod
52             #pod Coercions are provided for Str types with one of the following values:
53             #pod
54             #pod filled solid outline
55             #pod
56             #pod =cut
57              
58             our %Map_AHFS = (
59             solid => 1,
60             filled => 1,
61             outline => 2,
62             );
63              
64             declare ArrowHeadFillStyle, as IntRange [ 1, 2 ];
65             coerce ArrowHeadFillStyle, from Str, via {
66             $Map_AHFS{ lc $_ } // $_
67             };
68              
69             readonly \%Map_AHFS;
70              
71             #pod =type CharacterHeight
72             #pod
73             #pod A positive real number.
74             #pod
75             #pod =cut
76              
77             declare CharacterHeight, as PositiveNum;
78              
79              
80             #pod =type Color
81             #pod
82             #pod An integer in [0,255].
83             #pod
84             #pod Coercions are provided for Str types with one of the following values:
85             #pod
86             #pod background foreground
87             #pod black magenta blue-magenta
88             #pod white yellow red-magenta
89             #pod red orange dark-gray
90             #pod green green-yellow light-gray
91             #pod blue green-cyan darkgray
92             #pod cyan blue-cyan lightgray
93             #pod
94             #pod =cut
95              
96             our %Map_Color = (
97             background => 0,
98             black => 0,
99             foreground => 1,
100             white => 1,
101             red => 2,
102             green => 3,
103             blue => 4,
104             cyan => 5,
105             magenta => 6,
106             yellow => 7,
107             orange => 8,
108             'green-yellow' => 9,
109             'green-cyan' => 10,
110             'blue-cyan' => 11,
111             'blue-magenta' => 12,
112             'red-magenta' => 13,
113             'dark-gray' => 14,
114             'light-gray' => 15,
115             darkgray => 14,
116             lightgray => 15,
117             );
118              
119             readonly \%Map_Color;
120              
121             declare Color, as IntRange [ 0, 255 ];
122              
123             coerce Color, from Str,
124             via { exists $Map_Color{ lc $_ } ? $Map_Color{ lc $_ } : $_ };
125              
126              
127              
128             #pod =type FillAreaStyle
129             #pod
130             #pod An integer in [1,4].
131             #pod
132             #pod Coercions are provided for Str types with one of the following values:
133             #pod
134             #pod solid filled outline hatched cross-hatched
135             #pod
136             #pod =cut
137              
138             our %Map_FillAreaStyle = (
139             solid => 1,
140             filled => 1,
141             outline => 2,
142             hatched => 3,
143             'cross-hatched' => 4,
144             );
145              
146             readonly \%Map_FillAreaStyle;
147              
148             declare FillAreaStyle, as IntRange [ 1, 4 ];
149             coerce FillAreaStyle, from Str,
150             via { exists $Map_FillAreaStyle{ lc $_ } ? $Map_FillAreaStyle{ lc $_ } : $_ };
151              
152              
153             #pod =type Font
154             #pod
155             #pod An integer in [1,4].
156             #pod
157             #pod Coercions are provided for Str types with one of the following values:
158             #pod
159             #pod normal roman italic script
160             #pod
161             #pod =cut
162              
163             our %Map_Font = (
164             normal => 1,
165             roman => 2,
166             italic => 3,
167             script => 4,
168             );
169              
170             readonly \%Map_Font;
171              
172             declare Font, as IntRange [ 1, 4 ];
173             coerce Font, from Str,
174             via { exists $Map_Font{ lc $_ } ? $Map_Font{ lc $_ } : $_ };
175              
176              
177             #pod =type LineStyle
178             #pod
179             #pod An integer in [1,5].
180             #pod
181             #pod Coercions are provided for Str types with one of the following values:
182             #pod
183             #pod full dashed dot-dash-dot-dash dotted dash-dot-dot-dot
184             #pod
185             #pod =cut
186              
187             our %Map_LineStyle = (
188             full => 1,
189             dashed => 2,
190             'dot-dash-dot-dash' => 3,
191             dotted => 4,
192             'dash-dot-dot-dot' => 5,
193             );
194              
195             readonly \%Map_LineStyle;
196              
197             declare LineStyle, as IntRange [ 1, 5 ];
198             coerce LineStyle, from Str,
199             via { exists $Map_LineStyle{ lc $_ } ? $Map_LineStyle{ lc $_ } : $_ };
200              
201              
202             #pod =type LineWidth
203             #pod
204             #pod An integer in [1,201].
205             #pod
206             #pod =cut
207              
208             declare LineWidth, as IntRange [ 1, 201 ];
209              
210              
211              
212             #pod =type PlotUnits
213             #pod
214             #pod An integer in [0,4].
215             #pod
216             #pod Coercions are provided for Str types with one of the following values:
217             #pod
218             #pod ndc normalized-device-coordinates
219             #pod in inches
220             #pod mm millimeters
221             #pod pixels
222             #pod wc world-coordinates
223             #pod
224             #pod =cut
225              
226              
227             our %Map_PlotUnits = (
228             'normalized-device-coordinates' => 0,
229             ndc => 0,
230             inches => 1,
231             in => 1,
232             millimeters => 2,
233             mm => 2,
234             pixels => 3,
235             'world-coordinates' => 4,
236             wc => 4,
237             );
238              
239             readonly \%Map_PlotUnits;
240              
241             declare PlotUnits, as IntRange [ 0, 4 ];
242             coerce PlotUnits, from Str,
243             via { exists $Map_PlotUnits{ lc $_ } ? $Map_PlotUnits{ lc $_ } : $_ };
244              
245              
246             #pod =type Symbol
247             #pod
248             #pod An integer in [-31,255]
249             #pod
250             #pod Coercions are provided for string or references to strings with one of
251             #pod the following values:
252             #pod
253             #pod doicosagon dodecagon triangle
254             #pod henicosagon hendecagon dot0
255             #pod icosagon decagon dot1
256             #pod enneadecagon nonagon opensquare
257             #pod octadecagon enneagon dot
258             #pod heptadecagon octagon plus
259             #pod hexadecagon heptagon asterisk
260             #pod pentaadecagon hexagon opencircle
261             #pod tetradecagon pentagon cross
262             #pod tridecagon diamond x
263             #pod opensquare1 stardavid opencirc4
264             #pod opentriangle square opencirc5
265             #pod earth circle opencirc6
266             #pod sun star opencirc7
267             #pod curvesquare bigosquare backarrow
268             #pod opendiamond opencirc0 fwdarrow
269             #pod openstar opencirc1 uparrow
270             #pod triangle1 opencirc2 downarrow
271             #pod openplus opencirc3
272             #pod
273             #pod as well as characters with unicode/ascii codes in [32, 127].
274             #pod
275             #pod Because Perl well treat digits stored as strings as numbers rather than
276             #pod strings, the characters C<0>, C<1>, C<2>, C<3>, C<4>, C<5>, C<6>, C<7>, C<8>, C<9>
277             #pod will get treated as integers, not characters, so the resultant symbols
278             #pod will not be the expected characters. To ensure that a character is
279             #pod treated as a character, pass a reference to it. This will bypass the
280             #pod automatic conversion to integer.
281             #pod
282             #pod =cut
283              
284             our %Map_SymbolName = (
285             doicosagon => -22,
286             henicosagon => -21,
287             icosagon => -20,
288             enneadecagon => -19,
289             octadecagon => -18,
290             heptadecagon => -17,
291             hexadecagon => -16,
292             pentaadecagon => -15,
293             tetradecagon => -14,
294             tridecagon => -13,
295             dodecagon => -12,
296             hendecagon => -11,
297             decagon => -10,
298             nonagon => -9,
299             enneagon => -9,
300             octagon => -8,
301             heptagon => -7,
302             hexagon => -6,
303             pentagon => -5,
304             diamond => -4,
305             triangle => -3,
306             dot0 => -2,
307             dot1 => -1,
308             opensquare => 0,
309             dot => 1,
310             plus => 2,
311             asterisk => 3,
312             opencircle => 4,
313             cross => 5,
314             opensquare1 => 6,
315             opentriangle => 7,
316             earth => 8,
317             sun => 9,
318             curvesquare => 10,
319             opendiamond => 11,
320             openstar => 12,
321             triangle1 => 13,
322             openplus => 14,
323             stardavid => 15,
324             square => 16,
325             circle => 17,
326             star => 18,
327             bigosquare => 19,
328             opencirc0 => 20,
329             opencirc1 => 21,
330             opencirc2 => 22,
331             opencirc3 => 23,
332             opencirc4 => 24,
333             opencirc5 => 25,
334             opencirc6 => 26,
335             opencirc7 => 27,
336             backarrow => 28,
337             fwdarrow => 29,
338             uparrow => 30,
339             downarrow => 31
340             );
341              
342             readonly \%Map_SymbolName;
343              
344             declare Symbol, as IntRange [ -31, 255 ];
345              
346             coerce Symbol, from ScalarRef, via {
347             return $_ unless 'SCALAR' eq ref $_;
348             my $str = "$$_";
349              
350             my $name = lc $str;
351             return $Map_SymbolName{ $name } if exists $Map_SymbolName{ $name };
352              
353             my $ord = ord( $str );
354             return $ord > 31 && $ord < 128 ? $ord : $_;
355              
356             };
357              
358             coerce Symbol, from Str, via {
359              
360             my $name = lc $_;
361             return $Map_SymbolName{ $name } if exists $Map_SymbolName{ $name };
362              
363             my $ord = ord( $_ );
364              
365             return $ord > 31 && $ord < 128 ? $ord : $_;
366             };
367              
368              
369             #pod =type XAxisOptions
370             #pod
371             #pod A string containing any of the characters in C<< ABCGILNPMTS12 >>, where no character repeats.
372             #pod
373             #pod =cut
374              
375             declare XAxisOptions, as Str, where {
376             $_ =~ /^(?:
377             ( [ABCGILNPMTS12] )
378             (?!.*\g{-1})
379             )+$
380             /x;
381             };
382              
383             #pod =type YAxisOptions
384             #pod
385             #pod A string containing any of the characters in C<< ABCGILNPMTSV12 >>, where no character repeats.
386             #pod
387             #pod =cut
388              
389             declare YAxisOptions, as Str, where {
390             $_ =~ /^(?:
391             ( [ABCGILNPMTSV12] )
392             (?!.*\g{-1})
393             )+$
394             /x;
395             };
396              
397             1;
398              
399             #
400             # This file is part of Types-PGPLOT
401             #
402             # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
403             #
404             # This is free software, licensed under:
405             #
406             # The GNU General Public License, Version 3, June 2007
407             #
408              
409             __END__