blib/lib/CXC/Astro/Regions/CIAO.pm

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