Regions/CIAO.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 23 / 23 Podpod 100% 1 / 1 totaltotal 97.8% 90 / 92 CC 3 SCAR 1.5
CC
3
Cov
99%
mkregion
2.0
args
2.0
BEGIN
1.0
CRAP 1.2
« Regions/DS9/Types.pm ↑ Summary Regions.pm »
1 package CXC::Astro::Regions::CIAO;
2  
3 # ABSTRACT: CIAO Compatible Regions
4  
5 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use experimental 'signatures', 'postderef', 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.05';
10  
11 2 ▶use CXC::Astro::Regions::CIAO::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 Angle
13 Tuple
14 Length
15 NonEmptyStr
16 Vertex
17 ArrayRef
18 XPosition
19 YPosition
20 2 );
21  
22 2 ▶use CXC::Astro::Regions::CIAO::Variant;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶use constant RegionRole => __PACKAGE__ . '::Role::Region';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 ▶use parent 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 ▶my sub pkgpath ( @paths ) {
Subroutine pkgpath: called CC=1 SCAR=0.0
31 1 join q{::}, __PACKAGE__, map { ucfirst } @paths;
32 }
33  
34 54 ▶my sub args ( @args ) {
Subroutine args: called CC=2 SCAR=6.9
35 54 ▶ return @args == 1 ? ( name => $args[0] ) : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 42 12 54
36 }
37  
38 6 ▶my sub ANGLE { { name => 'angle', isa => Angle, args( @_ ) } }
Subroutine ANGLE: called CC=1 SCAR=0.0
39 4 ▶my sub ANGLEPAIR { { name => 'angles', isa => Tuple [ Angle, Angle ], args( @_ ) } }
Subroutine ANGLEPAIR: called CC=1 SCAR=0.0
40 10 ▶my sub LENGTH { { name => 'length', isa => Length, args( @_ ) } }
Subroutine LENGTH: called CC=1 SCAR=0.0
41 6 ▶my sub LENGTHPAIR { { name => undef, isa => Tuple [ Length, Length ], args( @_ ) } }
Subroutine LENGTHPAIR: called CC=1 SCAR=0.0
42 2 ▶my sub STRING { { name => undef, isa => NonEmptyStr, args( @_ ) } }
Subroutine STRING: called CC=1 SCAR=0.0
43 16 ▶my sub VERTEX { { name => undef, isa => Vertex, args( @_ ) } }
Subroutine VERTEX: called CC=1 SCAR=0.0
44 2 ▶my sub VERTICES { { name => 'vertices', isa => ArrayRef [Vertex], args( @_ ) } }
Subroutine VERTICES: called CC=1 SCAR=0.0
45 4 ▶my sub XPOS { { name => undef, isa => XPosition, args( @_ ) } }
Subroutine XPOS: called CC=1 SCAR=0.0
46 4 ▶my sub YPOS { { name => undef, isa => YPosition, args( @_ ) } }
Subroutine YPOS: called CC=1 SCAR=0.0
47  
48 2 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 our @EXPORT_OK = ( 'mkregion' );
50  
51 # my sub REGION ( $name, $params ) { $Region{$name} = $params }
52 2 my $stash = Package::Stash->new( __PACKAGE__ );
53  
54 24 ▶my sub REGION ( $region, %spec ) {
Subroutine REGION: called CC=1 SCAR=0.0
55  
56 24 my $variant = Variant( $region, %spec );
57 24 Package::Stash->new( $variant )->add_symbol( q{@CARP_NOT}, [__PACKAGE__] );
58  
59 24 ▶ $stash->add_symbol( q{&} . $region, sub { $variant->new( @_ ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
60 24 push @EXPORT_OK, $region;
61 }
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73 # |-----------|-----------------------------------------------------|
74 # | ANNULUS | (xcenter,ycenter,iradius,oradius) |
75 # |-----------|-----------------------------------------------------|
76 2 REGION annulus => ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ) ], );
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88 # |-----------|-----------------------------------------------------|
89 # | BOX | (xcenter,ycenter,width,height) |
90 # | BOX | (xcenter,ycenter,width,height,angle) |
91 # |-----------|-----------------------------------------------------|
92 2 REGION box => (
93 params => [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE( required => !!0 ) ],
94 );
95  
96  
97  
98  
99  
100  
101  
102 # |-----------|-----------------------------------------------------|
103 # | CIRcle | (xcenter,ycenter,radius) |
104 # |-----------|-----------------------------------------------------|
105 2 REGION circle => ( params => [ VERTEX( 'center' ), LENGTH( 'radius' ) ], );
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117 # |-----------|-----------------------------------------------------|
118 # | ELLipse | (xcenter,ycenter,xradius,yradius,angle) |
119 # |-----------|-----------------------------------------------------|
120 2 REGION ellipse =>
121 ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ), ANGLE( default => 0 ) ], );
122  
123  
124  
125  
126  
127  
128  
129  
130  
131 # |-----------|-----------------------------------------------------|
132 # | FIELD | () |
133 # -------------------------------------------------------------------
134 2 REGION field => ( params => [], );
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146 # |-----------|-----------------------------------------------------|
147 # | PIE | (xcenter,ycenter,iradius,oradius,minangle,maxangle) |
148 # |-----------|-----------------------------------------------------|
149 2 REGION pie => ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ), ANGLEPAIR, ], );
150  
151  
152  
153  
154  
155  
156  
157  
158  
159 # |-----------|-----------------------------------------------------|
160 # | POInt | (xcenter,ycenter) |
161 # |-----------|-----------------------------------------------------|
162 2 REGION point => ( params => [ VERTEX( 'center' ) ], );
163  
164  
165  
166  
167  
168  
169  
170  
171  
172 # |-----------|-----------------------------------------------------|
173 # | POLYgon | (x1,y1,x2,y2,x3,y3,...) |
174 # |-----------|-----------------------------------------------------|
175 2 REGION polygon => ( params => [VERTICES], );
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186 # |-----------|-----------------------------------------------------|
187 # | RECTangle | (xmin,ymin,xmax,ymax) |
188 # |-----------|-----------------------------------------------------|
189 2 REGION rectangle =>
190 ( params => [ XPOS( 'xmin' ), YPOS( 'ymin' ), XPOS( 'xmax' ), YPOS( 'ymax' ) ], );
191  
192  
193  
194  
195  
196  
197  
198  
199  
200 # |-----------|-----------------------------------------------------|
201 # | REGION | (file) |
202 # |-----------|-----------------------------------------------------|
203 2 REGION region => ( params => [ STRING( 'file' ) ], );
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215 # |-----------|-----------------------------------------------------|
216 # | ROTBOX | (xcenter,ycenter,width,height,angle) |
217 # |-----------|-----------------------------------------------------|
218 2 REGION rotbox =>
219 ( params => [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE ], );
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231 # |-----------|-----------------------------------------------------|
232 # | SECTor | (xcenter,ycenter,minangle,maxangle) |
233 # |-----------|-----------------------------------------------------|
234 2 REGION sector => ( params => [ VERTEX( 'center' ), ANGLEPAIR, ], );
235  
236 # No longer need this; clean it up.
237 2 undef $stash;
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248 1 ▶sub mkregion ( $shape, @args ) {
Subroutine mkregion: called CC=2 SCAR=7.1
Pod documented
249 1 my $class = pkgpath( $shape );
250 1 ▶ my $new = $class->can( 'new' ) // croak( "unknown region: $shape" );
Condition50%1/2
$class->can("new") // croak("unknown region: $shape")
l!l
10
MC/DC0%0/1
$class->can("new") // croak("unknown region: $shape")
$class->can("new")
Truth table50%1/2
A
A= $class->can("new")
Aresult
11
00
251 1 $class->$new( @args );
252 }
253  
254 2 1;
255  
256 #
257 # This file is part of CXC-Astro-Regions
258 #
259 # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory.
260 #
261 # This is free software, licensed under:
262 #
263 # The GNU General Public License, Version 3, June 2007
264 #
265  
266 __END__
« Regions/DS9/Types.pm ↑ Summary Regions.pm »