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

filter: Statementstmt 94.4% 68 / 72 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 95.8% 23 / 24 Podpod 100% 1 / 1 totaltotal 86.8% 99 / 114 CC 6 SCAR 5.2
CC
6
Cov
89%
REGION
4.6
mkregion
2.1
args
2.0
CRAP 1.7
« blib/lib/CXC/Astro/Regions/DS9.pm ↑ Summary blib/lib/CXC/Astro/Regions/CIAO.pm »
1 package CXC::Astro::Regions::CFITSIO;
2  
3 # ABSTRACT: CFITSIO 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::CFITSIO::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::CFITSIO::Variant;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 package CXC::Astro::Regions::CFITSIO::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 23 join q{::}, __PACKAGE__, map { ucfirst( $_ ) } @paths;
36 }
37  
38 ▶my sub args ( @args ) {
Subroutine args: called CC=2 SCAR=6.9
39 60 ▶ return @args == 1 ? ( name => $args[0] ) : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 46 14 60
40 }
41  
42 8 ▶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 8 ▶my sub LENGTHPAIR { { name => undef, isa => Tuple [ Length, Length ], args( @_ ) } }
Subroutine LENGTHPAIR: called CC=1 SCAR=0.0
46 0 ▶my sub STRING { { name => undef, isa => NonEmptyStr, args( @_ ) } }
Subroutine STRING: not called CC=1 SCAR=6.9
47 20 ▶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 22 ▶ $spec{with} //= [RegionRole];
Condition50%1/2
$spec{"with"} //= ["CXC::Astro::Regions::CFITSIO::Role::Region"]
l!l
022
MC/DC0%0/1
$spec{"with"} //= ["CXC::Astro::Regions::CFITSIO::Role::Region"]
$spec{"with"}
Truth table50%1/2
A
A= $spec{"with"}
Aresult
11
00
61 22 my $package = pkgpath( $region );
62  
63 22 ▶ if ( exists $spec{name} && $spec{name} ne $region ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec{"name"} and $spec{"name"} ne $region) 0 22 22
Condition66%2/3
exists $spec{"name"} and $spec{"name"} ne $region
!ll&&!rl&&r
1840
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 22 my $variant = Variant( $region, %spec );
70 22 Package::Stash->new( $variant )->add_symbol( q{@CARP_NOT}, [__PACKAGE__] );
71  
72 22 ▶ $stash->add_symbol( q{&} . $region, sub { $package->new( @_ ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
73 22 push @EXPORT_OK, $region;
74 }
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86 # Annulus ( Xc, Yc, Rin, Rout )
87 2 REGION annulus => (
88 name => 'annulus',
89 params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ) ],
90 );
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102 # Box ( Xc, Yc, Wdth, Hght, A ) V within the region
103 2 REGION box => (
104 name => 'box',
105 params => [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE( default => 0 ) ],
106 );
107  
108  
109  
110  
111  
112  
113  
114 # Circle ( Xc, Yc, R )
115 2 REGION circle => ( params => [ VERTEX( 'center' ), LENGTH( 'radius' ) ], );
116  
117  
118  
119  
120  
121  
122  
123  
124 # Diamond ( Xc, Yc, Wdth, Hght, A )
125 2 REGION diamond =>
126 ( params => [ VERTEX( 'center' ), LENGTH( 'width' ), LENGTH( 'height' ), ANGLE( default => 0 ) ],
127 );
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139 # Ellipse ( Xc, Yc, Rx, Ry, A )
140 2 REGION ellipse =>
141 ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'radii' ), ANGLE( default => 0 ) ], );
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154 # Elliptannulus ( Xc, Yc, Rinx, Riny, Routx, Routy, Ain, Aout )
155 2 REGION elliptannulus =>
156 ( params => [ VERTEX( 'center' ), LENGTHPAIR( 'inner' ), LENGTHPAIR( 'outer' ), ANGLEPAIR ], );
157  
158  
159  
160  
161  
162  
163  
164  
165 # Line ( X1, Y1, X2, Y2 )
166 2 REGION line => ( params => [ VERTEX( 'v1' ), VERTEX( 'v2' ) ], );
167  
168  
169  
170  
171  
172  
173  
174  
175  
176 # Point ( X1, Y1 )
177 2 REGION point => ( params => [ VERTEX( 'center' ) ], );
178  
179  
180  
181  
182  
183  
184  
185  
186  
187 # Polygon ( X1, Y1, X2, Y2, ... )
188 2 REGION polygon => ( params => [VERTICES], );
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200 # Rectangle ( X1, Y1, X2, Y2, A )
201 2 REGION rectangle => (
202 params => [ XPOS( 'xmin' ), YPOS( 'ymin' ), XPOS( 'xmax' ), YPOS( 'ymax' ), ANGLE( default => 0 ) ],
203 );
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214 # Sector ( Xc, Yc, Amin, Amax )
215 2 REGION sector => ( params => [ VERTEX( 'center' ), ANGLEPAIR, ], );
216  
217 # No longer need this; clean it up.
218 2 undef $stash;
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229 ▶sub mkregion ( $shape, @args ) {
Subroutine mkregion: called CC=2 SCAR=7.6
Pod documented
230 1 my $class = pkgpath( $shape );
231 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
232 1 $class->$new( @args );
233 }
234  
235 2 1;
236  
237 #
238 # This file is part of CXC-Astro-Regions
239 #
240 # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory.
241 #
242 # This is free software, licensed under:
243 #
244 # The GNU General Public License, Version 3, June 2007
245 #
246  
247 __END__
« blib/lib/CXC/Astro/Regions/DS9.pm ↑ Summary blib/lib/CXC/Astro/Regions/CIAO.pm »