File Coverage

blib/lib/PGPLOTx/Constants.pm
Criterion Covered Total %
statement 34 34 100.0
branch 8 10 80.0
condition 10 15 66.6
subroutine 11 11 100.0
pod 2 2 100.0
total 65 72 90.2


line stmt bran cond sub pod time code
1             package PGPLOTx::Constants;
2              
3             # ABSTRACT: Constants for use with PGPLOT
4              
5 2     2   321532 use strict;
  2         4  
  2         60  
6 2     2   8 use warnings;
  2         6  
  2         121  
7              
8 2     2   973 use CXC::Exporter::Util ':all';
  2         14924  
  2         276  
9 2     2   334 use parent 'Exporter::Tiny';
  2         313  
  2         14  
10              
11             #<<<
12             our $VERSION = '0.03';
13             #>>>
14              
15             my %Constants = (
16             ARROWHEAD_FILL_STYLES => {
17             SOLID => 1,
18             FILLED => 1,
19             OUTLINE => 2,
20             },
21              
22             COLORS => {
23             BACKGROUND => 0,
24             BLACK => 0,
25             FOREGROUND => 1,
26             WHITE => 1,
27             RED => 2,
28             GREEN => 3,
29             BLUE => 4,
30             CYAN => 5,
31             MAGENTA => 6,
32             YELLOW => 7,
33             ORANGE => 8,
34             GREEN_YELLOW => 9,
35             GREEN_CYAN => 10,
36             BLUE_CYAN => 11,
37             BLUE_MAGENTA => 12,
38             RED_MAGENTA => 13,
39             DARK_GRAY => 14,
40             LIGHT_GRAY => 15,
41             DARKGRAY => 14,
42             LIGHTGRAY => 15,
43             },
44              
45             AREA_FILL_STYLES => {
46             SOLID => 1,
47             FILLED => 1,
48             OUTLINE => 2,
49             HATCHED => 3,
50             CROSS_HATCHED => 4,
51             },
52              
53             FONTS => {
54             NORMAL => 1,
55             ROMAN => 2,
56             ITALIC => 3,
57             SCRIPT => 4,
58             },
59              
60             LINE_STYLES => {
61             FULL => 1,
62             DASHED => 2,
63             DOT_DASH_DOT_DASH => 3,
64             DOTTED => 4,
65             DASH_DOT_DOT_DOT => 5,
66             },
67              
68             PLOT_UNITS => {
69             NORMALIZED_DEVICE_COORDINATES => 0,
70             NDC => 0,
71             INCHES => 1,
72             IN => 1,
73             MILLIMETERS => 2,
74             MM => 2,
75             PIXELS => 3,
76             WORLD_COORDINATES => 4,
77             WC => 4,
78             },
79              
80             SYMBOLS => {
81             DOICOSAGON => -22,
82             HENICOSAGON => -21,
83             ICOSAGON => -20,
84             ENNEADECAGON => -19,
85             OCTADECAGON => -18,
86             HEPTADECAGON => -17,
87             HEXADECAGON => -16,
88             PENTADECAGON => -15,
89             TETRADECAGON => -14,
90             TRIDECAGON => -13,
91             DODECAGON => -12,
92             HENDECAGON => -11,
93             DECAGON => -10,
94             NONAGON => -9,
95             ENNEAGON => -9,
96             OCTAGON => -8,
97             HEPTAGON => -7,
98             HEXAGON => -6,
99             PENTAGON => -5,
100             DIAMOND => -4,
101             TRIANGLE => -3,
102             DOT0 => -2,
103             DOT1 => -1,
104             OPENSQUARE => 0,
105             DOT => 1,
106             PLUS => 2,
107             ASTERISK => 3,
108             OPENCIRCLE => 4,
109             CROSS => 5,
110             OPENSQUARE1 => 6,
111             OPENTRIANGLE => 7,
112             EARTH => 8,
113             SUN => 9,
114             CURVESQUARE => 10,
115             OPENDIAMOND => 11,
116             OPENSTAR => 12,
117             TRIANGLE1 => 13,
118             OPENPLUS => 14,
119             STARDAVID => 15,
120             SQUARE => 16,
121             CIRCLE => 17,
122             STAR => 18,
123             BIGOSQUARE => 19,
124             OPENCIRC0 => 20,
125             OPENCIRC1 => 21,
126             OPENCIRC2 => 22,
127             OPENCIRC3 => 23,
128             OPENCIRC4 => 24,
129             OPENCIRC5 => 25,
130             OPENCIRC6 => 26,
131             OPENCIRC7 => 27,
132             BACKARROW => 28,
133             FWDARROW => 29,
134             UPARROW => 30,
135             DOWNARROW => 31
136             },
137              
138             XAXIS_OPTIONS => { map { ( "XAXIS_OPT_$_" => $_ ) } qw( A B C G I L N P M T S ) },
139              
140             YAXIS_OPTIONS => { map { ( "YAXIS_OPT_$_" => $_ ) } qw( A B C G I L N P M T S V ) },
141             );
142              
143             install_CONSTANTS( \%Constants );
144             install_EXPORTS( { subs => [qw(coerce_constant list_constants)] } );
145              
146             sub _croak {
147 18     18   145 require Carp;
148 18         2961 goto \&Carp::croak;
149             }
150              
151             my %Coerce;
152              
153             for my $tag ( keys %Constants ) {
154              
155             my $coerce = $Coerce{ lc $tag } = {};
156             for my $const ( keys %{ $Constants{$tag} } ) {
157             my $ref = \$Constants{$tag}{$const};
158             $coerce->{$const} = $coerce->{ lc $const } = $ref;
159             $const =~ s/_/-/g;
160             $coerce->{$const} = $coerce->{ lc $const } = $ref;
161             }
162              
163             }
164              
165             sub _exporter_validate_opts {
166 22     22   365613 my ( $class, $globals ) = @_;
167              
168 22 50 66     127 if ( exists $globals->{as} && !ref $globals->{as} && $globals->{as} eq 'lc' ) {
      66        
169 20     20   909 $globals->{as} = sub { lc $_[0] }
170 1         5 }
171             }
172              
173             sub _exporter_merge_opts {
174 11     11   161939 my $class = shift;
175 11         24 my $tag_opts = shift;
176              
177 11 100       42 $tag_opts = {} unless ref( $tag_opts ) eq q(HASH);
178 11 50 66     50 if ( exists $tag_opts->{-as} && !ref $tag_opts->{-as} && $tag_opts->{-as} eq 'lc' ) {
      66        
179 1     20   1 $tag_opts = { %{$tag_opts}, -as => sub { lc $_[0] } };
  1         6  
  20         857  
180             }
181              
182 11         73 return $class->SUPER::_exporter_merge_opts( $tag_opts, @_ );
183             }
184              
185              
186              
187              
188              
189              
190              
191              
192              
193              
194              
195              
196              
197              
198              
199              
200              
201              
202             sub coerce_constant {
203 327     327 1 505629 my ( $tag, $label ) = @_;
204              
205             _croak( "unknown constant '$tag:$label'" )
206             unless exists $Coerce{$tag}
207 327 100 66     1952 && exists $Coerce{$tag}{$label};
208              
209 318         542 return ${ $Coerce{$tag}{$label} };
  318         1728  
210             }
211              
212              
213              
214              
215              
216              
217              
218              
219              
220              
221             sub list_constants {
222 18     18 1 40079 my ( $tag ) = @_;
223              
224             _croak( "unknown constant tag '$tag'" )
225 18 100       102 unless exists $Coerce{$tag};
226              
227 9         21 return ( sort keys %{ $Coerce{$tag} } );
  9         268  
228             }
229              
230             1;
231              
232             #
233             # This file is part of PGPLOTx-Constants
234             #
235             # This software is Copyright (c) 2026 by Smithsonian Astrophysical Observatory.
236             #
237             # This is free software, licensed under:
238             #
239             # The GNU General Public License, Version 3, June 2007
240             #
241              
242             __END__