File Coverage

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