blib/lib/Astro/App/Satpass2.pm

filter: Statementstmt 73.6% 2162 / 2935 Branchbran 51.4% 767 / 1490 Conditioncond 42.0% 200 / 476 MC/DCmcdc 20.7% 59 / 285 Subroutinesub 79.3% 342 / 431 Podpod 93.6% 59 / 63 totaltotal 63.1% 3589 / 5680 CC 1006 SCAR 38.1
CC
1006
Cov
64%
spacetrack
380.0
save
293.6
_sky_sub_class
272.0
CRAP 45.3
↑ Summary blib/lib/Astro/App/Satpass2/ParseTime/Date/Manip/v5.pm »
1 package Astro::App::Satpass2;
2  
3 20 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use Astro::App::Satpass2::Locale qw{ __localize };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use Astro::App::Satpass2::Macro::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use Astro::App::Satpass2::Macro::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 20 ▶use Astro::App::Satpass2::ParseTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 20 ▶use Astro::App::Satpass2::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
13 :os
14 :ref
15 __arguments __legal_options
16 expand_tilde find_package_pod
17 has_method instance load_package
18 my_dist_config quoter
19 __parse_class_and_args
20 20 };
21  
22 20 ▶use Astro::Coord::ECI 0.077; # This needs at least 0.049.
Subroutine BEGIN: called CC=1 SCAR=0.0
23 20 ▶use Astro::Coord::ECI::Moon 0.077;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 20 ▶use Astro::Coord::ECI::Star 0.077;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 20 ▶use Astro::Coord::ECI::Sun 0.077;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 20 ▶use Astro::Coord::ECI::TLE 0.077 qw{:constants}; # This needs at least 0.059.
Subroutine BEGIN: called CC=1 SCAR=0.0
27 20 ▶use Astro::Coord::ECI::TLE::Set 0.077;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 # The following includes @CARP_NOT.
29 20 ▶use Astro::Coord::ECI::Utils 0.112 qw{ :all }; # This needs at least 0.112.
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 {
32 20 local $@ = undef;
33 20 ▶ use constant HAVE_TLE_IRIDIUM => eval {
Subroutine BEGIN: called CC=2 SCAR=7.9
Condition50%1/2
eval { do { require Astro::Coord::ECI::TLE::Iridium; 'Astro::Coord::ECI::TLE::Iridium'->VERSION(0.077); 1 } } || 0
l!l
020
MC/DC0%0/1
eval { do { require Astro::Coord::ECI::TLE::Iridium; 'Astro::Coord::ECI::TLE::Iridium'->VERSION(0.077); 1 } } || 0
eval { do { require Astro::Coord::ECI::TLE::Iridium; 'Astro::Coord::ECI::TLE::Iridium'->VERSION(0.077); 1 } }
Truth table50%1/2
A
A= eval { do { require Astro::Coord::ECI::TLE::Iridium; 'Astro::Coord::ECI::TLE::Iridium'->VERSION(0.077); 1 } }
Aresult
11
00
34 20 require Astro::Coord::ECI::TLE::Iridium;
35 0 Astro::Coord::ECI::TLE::Iridium->VERSION( 0.077 );
36 0 1;
37 20 } || 0;
38 # Unfortunately the alias code creates the alias even if the version
39 # is unacceptable; so we may have to just delete the Iridium aliases
40 20 unless( HAVE_TLE_IRIDIUM ) {
41 20 my %type_map = Astro::Coord::ECI::TLE->alias();
42 20 foreach my $name ( keys %type_map ) {
43 60 ▶ $type_map{$name} eq 'Astro::Coord::ECI::TLE::Iridium'
Branch: 1 branch
BranchTrueFalseTotal
$type_map{$name} eq "Astro::Coord::ECI::TLE::Iridium" and "Astro::Coord::ECI::TLE"->alias($name, undef) 0 60 60
44 and Astro::Coord::ECI::TLE->alias( $name, undef );
45 }
46 }
47 }
48  
49 20 ▶use Attribute::Handlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 20 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
51 20 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
52 20 ▶use File::Glob qw{ :glob };
Subroutine BEGIN: called CC=1 SCAR=0.0
53 20 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 20 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 20 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 20 ▶use Getopt::Long 2.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 20 ▶use IO::File 1.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 20 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 20 ▶use POSIX qw{ floor };
Subroutine BEGIN: called CC=1 SCAR=0.0
60 20 ▶use Scalar::Util 1.26 qw{ blessed isdual openhandle };
Subroutine BEGIN: called CC=1 SCAR=0.0
61 20 ▶use Text::Abbrev;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 20 ▶use Text::ParseWords (); # Used only for {level1} stuff.
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 20 ▶use constant ASTRO_SPACETRACK_VERSION => 0.105;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 # The following scavenged from
66 # Term::ReadLine::Perl 1.0303
67 20 ▶use constant DEFAULT_COMPLETER_WORD_BREAK_CHARACTERS =>
Subroutine BEGIN: called CC=1 SCAR=0.0
68 20 qr-[\\\t\n' \"`\@\$><=;|&{(]+-; # )}
69 20 ▶use constant DEFAULT_STDOUT_LAYERS => ':encoding(utf-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 20 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=13.3
72 eval {
73 20 ▶ load_package( 'Time::y2038' )
Branch: 1 branch
BranchTrueFalseTotal
load_package("Time::y2038") and "Time::y2038"->import 0 20 20
74 and Time::y2038->import();
75 20 1;
76 }
77 20 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { load_package("Time::y2038") and "Time::y2038"->import; 1 } } or do { require Time::Local; "Time::Local"->import } 20 0 20
78 0 require Time::Local;
79 0 Time::Local->import();
80 };
81 }
82  
83 # The following is returned by method _attribute_value() when a
84 # non-existent attribute is specified. We can't use undef for this,
85 # because the attribute might really be undef.
86 # NOTE that this used to be just bless \( $x = undef ) ..., but blead
87 # Perl 6a011f13d7690dbe2e03ad7500756c983bcb1834 did not like this
88 # (modificatoin of read-only variable).
89 20 ▶use constant NULL => do {
Subroutine BEGIN: called CC=1 SCAR=0.0
90 20 my $x = undef;
91 20 bless \$x, 'Null';
92 20 };
93 # The canonical way to see if $rslt actually contains the above is
94 # NULL_REF eq ref $rslt
95 20 ▶use constant NULL_REF => ref NULL;
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 20 ▶use constant SUN_CLASS_DEFAULT => 'Astro::Coord::ECI::Sun';
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 20 our $VERSION = '0.059';
100  
101 # The following 'cute' code is so that we do not determine whether we
102 # actually have optional modules until we really need them, and yet do
103 # not repeat the process once it is done.
104  
105 20 my $have_time_hires;
106 1 ▶$have_time_hires = sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
107 1 my $value = load_package( 'Time::HiRes' );
108 0 ▶ $have_time_hires = sub { return $value };
Subroutine __ANON__: not called CC=1 SCAR=1.2
109 1 return $value;
110 20 };
111  
112 20 my $have_astro_spacetrack;
113 20 ▶$have_astro_spacetrack = sub {
Subroutine __ANON__: called CC=2 SCAR=8.5
114 20 ▶ my $value = load_package( { lib => undef }, 'Astro::SpaceTrack' ) && eval {
Condition33%1/3
load_package({'lib', undef}, 'Astro::SpaceTrack') && eval { do { 'Astro::SpaceTrack'->VERSION(0.105); 1 } }
!ll&&!rl&&r
2000
MC/DC0%0/2
load_package({'lib', undef}, 'Astro::SpaceTrack') && eval { do { 'Astro::SpaceTrack'->VERSION(0.105); 1 } }
load_package({'lib', undef}, 'Astro::SpaceTrack') eval { do { 'Astro::SpaceTrack'->VERSION(0.105); 1 } }
Truth table33%1/3
A && B
A= load_package({'lib', undef}, 'Astro::SpaceTrack')B= eval { do { 'Astro::SpaceTrack'->VERSION(0.105); 1 } }
ABresult
0X0
100
111
115 0 Astro::SpaceTrack->VERSION( ASTRO_SPACETRACK_VERSION );
116 0 1;
117 };
118 20 ▶ $have_astro_spacetrack = sub { $value };
Subroutine __ANON__: called CC=1 SCAR=0.0
119 20 return $value;
120 20 };
121  
122 20 my $default_geocoder;
123 0 ▶$default_geocoder = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 0 my $value =
125 _can_use_geocoder( 'Astro::App::Satpass2::Geocode::OSM'
126 );
127 0 ▶ $default_geocoder = sub { return $value };
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 0 return $value;
129 20 };
130  
131 0 ▶sub _can_use_geocoder {
Subroutine _can_use_geocoder: not called CC=3 SCAR=24.8
132 0 my ( $geocoder ) = @_;
133 0 ▶ my $pkg = load_package( $geocoder )
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = load_package($geocoder) or return 0 0 0
134 or return;
135 0 ▶ load_package( $pkg->GEOCODER_CLASS() )
Branch: 1 branch
BranchTrueFalseTotal
load_package($pkg->GEOCODER_CLASS) or return 0 0 0
136 or return;
137 0 return $pkg;
138 }
139  
140 20 my $interrupted = 'Interrupted by user.';
141  
142 20 my %twilight_def = (
143 civil => deg2rad (-6),
144 nautical => deg2rad (-12),
145 astronomical => deg2rad (-18),
146 );
147 20 my %twilight_abbr = abbrev (keys %twilight_def);
148  
149 # Individual commands are defined by subroutines of the same name,
150 # and having the Verb attribute. You can specify additional
151 # attributes if you need to. Following are descriptions of the
152 # attributes used by this script.
153 #
154 # Configure(configurations)
155 #
156 # The 'Configure' attribute specifies options to be passed to
157 # Getopt::Long::Configure before the options are parsed. For
158 # example, if a command wants to keep unrecognized options on the
159 # command you would specify:
160 # sub foo : Configure(pass_through) Verb
161 #
162 # Tokenize(options)
163 #
164 # The 'Tokenize' attribute specifies tokenizatino options. These
165 # can not take effect until fairly late in the parse when the
166 # tokens are known. These options are parsed by Getopt::Long, and
167 # the value of the attribute is a reference to the options hash
168 # thus generated. Possible options are:
169 # -expand_tilde - Expand tildes in the tokens. For historical
170 # reasons this is the default, but it can be negated by
171 # specifying -noexpand_tilde. Tildes in redirect
172 # specifications are always expanded.
173 #
174 # Tweak(options)
175 #
176 # The 'Tweak' attribute specifies miscellaneous tweaks to
177 # subroutine usage. Possible options are:
178 # -unsatisfied - Execute even inside an unsatisfied if().
179 # Subroutines with this attribute may have to be aware
180 # that they are being called within the scope of an
181 # unsatisfied if(). All interactive methods that must be
182 # called even inside an unsatisfied if() MUST have this
183 # attribute. These are begin() and end(), and anything
184 # that might dispatch either of these. At the moment this
185 # means if() and time().
186 # -completion - Requires as argument the name of the command
187 # completion method. This can not be checked at compile
188 # time. It will be called with the following arguments:
189 # $code - the relevant code reference
190 # $text - the text being completed
191 # $line - the line being completed
192 # $start - the current position in the line.
193 # It should return either a reference to an array
194 # containing possible completions, or nothing to fall
195 # through to standard completion
196 #
197 # Verb(options)
198 #
199 # The 'Verb' attribute identifies the subroutine as representing a
200 # cvsx command. If it has options, they should be specified inside
201 # parentheses as a whitespace-separated list of option
202 # specifications appropriate for Getopt::Long. For example:
203 # sub foo : Verb(bar baz=s)
204 # specifies that 'foo' is a command, taking options -bar, and
205 # -baz; the latter takes a string value.
206  
207 {
208 20 my %attr;
209  
210 0 ▶ sub Configure : ATTR(CODE,RAWDATA) {
Subroutine Configure: not called CC=1 SCAR=6.9
Pod undocumented
211 0 my ( undef, undef, $code, $name, $data ) = @_;
212 0 $attr{$code}{$name} = _attr_list( $data );
213 0 return;
214 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
215  
216 20 ▶ sub Tokenize : ATTR(CODE,RAWDATA) {
Subroutine Tokenize: called CC=2 SCAR=7.0
Pod undocumented
217 20 my ( undef, undef, $code, $name, $data ) = @_;
218 20 my $opt = _attr_hash( $name, $data, qw{ expand_tilde|expand-tilde! } );
219 exists $opt->{expand_tilde}
220 20 ▶ or $opt->{expand_tilde} = 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"expand_tilde"} or $opt->{"expand_tilde"} = 1 20 0 20
221 20 $attr{$code}{$name} = $opt;
222 20 return;
223 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
224  
225 300 ▶ sub Tweak : ATTR(CODE,RAWDATA) {
Subroutine Tweak: called CC=1 SCAR=0.0
Pod undocumented
226 300 my ( undef, undef, $code, $name, $data ) = @_;
227 300 $attr{$code}{$name} = _attr_hash( $name, $data,
228 qw{ completion=s unsatisfied! } );
229 300 return;
230 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
231  
232 1305 ▶ sub Verb : ATTR(CODE,RAWDATA) {
Subroutine Verb: called CC=1 SCAR=0.0
Pod undocumented
233 1305 my ( undef, undef, $code, $name, $data ) = @_;
234 1305 $attr{$code}{$name} = _attr_list( $data );
235 1305 return;
236 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
237  
238 320 ▶ sub _attr_hash {
Subroutine _attr_hash: called CC=2 SCAR=7.6
239 320 my ( $name, $arg, @legal ) = @_;
240 320 my $gol = Getopt::Long::Parser->new();
241 320 my %opt;
242 $gol->getoptionsfromarray(
243 _attr_list( $arg ),
244 \%opt,
245 @legal,
246 320 ▶ ) or do {
Branch: 1 branch
BranchTrueFalseTotal
$gol->getoptionsfromarray(_attr_list($arg), \%opt, @legal) or do { require Carp; Carp::croak("Bad $name option") } 320 0 320
247 0 require Carp;
248 0 Carp::croak( "Bad $name option" );
249 };
250 320 return \%opt;
251 }
252  
253 1625 ▶ sub _attr_list {
Subroutine _attr_list: called CC=2 SCAR=7.1
254 1625 ▶ defined( local $_ = $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
defined(local $_ = $_[0]) or return [] 1625 0 1625
255 or return [];
256 1625 s/ \A \s+ //smx;
257 1625 return [ split qr< \s+ >smx ];
258 }
259  
260 1778 ▶ sub __get_attr {
Subroutine __get_attr: called CC=4 SCAR=14.1
261 1778 my ( undef, $code, $name, $dflt ) = @_; # $pkg unused
262 1778 ▶ defined $code
Branch: 1 branch
BranchTrueFalseTotal
defined $code or return \%attr 1778 0 1778
263 or return \%attr;
264 defined $name
265 1778 ▶ or return $attr{$code};
Branch: 1 branch
BranchTrueFalseTotal
defined $name or return $attr{$code} 1778 0 1778
266 exists $attr{$code}{$name}
267 1778 ▶ and return $attr{$code}{$name};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr{$code}{$name} and return $attr{$code}{$name} 763 1015 1778
268 1015 return $dflt;
269 }
270 }
271  
272 20 my %mutator = (
273 almanac_horizon => \&_set_almanac_horizon,
274 appulse => \&_set_angle,
275 autoheight => \&_set_unmodified,
276 backdate => \&_set_unmodified,
277 background => \&_set_unmodified,
278 continuation_prompt => \&_set_unmodified,
279 country => \&_set_unmodified,
280 date_format => \&_set_formatter_attribute,
281 desired_equinox_dynamical => \&_set_formatter_attribute,
282 debug => \&_set_unmodified,
283 echo => \&_set_unmodified,
284 edge_of_earths_shadow => \&_set_unmodified,
285 ellipsoid => \&_set_ellipsoid,
286 error_out => \&_set_unmodified,
287 events => \&_set_unmodified,
288 exact_event => \&_set_unmodified,
289 execute_filter => \&_set_code_ref, # Undocumented and unsupported
290 explicit_macro_delete => \&_set_unmodified,
291 extinction => \&_set_unmodified,
292 filter => \&_set_unmodified,
293 flare_mag_day => \&_set_unmodified,
294 flare_mag_night => \&_set_unmodified,
295 formatter => \&_set_formatter,
296 geocoder => \&_set_geocoder,
297 geometric => \&_set_unmodified,
298 gmt => \&_set_formatter_attribute,
299 height => \&_set_distance_meters,
300 horizon => \&_set_angle,
301 illum => \&_set_illum_class,
302 latitude => \&_set_angle_or_undef,
303 local_coord => \&_set_formatter_attribute,
304 location => \&_set_unmodified,
305 longitude => \&_set_angle_or_undef,
306 model => \&_set_model,
307 max_mirror_angle => \&_set_angle,
308 output_layers => \&_set_output_layers,
309 pass_threshold => \&_set_angle_or_undef,
310 pass_variant => \&_set_pass_variant,
311 perltime => \&_set_time_parser_attribute,
312 prompt => \&_set_unmodified,
313 refraction => \&_set_unmodified,
314 simbad_url => \&_set_unmodified,
315 singleton => \&_set_unmodified,
316 spacetrack => \&_set_spacetrack,
317 stdout => \&_set_stdout,
318 sun => \&_set_sun_class, # Only in {level1}
319 time_format => \&_set_formatter_attribute,
320 time_formatter => \&_set_formatter_attribute,
321 time_parser => \&_set_time_parser,
322 ## timing => \&_set_unmodified,
323 twilight => \&_set_twilight, # 'civil', 'nautical', 'astronomical'
324 # (or a unique abbreviation thereof),
325 # or degrees above (positive) or below
326 # (negative) the geometric horizon.
327 tz => \&_set_tz,
328 verbose => \&_set_unmodified, # 0 = events only
329 # 1 = whenever above horizon
330 # 2 = anytime
331 visible => \&_set_unmodified, # 1 = only if sun down & sat illuminated
332 warning => \&_set_warner_attribute, # True to warn/die; false to carp/croak.
333 warn_on_empty => \&_set_unmodified,
334 # True to have list commands warn on
335 # an empty list.
336 webcmd => \&_set_webcmd, # Command to spawn for web pages
337 );
338  
339 20 my %accessor = (
340 date_format => \&_get_formatter_attribute,
341 desired_equinox_dynamical => \&_get_formatter_attribute,
342 geocoder => \&_get_geocoder,
343 gmt => \&_get_formatter_attribute,
344 local_coord => \&_get_formatter_attribute,
345 perltime => \&_get_time_parser_attribute,
346 spacetrack => \&_get_spacetrack,
347 time_format => \&_get_formatter_attribute,
348 time_formatter => \&_get_formatter_attribute,
349 tz => \&_get_time_parser_attribute,
350 warning => \&_get_warner_attribute,
351 );
352  
353 20 foreach ( keys %mutator, qw{ initfile } ) {
354 928 ▶ $accessor{$_} ||= sub { return $_[0]->{$_[1]} };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$accessor{$_} ||= sub { return $_[0]{$_[1]}; }
l!l&&r!l&&!r
2209200
MC/DC0%0/2
$accessor{$_} ||= sub { return $_[0]{$_[1]}; }
$accessor{$_} sub { return $_[0]{$_[1]}; }
Truth table66%2/3
A ||= B
A= $accessor{$_}B= sub { return $_[0]{$_[1]}; }
ABresult
1X1
011
000
355 }
356  
357 20 my %shower = (
358 date_format => \&_show_formatter_attribute,
359 desired_equinox_dynamical => \&_show_formatter_attribute,
360 formatter => \&_show_copyable,
361 geocoder => \&_show_copyable,
362 gmt => \&_show_formatter_attribute,
363 local_coord => \&_show_formatter_attribute,
364 pass_variant => \&_show_pass_variant,
365 sun => \&_show_sun_class, # only in {level1}
366 time_parser => \&_show_time_parser,
367 time_format => \&_show_formatter_attribute,
368 time_formatter => \&_show_formatter_attribute,
369 );
370 20 ▶foreach ( keys %accessor ) { $shower{$_} ||= \&_show_unmodified }
Condition100%2/2
$shower{$_} ||= \&Astro::App::Satpass2::_show_unmodified
l!l
220920
MC/DC100%1/1
$shower{$_} ||= \&Astro::App::Satpass2::_show_unmodified
$shower{$_}
Truth table100%2/2
A
A= $shower{$_}
Aresult
11
00
371  
372 # Attributes which must be set programmatically (i.e. not
373 # interactively or in the initialization file).
374  
375 20 my %nointeractive = map {$_ => 1} qw{
376 execute_filter
377 spacetrack
378 stdout
379 };
380  
381 # Initial object contents
382  
383 my %static = (
384 almanac_horizon => 0,
385 appulse => 0,
386 autoheight => 1,
387 background => 1,
388 backdate => 0,
389 continuation_prompt => '> ',
390 date_format => '%a %d-%b-%Y',
391 debug => 0,
392 echo => 0,
393 edge_of_earths_shadow => 1,
394 ellipsoid => Astro::Coord::ECI->get ('ellipsoid'),
395 error_out => 0,
396 events => 0,
397 exact_event => 1,
398 0 ▶ execute_filter => sub { return 1 }, # Undocumented and unsupported
Subroutine __ANON__: not called CC=1 SCAR=6.9
399 ## explicit_macro_delete => 1, # Deprecated
400 extinction => 1,
401 filter => 0,
402 flare_mag_day => -6,
403 flare_mag_night => 0,
404 formatter => 'Astro::App::Satpass2::Format::Template', # Formatter class.
405 ## geocoder => $default_geocoder->(), # Geocoder class set when accessed
406 geometric => 1,
407 height => undef, # meters
408 # initfile => undef, # Set by init()
409 horizon => 20, # degrees
410 illum => SUN_CLASS_DEFAULT,
411 latitude => undef, # degrees
412 longitude => undef, # degrees
413 max_mirror_angle => HAVE_TLE_IRIDIUM ? rad2deg(
414 Astro::Coord::ECI::TLE::Iridium->DEFAULT_MAX_MIRROR_ANGLE ) :
415 undef,
416 model => 'model',
417 # pending => undef, # Continued input line if it exists.
418 pass_variant => PASS_VARIANT_NONE,
419 perltime => 0,
420 prompt => 'satpass2> ',
421 refraction => 1,
422 simbad_url => 'simbad.u-strasbg.fr',
423 singleton => 0,
424 # spacetrack => undef, # Astro::SpaceTrack object set when accessed
425 # stdout => undef, # Set to stdout in new().
426 output_layers => DEFAULT_STDOUT_LAYERS,
427 time_parser => 'Astro::App::Satpass2::ParseTime', # Time parser class.
428 twilight => 'civil',
429 tz => $ENV{TZ},
430 20 verbose => 0,
431 visible => 1,
432 warning => 0,
433 warn_on_empty => 1,
434 webcmd => ''
435 );
436  
437 20 my %sky_class = (
438 fold_case( 'Sun' ) => [ SUN_CLASS_DEFAULT, name => 'Sun' ],
439 fold_case( 'Moon' ) => [ 'Astro::Coord::ECI::Moon', name => 'Moon' ],
440 # # The shape of things to come -- maybe
441 # # but commented out because Astro-App-Satpass2 does not depend on
442 # # these
443 # ( map { fold_case( $_ ) =>
444 # "Astro::Coord::ECI::VSOP87D::$_" } qw{ Mercury Venus
445 # Mars Jupiter Saturn Uranus Neptune } ),
446 );
447  
448 7 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
449 7 my ( $class, %args ) = @_;
450 7 ▶ ref $class and $class = ref $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 7 7
451 7 my $self = {};
452 7 $self->{bodies} = [];
453 7 $self->{macro} = {};
454 $self->{sky} = [
455 7 SUN_CLASS_DEFAULT->new (),
456 Astro::Coord::ECI::Moon->new (),
457 ];
458 7 $self->{sky_class} = { %sky_class };
459 $self->{_help_module} = {
460 7 '' => __PACKAGE__,
461 eci => 'Astro::Coord::ECI',
462 moon => 'Astro::Coord::ECI::Moon',
463 set => 'Astro::Coord::ECI::TLE::Set',
464 sun => SUN_CLASS_DEFAULT,
465 spacetrack => 'Astro::SpaceTrack',
466 star => 'Astro::Coord::ECI::Star',
467 tle => 'Astro::Coord::ECI::TLE',
468 utils => 'Astro::Coord::ECI::Utils',
469 };
470 HAVE_TLE_IRIDIUM
471 7 and $self->{_help_module}{iridium} = 'Astro::Coord::ECI::TLE::Iridium';
472 7 bless $self, $class;
473 7 $self->_frame_push(initial => []);
474 7 $self->set(stdout => select());
475  
476 7 foreach my $name ( keys %static ) {
477 301 ▶ exists $args{$name} or $args{$name} = $static{$name};
Branch: 1 branch
BranchTrueFalseTotal
exists $args{$name} or $args{$name} = $static{$name} 0 301 301
478 }
479  
480 $self->{_warner} = Astro::App::Satpass2::Warner->new(
481 warning => delete $args{warning}
482 7 );
483  
484 7 foreach my $name ( qw{ formatter time_parser } ) {
485 14 $self->set( $name => delete $args{$name} );
486 }
487  
488 7 $self->set( %args );
489  
490 7 return $self;
491 }
492  
493 1 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod documented
494 1 my ( $self, @bodies ) = @_;
495 1 foreach my $body ( @bodies ) {
496 1 ▶ embodies( $body, 'Astro::Coord::ECI::TLE' )
Branch: 1 branch
BranchTrueFalseTotal
embodies($body, "Astro::Coord::ECI::TLE") or $self->wail("Arguments must represent Astro::Coord::ECI::TLE objects") 1 0 1
497 or $self->wail(
498 'Arguments must represent Astro::Coord::ECI::TLE objects' );
499 }
500 1 push @{ $self->{bodies} }, @bodies;
501 1 return $self;
502 }
503  
504 5 ▶sub alias : Verb() {
Subroutine alias: called CC=3 SCAR=11.0
Pod documented
505 5 my ( undef, undef, @args ) = __arguments( @_ ); # Invocant, $opt unused
506  
507 5 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 2 3 5
508 2 Astro::Coord::ECI::TLE->alias( @args );
509 2 return;
510 } else {
511 3 my $output;
512 3 my %alias = Astro::Coord::ECI::TLE->alias();
513 3 foreach my $key ( sort keys %alias ) {
514 10 $output .= join( ' ', 'alias', $key, $alias{$key} ) . "\n";
515 }
516 3 return $output;
517 }
518 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
519  
520 # Attributes must all be on one line to process correctly under Perl
521 # 5.8.8.
522 3 ▶sub almanac : Verb( choose=s@ dump! horizon|rise|set! transit! twilight! quarter! ) {
Subroutine almanac: called CC=6 SCAR=18.5
Pod documented
523 3 my ( $self, $opt, @args ) = __arguments( @_ );
524 3 $self->_apply_boolean_default(
525 $opt, 0, qw{ horizon transit twilight quarter } );
526  
527 3 my $almanac_start = $self->__parse_time(
528 shift @args, $self->_get_day_midnight());
529 3 ▶ my $almanac_end = $self->__parse_time (shift @args || '+1');
Condition50%1/2
shift @args || '+1'
l!l
03
MC/DC0%0/1
shift @args || '+1'
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
530  
531 3 ▶ $almanac_start >= $almanac_end
Branch: 1 branch
BranchTrueFalseTotal
$almanac_start >= $almanac_end and $self->wail("End time must be after start time") 0 3 3
532 and $self->wail( 'End time must be after start time' );
533  
534 # Build an object representing our ground location.
535  
536 3 my $sta = $self->station();
537  
538 3 my @almanac;
539  
540 # Iterate through the background bodies, accumulating data or
541 # complaining about the lack of an almanac() method as
542 # appropriate.
543  
544 my @sky = $self->__choose( $opt->{choose}, $self->{sky} )
545 3 ▶ or return $self->__wail( 'No bodies selected' );
Branch: 1 branch
BranchTrueFalseTotal
my(@sky) = $self->__choose($opt->{"choose"}, $self->{"sky"}) or return $self->__wail("No bodies selected") 3 0 3
546  
547 3 foreach my $body ( @sky ) {
548 6 ▶ $body->can ('almanac') or do {
Branch: 1 branch
BranchTrueFalseTotal
$body->can("almanac") or do { $self->whinge(ref $body, " does not support the almanac method"); next } 6 0 6
549 0 $self->whinge(
550 ref $body, ' does not support the almanac method');
551 0 next;
552 };
553 $body->set (
554 station => $sta,
555 twilight => $self->{_twilight},
556 6 );
557 6 push @almanac, $body->almanac_hash(
558 $almanac_start, $almanac_end);
559 }
560  
561 # Record number of events found
562  
563 3 @almanac = grep { $opt->{$_->{almanac}{event}} } @almanac;
564 3 $self->{events} += @almanac;
565  
566 # Localize the event descriptions if appropriate.
567  
568 3 _almanac_localize( @almanac );
569  
570 # Sort the almanac data by date, and display the results.
571  
572 return $self->__format_data(
573 almanac => [
574 3 sort { $a->{time} <=> $b->{time} }
575 @almanac
576 ], $opt );
577  
578 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
579 9 ▶sub _almanac_localize {
Subroutine _almanac_localize: called CC=2 SCAR=6.9
580 9 my @almanac = @_;
581 9 foreach my $event ( @almanac ) {
582 $event->{almanac}{description} = __localize(
583 text => [ almanac => $event->{body}->get( 'name' ),
584 $event->{almanac}{event}, $event->{almanac}{detail} ],
585 default => $event->{almanac}{description},
586 argument => $event->{body},
587 46 );
588 }
589 9 return;
590 }
591  
592 5 ▶sub begin : Verb() Tweak( -unsatisfied ) {
Subroutine begin: called CC=2 SCAR=7.0
Pod documented
593 5 my ( $self, $opt, @args ) = __arguments( @_ );
594 $self->_frame_push(
595 5 ▶ begin => @args ? \@args : $self->{frame}[-1]{args});
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 5 5
596 5 $self->{frame}[-1]{level1} = $opt->{level1};
597 5 return;
598 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
599  
600 # -level1 is UNSUPPORTED and may be removed without warning. It is only
601 # there for me to screw around with.
602 20 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
603 $ENV{SATPASS2_LEVEL1}
604 20 ▶ and __PACKAGE__->MODIFY_CODE_ATTRIBUTES(
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SATPASS2_LEVEL1"} and __PACKAGE__->MODIFY_CODE_ATTRIBUTES(\&Astro::App::Satpass2::begin, "Verb( level1! )") 0 20 20
605 \&begin,
606 'Verb( level1! )',
607 );
608 }
609  
610 2 ▶sub cd : Verb() {
Subroutine cd: called CC=4 SCAR=14.1
Pod documented
611 2 my ( $self, undef, $dir ) = __arguments( @_ ); # $opt unused
612 2 ▶ if (defined($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) { } 1 1 2
613 1 ▶ chdir $dir or $self->wail("Can not cd to $dir: $!");
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or $self->wail("Can not cd to ${dir}: $!") 1 0 1
614 } else {
615 1 ▶ chdir File::HomeDir->my_home()
Branch: 1 branch
BranchTrueFalseTotal
chdir "File::HomeDir"->my_home or $self->wail("Can not cd to home: $!") 1 0 1
616 or $self->wail("Can not cd to home: $!");
617 }
618 2 return;
619 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
620  
621 2 ▶sub choose : Verb( epoch=s ) {
Subroutine choose: called CC=4 SCAR=15.5
Pod documented
622 2 my ( $self, $opt, @args ) = __arguments( @_ );
623  
624 2 ▶ if ($opt->{epoch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"epoch"}) 0 2 2
625 0 my $epoch = $self->__parse_time($opt->{epoch});
626 $self->{bodies} = [
627 map {
628 0 $_->select($epoch);
629 }
630 $self->_aggregate( $self->{bodies} )
631 0 ];
632 }
633 2 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 2 0 2
634 2 ▶ my @bodies = @{ $self->__choose( \@args, $self->{bodies} ) }
Branch: 1 branch
BranchTrueFalseTotal
my(@bodies) = @{$self->__choose(\@args, $self->{"bodies"});} or return $self->__wail("No bodies chosen") 2 0 2
635 or return $self->__wail( 'No bodies chosen' );
636 2 @{ $self->{bodies} } = @bodies;
637 }
638 2 return;
639 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
640  
641 5 ▶sub clear : Verb() {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
642 5 my ( $self ) = __arguments( @_ ); # $opt, @args unused
643 5 @{$self->{bodies}} = ();
644 5 return;
645 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
646  
647 289 ▶sub dispatch {
Subroutine dispatch: called CC=12 SCAR=24.9
Pod documented
648 289 my ($self, $verb, @args) = @_;
649  
650 289 ▶ defined $verb or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $verb or return 289 0 289
651  
652 289 my $unsatisfied = $self->_in_unsatisfied_if();
653  
654 289 ▶ if ( $self->{macro}{$verb} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"macro"}{$verb}) 19 270 289
655 19 ▶ $unsatisfied
Branch: 1 branch
BranchTrueFalseTotal
$unsatisfied and return 0 19 19
656 and return;
657 19 return $self->_macro( $verb, @args );
658 }
659  
660 270 my $code;
661 270 $verb =~ s/ \A core [.] //smx;
662 270 ▶ $code = $self->can($verb)
Branch: 1 branch
BranchTrueFalseTotal
$code = $self->can($verb) and $self->__get_attr($code, "Verb") or $self->wail("Unknown interactive method '${verb}'") 269 1 270
Condition66%2/3
$code = $self->can($verb) and $self->__get_attr($code, "Verb")
!ll&&!rl&&r
10269
MC/DC50%1/2
$code = $self->can($verb) and $self->__get_attr($code, "Verb")
$code = $self->can($verb) $self->__get_attr($code, "Verb")
Truth table66%2/3
A and B
A= $code = $self->can($verb)B= $self->__get_attr($code, "Verb")
ABresult
0X0
100
111
663 and $self->__get_attr($code, 'Verb')
664 or $self->wail("Unknown interactive method '$verb'");
665  
666 269 my $rslt;
667 $unsatisfied
668 and not $self->__get_attr( $code, Tweak => {} )->{unsatisfied}
669 269 ▶ or $rslt = $code->( $self, @args );
Branch: 1 branch
BranchTrueFalseTotal
$unsatisfied and not $self->__get_attr($code, "Tweak", {})->{"unsatisfied"} or $rslt = &$code($self, @args) 12 257 269
Condition100%3/3
$unsatisfied and not $self->__get_attr($code, "Tweak", {})->{"unsatisfied"}
!ll&&!rl&&r
249812
MC/DC100%2/2
$unsatisfied and not $self->__get_attr($code, "Tweak", {})->{"unsatisfied"}
$unsatisfied not $self->__get_attr($code, "Tweak", {})->{"unsatisfied"}
Truth table100%3/3
A and not(B)
A= $unsatisfiedB= not $self->__get_attr($code, "Tweak", {})->{"unsatisfied"}
ABresult
0X0
100
111
670  
671 261 ▶ defined $rslt
Branch: 1 branch
BranchTrueFalseTotal
defined $rslt and $rslt =~ s/ (?<! \n ) \z /\n/msx 145 116 261
672 and $rslt =~ s/ (?<! \n ) \z /\n/smx;
673  
674 261 foreach my $code (
675 261 ▶ reverse @{ delete( $self->{frame}[-1]{post_dispatch} ) || [] }
Condition100%2/2
delete $self->{'frame'}[-1]{'post_dispatch'} || []
l!l
23238
MC/DC100%1/1
delete $self->{'frame'}[-1]{'post_dispatch'} || []
delete $self->{'frame'}[-1]{'post_dispatch'}
Truth table100%2/2
A
A= delete $self->{'frame'}[-1]{'post_dispatch'}
Aresult
11
00
676 ) {
677 23 my $append;
678 23 ▶ defined( $append = $code->( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
defined($append = &$code($self)) and $rslt .= $append 1 22 23
679 and $rslt .= $append;
680 }
681 261 return $rslt;
682 }
683  
684 {
685 my %special = (
686 4 ▶ begin => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
687 4 my ( $self, $verb ) = @_;
688 4 ▶ $self->_is_interactive()
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_interactive or $self->wail("'begin' forbidden in non-interactive $verb()") 4 0 4
689 or $self->wail(
690 "'begin' forbidden in non-interactive $verb()" );
691 4 return;
692 },
693 0 ▶ end => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
694 0 my ( $self, $verb ) = @_;
695 0 $self->wail( "'end' forbidden in $verb()" );
696 },
697 20 );
698  
699 23 ▶ sub _dispatch_check {
Subroutine _dispatch_check: called CC=2 SCAR=6.9
700 23 my ( $self, $verb, $disp ) = @_;
701 23 ▶ my $code = $special{$disp}
Branch: 1 branch
BranchTrueFalseTotal
my $code = $special{$disp} or return 4 19 23
702 or return;
703 4 return $code->( $self, $verb, $disp );
704 }
705 }
706  
707 20 ▶sub drop : Verb() {
Subroutine drop: called CC=3 SCAR=11.1
Pod documented
708 1 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
709  
710 @args
711 1 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
@args or return 1 0 1
712  
713 my @bodies = @{
714 1 ▶ $self->__choose( { invert => 1 }, \@args, $self->{bodies} ) }
Branch: 1 branch
BranchTrueFalseTotal
my(@bodies) = @{$self->__choose({"invert", 1}, \@args, $self->{"bodies"});} or return $self->__wail("No bodies left") 1 0 1
715 or return $self->__wail( 'No bodies left' );
716  
717 1 @{ $self->{bodies} } = @bodies;
718  
719 1 return;
720 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
721  
722 0 ▶sub dump : method Verb() Tweak( -unsatisfied ) { ## no critic (ProhibitBuiltInHomonyms)
Subroutine dump: not called CC=8 SCAR=42.8
Pod documented
723 0 my ( $self, undef, @arg ) = __arguments( @_ ); # $opt unused
724  
725 0 local $self->{time_parser} = ref $self->{time_parser};
726  
727 0 my $dumper = $self->_get_dumper();
728  
729 @arg
730 0 ▶ or return $dumper->( $self );
Branch: 1 branch
BranchTrueFalseTotal
@arg or return &$dumper($self) 0 0 0
731  
732 0 local $_ = shift @arg;
733  
734 ref
735 0 ▶ and return $dumper->( $_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ and return &$dumper($_) 0 0 0
736  
737 m/ \A frames? \z /smxi
738 0 ▶ and return $dumper->( $self->{frame} );
Branch: 1 branch
BranchTrueFalseTotal
/ \A frames? \z /imsx and return &$dumper($self->{"frame"}) 0 0 0
739  
740 0 ▶ m/ \A tokens? \z /smxi
Branch: 1 branch
BranchTrueFalseTotal
/ \A tokens? \z /imsx and return &$dumper($self->__tokenize(@arg)) 0 0 0
741 and return $dumper->( $self->__tokenize( @arg ) );
742  
743 m/ \A twilight \z /smxi
744 and return $dumper->(
745 0 ▶ { map { $_ => $self->{$_} } qw{ twilight _twilight } } );
Branch: 1 branch
BranchTrueFalseTotal
/ \A twilight \z /imsx and return &$dumper({map({$_, $self->{$_};} "twilight", "_twilight")}) 0 0 0
746  
747 0 my @stuff = $self->__choose( [ $_ ], $self->{bodies} );
748 0 ▶ if ( defined( my $inx = $self->_find_in_sky( $_ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $inx = $self->_find_in_sky($_))) 0 0 0
749 0 push @stuff, $self->{sky}[$inx];
750 }
751 @stuff
752 0 ▶ and return $dumper->( @stuff );
Branch: 1 branch
BranchTrueFalseTotal
@stuff and return &$dumper(@stuff) 0 0 0
753  
754 0 $self->whinge( "Dump argument '$_' not recognized" );
755
756 0 return;
757 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
758  
759 44 ▶sub echo : Verb( n! ) {
Subroutine echo: called CC=2 SCAR=7.0
Pod documented
760 44 my ( undef, $opt, @args ) = __arguments( @_ ); # Invocant unused
761 44 my $output = join( ' ', @args );
762 44 ▶ $opt->{n} or $output .= "\n";
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"n"} or $output .= "\n" 0 44 44
763 44 return $output;
764 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
765  
766 2 ▶sub else : method Verb() Tweak( -unsatisfied ) { ## no critic (ProhibitBuiltInHomonyms)
Subroutine else: called CC=5 SCAR=18.9
Pod documented
767 2 my ( $self ) = __arguments( @_ ); # $opt, @args unused
768  
769 2 @{ $self->{frame} } > 1
770 and 'begin' eq $self->{frame}[-1]{type}
771 and 'if' eq $self->{frame}[-2]{type}
772 2 ▶ or $self->wail( 'Else without if ... then begin' );
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"} or $self->wail("Else without if ... then begin") 2 0 2
Condition33%2/6
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"}
!ll&&!rl&&r
002
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"}
!ll&&!rl&&r
002
MC/DC0%0/3
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"}
@{$self->{"frame"};} > 1 "begin" eq $self->{"frame"}[-1]{"type"} "if" eq $self->{"frame"}[-2]{"type"}
Truth table25%1/4
A and B and C
A= @{$self->{"frame"};} > 1B= "begin" eq $self->{"frame"}[-1]{"type"}C= "if" eq $self->{"frame"}[-2]{"type"}
ABCresult
0XX0
10X0
1100
1111
773  
774 2 ▶ $self->{frame}[-1]{in_else}++
Branch: 1 branch
BranchTrueFalseTotal
$self->{"frame"}[-1]{"in_else"}++ and $self->wail("Only one else may follow an if") 0 2 2
775 and $self->wail( 'Only one else may follow an if' );
776  
777 2 return $self->_twiddle_condition( ! $self->{frame}[-2]{condition} );
778 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
779  
780 4 ▶sub _twiddle_condition {
Subroutine _twiddle_condition: called CC=3 SCAR=11.2
781 4 my ( $self, $cond ) = @_;
782  
783 # Here is where I pay for the convenience of the if()
784 # implementation. The if() itself is a frame because I do not yet
785 # know if it will entail a begin(). But I can't do an else() unless
786 # there is in fact a begin(), which creates another frame. So I end
787 # up twiddling values in both frames.
788  
789 $self->{frame}[-1]{unsatisfied_if} =
790 $self->{frame}[-2]{unsatisfied_if} =
791 ! $cond || (
792 2 @{ $self->{frame} } > 2 ?
793 $self->{frame}[-3]{unsatisfied_if} :
794 4 ▶ 0
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'frame'};} > 2 ? : 2 0 2
Condition66%2/3
!$cond || (@{$self->{'frame'};} > 2 ? $self->{'frame'}[-3]{'unsatisfied_if'} : 0)
l!l&&r!l&&!r
202
MC/DC50%1/2
!$cond || (@{$self->{'frame'};} > 2 ? $self->{'frame'}[-3]{'unsatisfied_if'} : 0)
!$cond (@{$self->{'frame'};} > 2 ? $self->{'frame'}[-3]{'unsatisfied_if'} : 0)
Truth table66%2/3
not(A) || B
A= !$condB= (@{$self->{'frame'};} > 2 ? $self->{'frame'}[-3]{'unsatisfied_if'} : 0)
ABresult
1X1
011
000
795 );
796  
797 $self->{frame}[-1]{condition} =
798 4 $self->{frame}[-2]{condition} = $cond;
799  
800 4 return;
801 }
802  
803 5 ▶sub end : Verb() Tweak( -unsatisfied ) {
Subroutine end: called CC=2 SCAR=7.0
Pod documented
804 5 my ( $self ) = __arguments( @_ ); # $opt, @args unused
805  
806 5 ▶ $self->{frame}[-1]{type} eq 'begin'
Branch: 1 branch
BranchTrueFalseTotal
$self->{"frame"}[-1]{"type"} eq "begin" or $self->wail("End without begin") 5 0 5
807 or $self->wail( 'End without begin' );
808 5 $self->_frame_pop();
809 5 return;
810 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
811  
812 1 ▶sub error : Verb() {
Subroutine error: called CC=2 SCAR=7.6
Pod documented
813 1 my ( $self, undef, @arg ) = __arguments( @_ );
814 @arg
815 1 ▶ or push @arg, 'An error has occurred';
Branch: 1 branch
BranchTrueFalseTotal
@arg or push @arg, "An error has occurred" 1 0 1
816 1 $self->wail( @arg );
817 0 return;
818 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
819  
820 # Tokenize and execute one or more commands. Optionally (and
821 # unsupportedly) you can pass a code reference as the first argument.
822 # This code reference will be used to fetch commands when the arguments
823 # are exhausted. IF you pass your own code reference, we return after
824 # the first command, since the code reference is presumed to manage the
825 # input stream itself.
826 264 ▶sub execute {
Subroutine execute: called CC=11 SCAR=24.0
Pod documented
827 264 my ($self, @args) = @_;
828 264 my $accum;
829 my $in;
830 264 my $extern;
831 264 ▶ if ( CODE_REF eq ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('CODE' eq ref $args[0]) { } 13 251 264
832 13 $extern = shift @args;
833 21 ▶ $in = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
834 21 my ( $prompt ) = @_;
835 21 ▶ @args and return shift @args;
Branch: 1 branch
BranchTrueFalseTotal
@args and return shift @args 13 8 21
836 8 return $extern->( $prompt );
837 13 };
838 } else {
839 251 ▶ $in = sub { return shift @args };
Subroutine __ANON__: called CC=1 SCAR=0.0
840 }
841 264 @args = map { split qr{ (?<= \n ) }smx, $_ } @args;
842 264 ▶ while ( defined ( local $_ = $in->( $self->get( 'prompt' ) ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = &$in($self->get("prompt")))) 280 240 520
843 280 ▶ $self->{echo} and $self->whinge($self->get( 'prompt' ), $_);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"echo"} and $self->whinge($self->get("prompt"), $_) 0 280 280
844 280 ▶ m/ \A \s* [#] /smx and next;
Branch: 1 branch
BranchTrueFalseTotal
/ \A \s* [#] /msx and next 3 277 280
845 277 my $stdout = $self->{frame}[-1]{stdout};
846 my ($args, $redirect) = $self->__tokenize(
847 277 { in => $in }, $_, $self->{frame}[-1]{args});
848 # NOTICE
849 #
850 # The execute_filter attribute is undocumented and unsupported.
851 # It exists only so I can scavenge the user's initialization
852 # file for the (possible) Space Track username and password, to
853 # be used in testing, without being subject to any other
854 # undesired side effects, such as running a prediction and
855 # exiting. If I change my mind on how or whether to do this,
856 # execute_filter will be altered or retracted without warning,
857 # much less a deprecation cycle. If you have a legitimate need
858 # for this functionality, contact me.
859 #
860 # YOU HAVE BEEN WARNED.
861 273 ▶ $self->{execute_filter}->( $self, $args ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"execute_filter"}->($self, $args) or next 267 6 273
862 267 ▶ @{ $args } or next;
Branch: 1 branch
BranchTrueFalseTotal
@{$args;} or next 266 1 267
863 266 ▶ if ($redirect->{'>'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redirect->{">"}) 1 265 266
864 1 my ( $mode, $name ) = map { $redirect->{'>'}{$_} } qw{ mode name };
865 1 my $fh;
866 1 ▶ $stdout = sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
867 1 my ( $output ) = @_;
868 1 ▶ $fh ||= $self->_file_opener( $name, $mode );
Condition33%1/3
$fh ||= $self->_file_opener($name, $mode)
l!l&&r!l&&!r
010
MC/DC0%0/2
$fh ||= $self->_file_opener($name, $mode)
$fh $self->_file_opener($name, $mode)
Truth table33%1/3
A ||= B
A= $fhB= $self->_file_opener($name, $mode)
ABresult
1X1
011
000
869 1 $fh->print( $output );
870 1 return;
871 1 };
872 }
873  
874 # {localout} is the output to be used for this command. It goes
875 # in the frame stack because our command may start a new frame,
876 # and _frame_push() needs to have a place to get the correct
877 # output handle.
878  
879 266 my $frame_depth = $#{$self->{frame}};
880 266 $self->{frame}[-1]{localout} = $stdout;
881  
882 266 my $output = $self->dispatch( @$args );
883  
884 256 $#{$self->{frame}} >= $frame_depth
885 256 ▶ and delete $self->{frame}[ $frame_depth ]{localout};
Branch: 1 branch
BranchTrueFalseTotal
$#{$$self{"frame"};} >= $frame_depth and delete $self->{"frame"}[$frame_depth]{"localout"} 251 5 256
886  
887 256 ▶ $self->_execute_output( $output,
Branch: 1 branch
BranchTrueFalseTotal
defined $stdout ? : 6 250 256
888 defined $stdout ? $stdout : \$accum );
889  
890 256 ▶ $extern and last;
Branch: 1 branch
BranchTrueFalseTotal
$extern and last 10 246 256
891 }
892 250 return $accum;
893 }
894  
895 # $satpass2->_execute(...);
896 #
897 # This subroutine calls $satpass2->execute() once for each
898 # argument. The call is wrapped in an eval{}; if an exception
899 # occurs the user is notified via warn.
900  
901 0 ▶sub _execute {
Subroutine _execute: not called CC=4 SCAR=30.0
902 0 my ($self, @args) = @_;
903 0 ▶ my $in = CODE_REF eq ref $args[0] ? shift @args : sub { return shift
Subroutine __ANON__: not called CC=1 SCAR=6.9
904 0 ▶ @args };
Branch: 1 branch
BranchTrueFalseTotal
'CODE' eq ref $args[0] ? : 0 0 0
905 0 ▶ while ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
906 0 ▶ local $SIG{INT} = sub {die "\n$interrupted\n"};
Subroutine __ANON__: not called CC=1 SCAR=6.9
907 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->execute($in, shift @args); 1 } } or warn $@ 0 0 0
908 0 $self->execute( $in, shift @args );
909 0 1;
910 } or warn $@; # Not whinge, since presumably we already did.
911 }
912 0 return;
913 }
914  
915 # $satpass2->_execute_output( $output, $stdout );
916 #
917 # If $output is defined, sends it to $stdout.
918  
919 256 ▶sub _execute_output {
Subroutine _execute_output: called CC=6 SCAR=18.4
920 256 my ( undef, $output, $stdout ) = @_; # Invocant unused
921 256 ▶ defined $output or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $output or return 152 104 256
922 152 my $ref = ref $stdout;
923 152 ▶ if ( !defined $stdout ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $stdout) { } 0 152 152
elsif ('SCALAR' eq $ref) { } 149 3 152
elsif ('CODE' eq $ref) { } 2 1 3
elsif ('ARRAY' eq $ref) { } 1 0 1
924 0 return $output;
925 } elsif ( SCALAR_REF eq $ref ) {
926 149 $$stdout .= $output;
927 } elsif ( CODE_REF eq $ref ) {
928 2 $stdout->( $output );
929 } elsif ( ARRAY_REF eq $ref ) {
930 1 push @$stdout, split qr{ (?<=\n) }smx, $output;
931 } else {
932 0 $stdout->print( $output );
933 }
934 152 return;
935 }
936  
937 1 ▶sub exit : method Verb() { ## no critic (ProhibitBuiltInHomonyms)
Subroutine exit: called CC=1 SCAR=0.1
Pod documented
938 1 my ( $self ) = __arguments( @_ ); # $opt, @args unused
939  
940 1 $self->_frame_pop(1); # Leave only the inital frame.
941  
942 1 eval { ## no critic (RequireCheckingReturnValueOfEval)
943 20 ▶ no warnings qw{exiting};
Subroutine BEGIN: called CC=1 SCAR=0.0
944 1 last SATPASS2_EXECUTE;
945 };
946 0 $self->whinge("$@Exiting Perl");
947 0 exit;
948  
949 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
950  
951 4 ▶sub export : Verb() {
Subroutine export: called CC=4 SCAR=13.9
Pod documented
952 4 my ( $self, undef, $name, @args ) = __arguments( @_ ); # $opt unused
953 4 ▶ if ($mutator{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mutator{$name}) { } 1 3 4
954 1 ▶ @args and $self->set ($name, shift @args);
Branch: 1 branch
BranchTrueFalseTotal
@args and $self->set($name, shift @args) 1 0 1
955 1 $self->{exported}{$name} = 1;
956 } else {
957 3 ▶ @args or return $self->wail( 'You must specify a value' );
Branch: 1 branch
BranchTrueFalseTotal
@args or return $self->wail("You must specify a value") 2 1 3
958 2 $self->{exported}{$name} = shift @args;
959 }
960 3 return;
961 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
962  
963 # Attributes must all be on one line to process correctly under Perl
964 # 5.8.8.
965 0 ▶sub flare : Verb( algorithm=s am! choose=s@ day! dump! pm! questionable|spare! quiet! tz|zone=s )
Subroutine flare: not called CC=15 SCAR=54.8
Pod documented
966 {
967 0 my ( $self, $opt, @args ) = __arguments( @_ );
968 0 HAVE_TLE_IRIDIUM
969 or $self->wail( 'Astro::Coord::ECI::TLE::Iridium not available' );
970 0 my $pass_start = $self->__parse_time (
971 shift @args, $self->_get_day_noon());
972 0 ▶ my $pass_end = $self->__parse_time (shift @args || '+7');
Condition0%0/2
shift @args || '+7'
l!l
00
MC/DC0%0/1
shift @args || '+7'
shift @args
Truth table0%0/2
A
A= shift @args
Aresult
11
00
973 0 ▶ $pass_start >= $pass_end
Branch: 1 branch
BranchTrueFalseTotal
$pass_start >= $pass_end and $self->wail("End time must be after start time") 0 0 0
974 and $self->wail( 'End time must be after start time' );
975 0 my $sta = $self->station();
976  
977 0 my $max_mirror_angle = deg2rad( $self->{max_mirror_angle} );
978 0 my $horizon = deg2rad ($self->{horizon});
979 0 my $twilight = $self->{_twilight};
980 0 my @flare_mag = ($self->{flare_mag_night}, $self->{flare_mag_day});
981 my $zone = exists $opt->{tz} ? $opt->{tz} :
982 $self->{formatter}->gmt() ? 0 :
983 0 ▶ $self->{formatter}->tz() || undef;
Branch: 2 branches
BranchTrueFalseTotal
exists $opt->{'tz'} ? : 0 0 0
$self->{'formatter'}->gmt ? : 0 0 0
Condition0%0/2
$self->{"formatter"}->tz or undef
l!l
00
MC/DC0%0/1
$self->{"formatter"}->tz or undef
$self->{"formatter"}->tz
Truth table0%0/2
A
A= $self->{"formatter"}->tz
Aresult
11
00
984  
985 0 $self->_apply_boolean_default(
986 $opt, 0, qw{ am day pm } );
987  
988 # Decide which model to use.
989  
990 0 my $model = $self->{model};
991  
992 # Select only the bodies capable of flaring.
993  
994 0 my @active;
995 0 foreach my $tle ( $self->_aggregate(
996 scalar $self->__choose( $opt->{choose}, $self->{bodies} )
997 ) )
998 {
999 0 ▶ $tle->can_flare( $opt->{questionable} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$tle->can_flare($opt->{"questionable"}) or next 0 0 0
1000 $tle->set (
1001 algorithm => $opt->{algorithm} || 'fixed',
1002 backdate => $self->{backdate},
1003 edge_of_earths_shadow => $self->{edge_of_earths_shadow},
1004 horizon => $horizon,
1005 twilight => $twilight,
1006 model => $model,
1007 am => $opt->{am},
1008 max_mirror_angle => $max_mirror_angle,
1009 day => $opt->{day},
1010 pm => $opt->{pm},
1011 extinction => $self->{extinction},
1012 0 ▶ station => $sta,
Condition0%0/2
$opt->{'algorithm'} || 'fixed'
l!l
00
MC/DC0%0/1
$opt->{'algorithm'} || 'fixed'
$opt->{'algorithm'}
Truth table0%0/2
A
A= $opt->{'algorithm'}
Aresult
11
00
1013 zone => $zone,
1014 );
1015 0 push @active, $tle;
1016 }
1017 0 ▶ @active or return $self->__wail( 'No bodies capable of flaring' );
Branch: 1 branch
BranchTrueFalseTotal
@active or return $self->__wail("No bodies capable of flaring") 0 0 0
1018  
1019 0 my @flares;
1020 0 foreach my $tle (@active) {
1021 eval {
1022 0 push @flares, $tle->flare( $pass_start, $pass_end );
1023 0 1;
1024 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { push @flares, $tle->flare($pass_start, $pass_end); 1 } } or do { $@ =~ / \Q$interrupted\E /mosx and $self->wail($@); $opt->{"quiet"} or $self->whinge($@) } 0 0 0
1025 0 ▶ $@ =~ m/ \Q$interrupted\E /smxo and $self->wail($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ =~ / \Q$interrupted\E /mosx and $self->wail($@) 0 0 0
1026 0 ▶ $opt->{quiet} or $self->whinge($@);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"quiet"} or $self->whinge($@) 0 0 0
1027 };
1028 }
1029  
1030 # Record number of events found
1031  
1032 0 @flares = sort { $a->{time} <=> $b->{time} }
1033 0 grep { $_->{magnitude} <= $flare_mag[
1034 0 ▶ ( $_->{type} eq 'day' ? 1 : 0 ) ] }
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type'} eq 'day' ? : 0 0 0
1035 @flares;
1036 0 $self->{events} += @flares;
1037  
1038 0 return $self->__format_data( flare => \@flares, $opt );
1039 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1040  
1041 9 ▶sub formatter : Verb() Tweak( -completion _readline_complete_subcommand ) {
Subroutine formatter: called CC=2 SCAR=7.2
Pod documented
1042 9 ▶ splice @_, ( HASH_REF eq ref $_[1] ? 2 : 1 ), 0, 'formatter';
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $_[1] ? : 0 9 9
1043 9 goto &_helper_handler;
1044 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1045  
1046 # Calls to the following _formatter_sub method are generated dynamically
1047 # above, so there is no way Perl::Critic can find them.
1048  
1049 5 ▶sub _formatter_sub { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _formatter_sub: called CC=5 SCAR=16.1
1050 5 my ( $app, $text, $line, $start, @arg ) = @_;
1051 5 my $fmtr = $app->get( 'formatter' );
1052 5 ▶ if ( @arg == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg == 2) 3 2 5
1053 3 my @list = qw{
1054 date_format
1055 desired_equinox_dynamical
1056 gmt
1057 local_coord
1058 time_format
1059 tz
1060 };
1061 3 ▶ $fmtr->can( '__list_templates' )
Branch: 1 branch
BranchTrueFalseTotal
$fmtr->can("__list_templates") and push @list, "template" 3 0 3
1062 and push @list, 'template';
1063 3 my $re = qr/ \A \Q$arg[1]\E /smx;
1064 3 return [ grep { $_ =~ $re } sort @list ];
1065 }
1066 2 ▶ my $code = $app->can( "_formatter_complete_$arg[1]" )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $app->can("_formatter_complete_$arg[1]") or return 2 0 2
1067 or return;
1068  
1069 2 my $r;
1070 2 ▶ $r = $app->_readline_complete_options( $code, $text, $line,
Branch: 1 branch
BranchTrueFalseTotal
$r = $app->_readline_complete_options($code, $text, $line, $start) and return $r 1 1 2
1071 $start )
1072 and return $r;
1073  
1074 1 return $code->( $app, @arg );
1075 }
1076  
1077 # Calls to the following _formatter_complete_... methods are generated
1078 # dynamically above, so there is no way Perl::Critic can find them.
1079 # The Verb attribute must aggree with _helper_handler().
1080  
1081 1 ▶sub _formatter_complete_template : Verb( changes! raw! ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _formatter_complete_template: called CC=1 SCAR=0.0
1082 1 my ( $app, undef, @arg ) = __arguments( @_ );
1083 1 my $fmtr = $app->get( 'formatter' );
1084 1 my $re = qr/ \A \Q$arg[2]\E /smx;
1085 return [
1086 1 grep { $_ =~ $re }
1087 sort( $fmtr->__list_templates() )
1088 ];
1089 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1090  
1091 0 ▶sub geocode : Verb( debug! ) {
Subroutine geocode: not called CC=7 SCAR=40.3
Pod documented
1092 0 my ( $self, $opt, $loc ) = __arguments( @_ );
1093  
1094 0 my $set_loc;
1095 0 ▶ if ( defined $loc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $loc) { } 0 0 0
1096 0 $set_loc = 1;
1097 } else {
1098 0 $loc = $self->get( 'location' );
1099 }
1100  
1101 0 my $geocoder = $self->_helper_get_object( 'geocoder' );
1102  
1103 0 my @rslt = $geocoder->geocode( $loc );
1104  
1105 0 my $output;
1106 0 ▶ if ( @rslt == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rslt == 1) { } 0 0 0
1107 $set_loc
1108 0 ▶ and $self->set( location => $rslt[0]{description} );
Branch: 1 branch
BranchTrueFalseTotal
$set_loc and $self->set("location", $rslt[0]{"description"}) 0 0 0
1109 0 $self->set( map { $_ => $rslt[0]{$_} } qw{ latitude
1110 longitude } );
1111 0 ▶ $output .= $self->show(
Branch: 1 branch
BranchTrueFalseTotal
$set_loc ? : 0 0 0
1112 ( $set_loc ? 'location' : () ), qw{latitude longitude} );
1113 0 ▶ if ( $self->get( 'autoheight' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get("autoheight")) 0 0 0
1114 0 $opt->{geocoding} = 1;
1115 0 $output .= $self->_height_us($opt);
1116 }
1117 } else {
1118 0 foreach my $poi ( @rslt ) {
1119 0 $output .= join ' ', map { $poi->{$_} } qw{ latitude
1120 longitude description };
1121 0 $output =~ s/ (?: \A | (?<! \n ) ) \z /\n/smx;
1122 }
1123 }
1124 0 return $output;
1125 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1126  
1127 0 ▶sub geodetic : Verb() {
Subroutine geodetic: not called CC=2 SCAR=17.9
Pod documented
1128 0 my ( $self, undef, $name, $lat, $lon, $alt ) = __arguments( @_ ); # $opt unused
1129 0 ▶ @_ == 5 or $self->wail( 'Want exactly four arguments' );
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or $self->wail("Want exactly four arguments") 0 0 0
1130 0 my $body = Astro::Coord::ECI::TLE->new(
1131 name => $name,
1132 id => '',
1133 model => 'null',
1134 )->geodetic(
1135 deg2rad( $self->__parse_angle( $lat ) ),
1136 deg2rad( $self->__parse_angle( $lon ) ),
1137 $self->__parse_distance( $alt ),
1138 );
1139 0 push @{ $self->{bodies} }, $body;
1140 0 return;
1141 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1142  
1143 935 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
1144 935 my ($self, $name) = @_;
1145 935 $self->_attribute_exists( $name );
1146 935 $self->_deprecation_notice( attribute => $name );
1147 935 return $accessor{$name}->($self, $name);
1148 }
1149  
1150 0 ▶sub height : Verb( debug! ) {
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
1151 0 return _height_us( __arguments( @_ ) );
1152 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1153  
1154 0 ▶sub _height_us {
Subroutine _height_us: not called CC=5 SCAR=34.0
1155 0 my ($self, $opt, @args) = @_;
1156 0 $self->_load_module ('Geo::WebService::Elevation::USGS');
1157 0 my $eq = Geo::WebService::Elevation::USGS->new(
1158 places => 2, # Service returns unreasonable precision
1159 units => 'METERS', # default for service is 'FEET'
1160 croak => 0, # Handle our own errors
1161 );
1162 0 ▶ @args or push @args, $self->get('latitude'), $self->get('longitude');
Branch: 1 branch
BranchTrueFalseTotal
@args or push @args, $self->get("latitude"), $self->get("longitude") 0 0 0
1163 0 my $output;
1164 0 my ( $rslt ) = $eq->elevation(@args);
1165 0 ▶ if ( $eq->is_valid( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eq->is_valid($rslt)) { } 0 0 0
1166 0 $self->set( height => $rslt->{Elevation} );
1167 } else {
1168 $opt->{geocoding}
1169 0 ▶ or $self->wail( $eq->get( 'error' ) || 'No valid result found' );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"geocoding"} or $self->wail($eq->get("error") || "No valid result found") 0 0 0
Condition0%0/2
$eq->get('error') || 'No valid result found'
l!l
00
MC/DC0%0/1
$eq->get('error') || 'No valid result found'
$eq->get('error')
Truth table0%0/2
A
A= $eq->get('error')
Aresult
11
00
1170 0 $self->set( height => 0 );
1171 0 $output .= "# Unable to obtain height. Setting to 0\n";
1172 }
1173 0 $output .= $self->show( 'height' );
1174 0 return $output;
1175 }
1176  
1177 0 ▶sub help : Verb() {
Subroutine help: not called CC=10 SCAR=47.0
Pod documented
1178 0 my ( $self, undef, $arg ) = __arguments( @_ ); # $opt unused
1179 0 ▶ defined $arg
Branch: 1 branch
BranchTrueFalseTotal
defined $arg or $arg = "" 0 0 0
1180 or $arg = '';
1181 defined $self->{_help_module}{$arg}
1182 0 ▶ and $arg = $self->{_help_module}{$arg};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"_help_module"}{$arg} and $arg = $self->{"_help_module"}{$arg} 0 0 0
1183 0 ▶ if ( my $cmd = $self->_get_browser_command() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cmd = $self->_get_browser_command) { } 0 0 0
1184 0 ▶ my $kind = $arg =~ m/ - /smx ? 'release' : 'pod';
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ / - /msx ? : 0 0 0
1185 0 $self->system( $cmd,
1186 "https://metacpan.org/$kind/$arg" );
1187 } else {
1188  
1189 0 my $os_specific = "_help_$^O";
1190 0 ▶ if (__PACKAGE__->can ($os_specific)) {
Branch: 2 branches
BranchTrueFalseTotal
if (__PACKAGE__->can($os_specific)) { } 0 0 0
elsif (load_package('Pod::Usage')) { } 0 0 0
1191 0 return __PACKAGE__->$os_specific ();
1192 } elsif ( load_package( 'Pod::Usage' ) ) {
1193 0 my @ha;
1194 0 ▶ if ( defined( my $path = find_package_pod( $arg ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = find_package_pod($arg))) 0 0 0
1195 0 push @ha, '-input' => $path;
1196 }
1197 0 my $stdout = $self->{frame}[-1]{localout};
1198 0 ▶ if (openhandle $stdout && !-t $stdout) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($stdout) and not -t $stdout) 0 0 0
Condition0%0/3
&openhandle($stdout) and not -t $stdout
!ll&&!rl&&r
000
MC/DC0%0/2
&openhandle($stdout) and not -t $stdout
&openhandle($stdout) not -t $stdout
Truth table0%0/3
A and not(B)
A= &openhandle($stdout)B= not -t $stdout
ABresult
0X0
100
111
1199 0 push @ha, -output => $stdout;
1200 }
1201 Pod::Usage::pod2usage (
1202 0 -verbose => 2, -exitval => 'NOEXIT', @ha);
1203 } else {
1204 # This should never happen, since Pod::Usage is core
1205 # since 5.6. On the other hand we have not declared it
1206 # as a dependency, and some downstream packagers seem to
1207 # think they know more than the author what should be in
1208 # a package.
1209 return <<'EOD'
1210 No help available; Pod::Usage can not be loaded.
1211 EOD
1212 0 }
1213 }
1214 0 return;
1215 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1216  
1217 # The call to this is generated dynamically above, and there is no way
1218 # Perl::Critic can find it.
1219 0 ▶sub _help_MacOS { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _help_MacOS: not called CC=1 SCAR=6.9
1220 0 return <<'EOD';
1221  
1222 Normally, we would display the documentation for the satpass2
1223 script here. But unfortunately this depends on the ability to
1224 spawn the perldoc command, and we do not have this ability under
1225 Mac OS 9 and earlier. You can find the same thing online at
1226 https://metacpan.org/release/Astro-App-Satpass2
1227  
1228 EOD
1229 }
1230  
1231 {
1232 # This hash specifies the specific grammar passed to
1233 # __infix_engine(). The keys are:
1234 # {done} optional; called when parse is complete.
1235 # {oper} defines operators. Values are hash refs with:
1236 # {handler} code that handles operator;
1237 # {validation} name of validation style (see {vld} below).
1238 # {vld} defines operator validation. There must be a key for each
1239 # distinct value of {oper}{$name}{validation}.
1240 # NOTE WELL
1241 # Because if() has the Tweak( -unsatisfied ) attribute, any
1242 # operators that have side effects will need to be aware of whether
1243 # they are running inside an unsatisfied if().
1244 my %define = (
1245 24 ▶ done => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1246 # my ( $self, $def, $ctx, $tokens ) = @_;
1247 24 my ( $self, undef, $ctx ) = @_;
1248 24 ▶ @{ $ctx }
Branch: 1 branch
BranchTrueFalseTotal
@{$ctx;} and $self->wail("No 'then'") 0 24 24
1249 and $self->wail( q<No 'then'> );;
1250 24 return;
1251 },
1252 oper => {
1253 '(' => {
1254 1 ▶ handler => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1255 1 my ( $self, $def, $ctx, $tokens ) = @_;
1256 1 my $want = delete $ctx->[-1]{want};
1257 1 ▶ defined $want
Branch: 1 branch
BranchTrueFalseTotal
defined $want or $want = 1 0 1 1
1258 or $want = 1;
1259 1 push @{ $ctx }, {
1260 want => $want,
1261 value => [],
1262 };
1263 $ctx->[-2]{shortcut}
1264 1 ▶ and $ctx->[1]{shortcut} = $ctx->[-2]{shortcut};
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-2]{"shortcut"} and $ctx->[1]{"shortcut"} = $ctx->[-2]{"shortcut"} 0 1 1
1265 1 my $depth = @{ $ctx };
1266 1 ▶ while ( $depth <= @{ $ctx } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= @{$ctx;}) 3 1 4
1267 3 $self->_infix_engine_dispatch( $def, $ctx, $tokens );
1268 }
1269 1 return;
1270 },
1271 },
1272 ')' => {
1273 1 ▶ handler => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
1274 # my ( $self, $def, $ctx, $tokens ) = @_;
1275 1 my ( $self, undef, $ctx ) = @_;
1276 1 ▶ @{ $ctx }
Branch: 1 branch
BranchTrueFalseTotal
@{$ctx;} or $self->wail("Unpaired right parentheses") 1 0 1
1277 or $self->wail( 'Unpaired right parentheses' );
1278 1 $ctx->[-1]{want} == @{ $ctx->[-1]{value} }
1279 or $self->wail(
1280 "Expected $ctx->[-1]{want} value(s), got " .
1281 0 ▶ scalar @{ $ctx->[-1]{value} } );
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"want"} == @{$ctx->[-1]{"value"};} or $self->wail(qq[Expected $ctx->[-1]{"want"} value(s), got ] . scalar(@{$ctx->[-1]{"value"};})) 1 0 1
1282 1 push @{ $ctx->[-2]{value} }, @{ $ctx->[-1]{value} };
1283 1 pop @{ $ctx };
1284 1 return;
1285 },
1286 },
1287 '-n' => {
1288 2 ▶ handler => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1289 # my ( $self, $def, $ctx, $tokens ) = @_;
1290 2 my ( undef, undef, $ctx, $tokens ) = @_;
1291 2 my $v = shift @{ $tokens };
1292 2 ▶ defined $v
Branch: 1 branch
BranchTrueFalseTotal
defined $v or $v = "" 2 0 2
1293 or $v = '';
1294 2 push @{ $ctx->[-1]{value} }, '' ne $v;
1295 },
1296 validation => 'prefix',
1297 },
1298 '-z' => {
1299 2 ▶ handler => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1300 # my ( $self, $def, $ctx, $tokens ) = @_;
1301 2 my ( undef, undef, $ctx, $tokens ) = @_;
1302 2 my $v = shift @{ $tokens };
1303 2 ▶ defined $v
Branch: 1 branch
BranchTrueFalseTotal
defined $v or $v = "" 2 0 2
1304 or $v = '';
1305 2 push @{ $ctx->[-1]{value} }, '' eq $v;
1306 },
1307 validation => 'prefix',
1308 },
1309 and => {
1310 2 ▶ handler => sub {
Subroutine __ANON__: called CC=4 SCAR=15.5
1311 2 my ( $self, $def, $ctx, $tokens ) = @_;
1312 $ctx->[-1]{value}[-1]
1313 2 ▶ or $ctx->[-1]{shortcut} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"value"}[-1] or $ctx->[-1]{"shortcut"} = 1 0 2 2
1314 2 $self->_infix_engine_dispatch( $def, $ctx, $tokens );
1315 # For some reason the following has to be done in
1316 # two statements, or both operands remain on the
1317 # stack.
1318 2 my $ro = pop @{ $ctx->[-1]{value} };
1319 $ctx->[-1]{value}[-1] &&= $ro
1320 2 ▶ unless delete $ctx->[-1]{shortcut};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $ctx->[-1]{"shortcut"} 0 2 2
Condition0%0/3
$ctx->[-1]{"value"}[-1] &&= $ro
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->[-1]{"value"}[-1] &&= $ro
$ctx->[-1]{"value"}[-1] $ro
Truth table0%0/3
A &&= B
A= $ctx->[-1]{"value"}[-1]B= $ro
ABresult
0X0
100
111
1321 2 return;
1322 },
1323 validation => 'infix',
1324 },
1325 attr => {
1326 3 ▶ handler => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
1327 # my ( $self, $def, $ctx, $tokens ) = @_;
1328 3 my ( $self, undef, $ctx, $tokens ) = @_;
1329 3 my $attr = shift @{ $tokens };
1330 3 my $val;
1331 $ctx->[-1]{shortcut}
1332 3 ▶ or $val = $self->_attribute_value( $attr );
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"shortcut"} or $val = $self->_attribute_value($attr) 0 3 3
1333 3 ▶ NULL_REF eq ref $val
Branch: 1 branch
BranchTrueFalseTotal
"Null" eq ref $val and $self->wail("No such attribute as '${attr}'") 0 3 3
1334 and $self->wail( "No such attribute as '$attr'" );
1335 3 push @{ $ctx->[-1]{value} }, $val;
1336 3 return;
1337 },
1338 validation => 'prefix',
1339 },
1340 env => {
1341 11 ▶ handler => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1342 # my ( $self, $def, $ctx, $tokens ) = @_;
1343 11 my ( undef, undef, $ctx, $tokens ) = @_;
1344 11 my $name = shift @{ $tokens };
1345 11 my $val;
1346 $ctx->[-1]{shortcut}
1347 11 ▶ or $val = $ENV{$name};
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"shortcut"} or $val = $ENV{$name} 2 9 11
1348 11 push @{ $ctx->[-1]{value} }, $val;
1349 11 return;
1350 },
1351 validation => 'prefix',
1352 },
1353 loaded => {
1354 2 ▶ handler => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1355 # my ( $self, $def, $ctx, $tokens ) = @_;
1356 2 my ( $self, undef, $ctx, $tokens ) = @_;
1357 2 my $name = shift @{ $tokens };
1358 2 my @loaded;
1359 $ctx->[-1]{shortcut}
1360 2 ▶ or @loaded = $self->__choose(
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"shortcut"} or @loaded = $self->__choose({"bodies", 1}, [$name]) 0 2 2
1361 { bodies => 1 },
1362 [ $name ],
1363 );
1364 2 push @{ $ctx->[-1]{value} }, scalar @loaded;
1365 2 return;
1366 },
1367 validation => 'prefix',
1368 },
1369 not => {
1370 5 ▶ handler => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1371 5 my ( $self, $def, $ctx, $tokens ) = @_;
1372 5 $self->_infix_engine_dispatch( $def, $ctx, $tokens );
1373 5 $ctx->[-1]{value}[-1] = ! $ctx->[-1]{value}[-1];
1374 5 return;
1375 },
1376 validation => 'prefix',
1377 },
1378 or => {
1379 1 ▶ handler => sub {
Subroutine __ANON__: called CC=4 SCAR=14.8
1380 1 my ( $self, $def, $ctx, $tokens ) = @_;
1381 $ctx->[-1]{value}[-1]
1382 1 ▶ and $ctx->[-1]{shortcut} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->[-1]{"value"}[-1] and $ctx->[-1]{"shortcut"} = 1 0 1 1
1383 1 $self->_infix_engine_dispatch( $def, $ctx, $tokens );
1384 # For some reason the following has to be done in
1385 # two statements, or both operands remain on the
1386 # stack.
1387 1 my $ro = pop @{ $ctx->[-1]{value} };
1388 $ctx->[-1]{value}[-1] ||= $ro
1389 1 ▶ unless delete $ctx->[-1]{shortcut};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $ctx->[-1]{"shortcut"} 1 0 1
Condition33%1/3
$ctx->[-1]{"value"}[-1] ||= $ro
l!l&&r!l&&!r
010
MC/DC0%0/2
$ctx->[-1]{"value"}[-1] ||= $ro
$ctx->[-1]{"value"}[-1] $ro
Truth table33%1/3
A ||= B
A= $ctx->[-1]{"value"}[-1]B= $ro
ABresult
1X1
011
000
1390 1 return;
1391 },
1392 validation => 'infix',
1393 },
1394 os => {
1395 3 ▶ handler => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1396 # my ( $self, $def, $ctx, $tokens ) = @_;
1397 3 my ( undef, undef, $ctx, $tokens ) = @_;
1398 3 my $re = qr< \A \Q$^O\E \z >smxi;
1399 3 my $rslt = 0;
1400 3 my $name = shift @{ $tokens };
1401 3 ▶ unless ( $ctx->[-1]{shortcut} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->[-1]{"shortcut"}) 3 0 3
1402 3 foreach my $os ( split qr< [|] >smx, $name ) {
1403 4 ▶ $os =~ $re
Branch: 1 branch
BranchTrueFalseTotal
$os =~ /$re/ or next 2 2 4
1404 or next;
1405 2 $rslt = 1;
1406 2 last;
1407 }
1408 }
1409 3 push @{ $ctx->[-1]{value} }, $rslt;
1410 3 return;
1411 },
1412 validation => 'prefix',
1413 },
1414 then => {
1415 24 ▶ handler => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1416 # my ( $self, $def, $ctx, $tokens ) = @_;
1417 24 my ( $self, undef, $ctx, $tokens ) = @_;
1418 24 ▶ 1 == @{ $ctx }
Branch: 1 branch
BranchTrueFalseTotal
1 == @{$ctx;} or $self->wail("Unclosed left parentheses") 24 0 24
1419 or $self->wail( 'Unclosed left parentheses' );
1420 24 my $last = pop @{ $ctx };
1421 24 my @arg = splice @{ $tokens };
1422 24 ▶ if ( $last->{dispatch} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last->{'dispatch'}) { } 22 2 24
1423 22 $self->_dispatch_check( if => $arg[0] );
1424 $self->_frame_push( if => [], {
1425 22 condition => $last->{value}[-1],
1426 },
1427 );
1428 22 ▶ $self->_add_post_dispatch( sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1429 22 $self->_frame_pop( if => undef );
1430 },
1431 22 );
1432 22 return $self->dispatch( @arg );
1433 } else {
1434 2 $self->_twiddle_condition( $last->{value}[-1] );
1435 }
1436 },
1437 validation => 'terminal',
1438 },
1439 },
1440 4 ▶ val => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1441 # my ( $self, $def, $ctx, $tkn, $tokens ) = @_;
1442 4 my ( undef, undef, $ctx, $tkn ) = @_;
1443 4 push @{ $ctx->[-1]{value} }, $tkn;
1444 4 return;
1445 },
1446 vld => {
1447 3 ▶ infix => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
1448 # my ( $self, $def, $ctx, $tkn, $tokens ) = @_;
1449 3 my ( $self, undef, $ctx, $tkn, $tokens ) = @_;
1450 3 ▶ @{ $ctx->[-1]{value} }
Branch: 1 branch
BranchTrueFalseTotal
@{$ctx->[-1]{"value"};} or $self->wail("'${tkn}' requires a left argument") 3 0 3
1451 or $self->wail( "'$tkn' requires a left argument" );
1452 3 ▶ @{ $tokens }
Branch: 1 branch
BranchTrueFalseTotal
@{$tokens;} or $self->wail("'${tkn}' requires a right argument") 3 0 3
1453 or $self->wail( "'$tkn' requires a right argument" );
1454 3 return;
1455 },
1456 28 ▶ prefix => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1457 # my ( $self, $def, $ctx, $tkn, $tokens ) = @_;
1458 28 my ( $self, undef, undef, $tkn, $tokens ) = @_;
1459 28 ▶ @{ $tokens }
Branch: 1 branch
BranchTrueFalseTotal
@{$tokens;} or $self->wail("'${tkn}' requires an argument") 28 0 28
1460 or $self->wail( "'$tkn' requires an argument" );
1461 28 return;
1462 },
1463 24 ▶ terminal => sub {
Subroutine __ANON__: called CC=5 SCAR=16.4
1464 # my ( $self, $def, $ctx, $tkn, $tokens ) = @_;
1465 24 my ( $self, undef, $ctx, $tkn, $tokens ) = @_;
1466 24 ▶ @{ $ctx->[-1]{value} }
Branch: 1 branch
BranchTrueFalseTotal
@{$ctx->[-1]{"value"};} or $self->wail("'${tkn}' requires a left argument") 24 0 24
1467 or $self->wail( "'$tkn' requires a left argument" );
1468 24 ▶ if ( $ctx->[-1]{dispatch} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->[-1]{'dispatch'}) { } 22 2 24
1469 22 ▶ @{ $tokens }
Branch: 1 branch
BranchTrueFalseTotal
@{$tokens;} or $self->wail("Command required after '${tkn}'") 22 0 22
1470 or $self->wail( "Command required after '$tkn'" );
1471 } else {
1472 2 ▶ @{ $tokens }
Branch: 1 branch
BranchTrueFalseTotal
@{$tokens;} and $self->wail("Command not allowed after '${tkn}'") 0 2 2
1473 and $self->wail( "Command not allowed after '$tkn'" );
1474 }
1475 24 return;
1476 }
1477 },
1478 20 );
1479  
1480 2 ▶ sub elsif : method Verb() Tweak( -unsatisfied ) { ## no critic (ProhibitBuiltInHomonyms)
Subroutine elsif: called CC=6 SCAR=20.5
Pod documented
1481 2 my ( $self, @args ) = @_;
1482 @args
1483 2 ▶ or $self->wail( 'Arguments required' );
Branch: 1 branch
BranchTrueFalseTotal
@args or $self->wail("Arguments required") 2 0 2
1484  
1485 2 @{ $self->{frame} } > 1
1486 and 'begin' eq $self->{frame}[-1]{type}
1487 and 'if' eq $self->{frame}[-2]{type}
1488 2 ▶ or $self->wail( 'Elsif without if ... then begin' );
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"} or $self->wail("Elsif without if ... then begin") 2 0 2
Condition33%2/6
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"}
!ll&&!rl&&r
002
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"}
!ll&&!rl&&r
002
MC/DC0%0/3
@{$self->{"frame"};} > 1 and "begin" eq $self->{"frame"}[-1]{"type"} and "if" eq $self->{"frame"}[-2]{"type"}
@{$self->{"frame"};} > 1 "begin" eq $self->{"frame"}[-1]{"type"} "if" eq $self->{"frame"}[-2]{"type"}
Truth table25%1/4
A and B and C
A= @{$self->{"frame"};} > 1B= "begin" eq $self->{"frame"}[-1]{"type"}C= "if" eq $self->{"frame"}[-2]{"type"}
ABCresult
0XX0
10X0
1100
1111
1489  
1490 2 my @ctx = ( {
1491 dispatch => 0,
1492 value => [],
1493 } );
1494  
1495 # If any previous if() or elsif() evaluates true, we do not
1496 # evaluate subsequent elsif() calls.
1497 $self->{frame}[-2]{condition}
1498 2 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"frame"}[-2]{"condition"} and return 0 2 2
1499 2 return $self->__infix_engine( \%define, \@ctx, @args );
1500 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
1501  
1502 22 ▶ sub if : method Verb() Tweak( -unsatisfied ) { ## no critic (ProhibitBuiltInHomonyms)
Subroutine if: called CC=2 SCAR=7.0
Pod documented
1503 22 my ( $self, @args ) = @_;
1504 @args
1505 22 ▶ or $self->wail( 'Arguments required' );
Branch: 1 branch
BranchTrueFalseTotal
@args or $self->wail("Arguments required") 22 0 22
1506 22 my @ctx = ( {
1507 dispatch => 1,
1508 value => [],
1509 } );
1510 22 return $self->__infix_engine( \%define, \@ctx, @args );
1511 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
1512 }
1513  
1514 20 ▶sub init {
Subroutine init: not called CC=5 SCAR=33.1
Pod documented
1515 0 my ( $self, @args ) = @_;
1516  
1517 0 ▶ my $opt = HASH_REF eq ref $args[0] ? shift @args : {};
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $args[0] ? : 0 0 0
1518 0 my $init_file = shift @args;
1519  
1520 0 $self->{initfile} = undef;
1521  
1522 0 ▶ foreach (
Branch: 1 branch
BranchTrueFalseTotal
defined $init_file ? : 0 0 0
1523 defined $init_file ? (
1524 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1525 # A missing init file is only an error if it was
1526 # specified explicitly.
1527 0 ▶ -e $init_file
Branch: 1 branch
BranchTrueFalseTotal
-e $init_file and not -d _ or $self->wail("Initialization file $init_file not found, or is a directory") 0 0 0
Condition0%0/3
-e $init_file and not -d _
!ll&&!rl&&r
000
MC/DC0%0/2
-e $init_file and not -d _
-e $init_file not -d _
Truth table0%0/3
A and not(B)
A= -e $init_fileB= not -d _
ABresult
0X0
100
111
1528 and not -d _
1529 or $self->wail(
1530 "Initialization file $init_file not found, or is a directory"
1531 );
1532 return ( $init_file, $opt->{level1} )
1533 0 },
1534 ) : (
1535 0 ▶ sub { return $ENV{SATPASS2INI} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1536 0 ▶ sub { $self->initfile( { quiet => 1 } ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1537 0 ▶ sub { return ( $ENV{SATPASSINI}, 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1538 \&_init_file_01,
1539 )
1540 ) {
1541  
1542 0 my ( $fn, $level1 ) = $_->($self);
1543 0 ▶ my $reader = $self->_file_reader( $fn, { optional => 1 } )
Branch: 1 branch
BranchTrueFalseTotal
my $reader = $self->_file_reader($fn, {"optional", 1}) or next 0 0 0
1544 or next;
1545 0 $self->{initfile} = $fn;
1546 0 return $self->source( { level1 => $level1 }, $reader );
1547  
1548 }
1549  
1550 0 return;
1551 }
1552  
1553 0 ▶sub initfile : Verb( create-directory! quiet! ) {
Subroutine initfile: not called CC=3 SCAR=24.8
Pod documented
1554 0 my ( $self, $opt ) = __arguments( @_ ); # @args unused
1555  
1556 my $init_dir = my_dist_config(
1557 0 { create => $opt->{'create-directory'} } );
1558  
1559 defined $init_dir
1560 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
defined $init_dir or do { $opt->{"quiet"} and return; $self->wail("Init file directory not found") } 0 0 0
1561 0 ▶ $opt->{quiet} and return;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"quiet"} and return 0 0 0
1562 0 $self->wail(
1563 'Init file directory not found' );
1564 };
1565  
1566 0 return File::Spec->catfile( $init_dir, 'satpass2rc' );
1567 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1568  
1569 290 ▶sub _in_unsatisfied_if {
Subroutine _in_unsatisfied_if: called CC=2 SCAR=7.1
1570 290 my ( $self ) = @_;
1571 290 ▶ return @{ $self->{frame} } ? $self->{frame}[-1]{unsatisfied_if} : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'frame'};} ? : 290 0 290
1572 }
1573  
1574 # This is a generalized infix expression engine. It does not implement
1575 # operator precedence and is therefore very small. The arguments are:
1576 # - $self is the invocant, which must be an
1577 # Astro::App::Satpass2::Copier.
1578 # - $def is the hash that defines the grammar. This provides the
1579 # following keys:
1580 # {done} is an optional code reference. If present, the code
1581 # reference is called once the parse is complete, and passed
1582 # ( $self, $def, $ctx, \@tokens ). It returns nothing. The intent
1583 # is to throw an exception if the parse is incomplete.
1584 # {oper} defines the operators. This is a hash keyed by the literal
1585 # operator (i.e. '+' to implement a '+' operator), and having the
1586 # following values:
1587 # {handler} is a required code reference, which implements the
1588 # operator. It is passed ( $self, $def, $ctx, \@tokens ). The
1589 # @tokens do not include the operator itself.
1590 # {validation} is an optional validation specification. If
1591 # present it is a key in the {vld} (see below).
1592 # {val} is an optional code reference. If present, it is called if a
1593 # token is not recognized as an operator, and passed ( $self,
1594 # $def, $ctx, \@tokens ). The @tokens include the unrecognized
1595 # token, which is presumed to be a value, and must be removed
1596 # from @tokens.
1597 # {vld} is a hash of validators. The keys are values in the
1598 # {validation} key documented under {oper} (above), and the
1599 # values are code references which are called with ( $self, $ctx,
1600 # $tkn, \@tokens ) where $tkn is the token being validated, and
1601 # @tokens is the rest of the tokens. This hash must exist if the
1602 # {validation} key is used in {oper}; otherwise it is optional.
1603 # - $ctx is context for the operations. It is not used by the engine
1604 # itself, but the individual operator code will need to use it as
1605 # context for the parse. See if() for an example.
1606 # - @tokens are the tokens to be evaluated by the engine.
1607 24 ▶sub __infix_engine {
Subroutine __infix_engine: called CC=4 SCAR=14.0
1608 24 my ( $self, $def, $ctx, @tokens ) = @_;
1609 @tokens
1610 24 ▶ or $self->wail( 'Nothing to compute' );
Branch: 1 branch
BranchTrueFalseTotal
@tokens or $self->wail("Nothing to compute") 24 0 24
1611 24 my $rslt;
1612 24 ▶ while ( @tokens ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 50 24 74
1613 50 $rslt = $self->_infix_engine_dispatch( $def, $ctx, \@tokens );
1614 }
1615 $def->{done}
1616 24 ▶ and $def->{done}->( $self, $def, $ctx, \@tokens );
Branch: 1 branch
BranchTrueFalseTotal
$def->{"done"} and $def->{"done"}->($self, $def, $ctx, \@tokens) 24 0 24
1617 24 return $rslt;
1618 }
1619  
1620 61 ▶sub _infix_engine_dispatch {
Subroutine _infix_engine_dispatch: called CC=5 SCAR=16.6
1621 61 my ( $self, $def, $ctx, $tokens ) = @_;
1622 61 ▶ @{ $tokens }
Branch: 1 branch
BranchTrueFalseTotal
@{$tokens;} or return 61 0 61
1623 or return;
1624 61 my $tkn = shift @{ $tokens };
1625 61 ▶ if ( my $info = $def->{oper}{$tkn} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $info = $def->{'oper'}{$tkn}) { } 57 4 61
elsif ($def->{'val'}) { } 4 0 4
1626 $info->{validation}
1627 57 ▶ and $def->{vld}{ $info->{validation} }->(
Branch: 1 branch
BranchTrueFalseTotal
$info->{"validation"} and $def->{"vld"}{$info->{"validation"}}($self, $def, $ctx, $tkn, $tokens) 55 2 57
1628 $self, $def, $ctx, $tkn, $tokens );
1629 57 return $info->{handler}->( $self, $def, $ctx, $tokens );
1630 } elsif ( $def->{val} ) {
1631 4 return $def->{val}->( $self, $def, $ctx, $tkn, $tokens );
1632 } else {
1633 0 $self->wail( "Unrecognized token '$tkn'" );
1634 }
1635 0 return; # We can't get here, but Perl::Critic does not know this.
1636 }
1637  
1638 # $file_name = _init_file_01()
1639 #
1640 # This subroutine returns the first alternate init file name,
1641 # which is the standard name for the Astro-satpass 'satpass'
1642 # script. If called in list context it returns not only the name,
1643 # but a 1 to tell the caller this is a 'level1' file.
1644  
1645 0 ▶sub _init_file_01 {
Subroutine _init_file_01: not called CC=10 SCAR=47.0
1646 0 ▶ my $inifn = $^O eq 'MSWin32' || $^O eq 'VMS' || $^O eq 'MacOS' ?
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' || $^O eq 'VMS' || $^O eq 'MacOS' ? : 0 0 0
Condition0%0/6
$^O eq "MSWin32" or $^O eq "VMS" or $^O eq "MacOS"
l!l&&r!l&&!r
000
$^O eq "MSWin32" or $^O eq "VMS"
l!l&&r!l&&!r
000
MC/DC0%0/3
$^O eq "MSWin32" or $^O eq "VMS" or $^O eq "MacOS"
$^O eq "MSWin32" $^O eq "VMS" $^O eq "MacOS"
Truth table0%0/4
A or B or C
A= $^O eq "MSWin32"B= $^O eq "VMS"C= $^O eq "MacOS"
ABCresult
1XX1
01X1
0011
0000
1647 'satpass.ini' : '.satpass';
1648 my $inifile = $^O eq 'VMS' ? "SYS\$LOGIN:$inifn" :
1649 $^O eq 'MacOS' ? $inifn :
1650 $ENV{HOME} ? "$ENV{HOME}/$inifn" :
1651 $ENV{LOGDIR} ? "$ENV{LOGDIR}/$inifn" :
1652 0 ▶ $ENV{USERPROFILE} ? "$ENV{USERPROFILE}" : undef;
Branch: 5 branches
BranchTrueFalseTotal
$^O eq 'VMS' ? : 0 0 0
$^O eq 'MacOS' ? : 0 0 0
$ENV{'HOME'} ? : 0 0 0
$ENV{'LOGDIR'} ? : 0 0 0
$ENV{'USERPROFILE'} ? : 0 0 0
1653 0 ▶ return wantarray ? ( $inifile, 1 ) : $inifile;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1654 }
1655  
1656 7 ▶sub list : Verb( choose=s@ ) {
Subroutine list: called CC=5 SCAR=17.0
Pod documented
1657 7 my ( $self, $opt, @args ) = __arguments( @_ );
1658  
1659 @args
1660 and not $opt->{choose}
1661 7 ▶ and $opt->{choose} = \@args;
Branch: 1 branch
BranchTrueFalseTotal
@args and not $opt->{"choose"} and $opt->{"choose"} = \@args 0 7 7
Condition33%1/3
@args and not $opt->{"choose"}
!ll&&!rl&&r
700
MC/DC0%0/2
@args and not $opt->{"choose"}
@args not $opt->{"choose"}
Truth table33%1/3
A and not(B)
A= @argsB= not $opt->{"choose"}
ABresult
0X0
100
111
1662 7 my @bodies = $self->__choose( $opt->{choose}, $self->{bodies} );
1663  
1664 @bodies
1665 7 ▶ and return $self->__format_data(
Branch: 1 branch
BranchTrueFalseTotal
@bodies and return $self->__format_data("list", \@bodies, $opt) 5 2 7
1666 list => \@bodies, $opt );
1667  
1668 $self->{warn_on_empty}
1669 2 ▶ and $self->whinge( 'The observing list is empty' );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"warn_on_empty"} and $self->whinge("The observing list is empty") 0 2 2
1670  
1671 2 return;
1672 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1673  
1674 6 ▶sub load : Verb( verbose! ) {
Subroutine load: called CC=4 SCAR=14.0
Pod documented
1675 6 my ( $self, $opt, @names ) = __arguments( @_ );
1676 6 ▶ @names or $self->wail( 'No file names specified' );
Branch: 1 branch
BranchTrueFalseTotal
@names or $self->wail("No file names specified") 6 0 6
1677  
1678 6 my $attrs = {
1679 illum => $self->get( 'illum' ),
1680 model => $self->get( 'model' ),
1681 sun => $self->_sky_object( 'sun' ),
1682 };
1683  
1684 6 foreach my $fn ( @names ) {
1685 6 ▶ $opt->{verbose} and warn "Loading $fn\n";
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"verbose"} and warn "Loading $fn\n" 0 6 6
1686 6 my $data = $self->_file_reader( $fn, { glob => 1 } );
1687 5 $self->__add_to_observing_list(
1688 Astro::Coord::ECI::TLE->parse( $attrs, $data ) );
1689 }
1690 5 return;
1691 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1692  
1693 1 ▶sub localize : Verb( all|except! ) {
Subroutine localize: called CC=4 SCAR=15.9
Pod documented
1694 1 my ( $self, $opt, @args ) = __arguments( @_ );
1695  
1696 1 foreach my $name ( @args ) {
1697 2 $self->_attribute_exists( $name );
1698 }
1699  
1700 1 ▶ if ( $opt->{all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"all"}) 0 1 1
1701 0 my %except = map { $_ => 1 } @args;
1702 0 @args = grep { ! $except{$_} } sort keys %mutator;
1703 }
1704  
1705 1 foreach my $name ( @args ) {
1706 2 $self->_localize( $name );
1707 }
1708  
1709 1 return;
1710 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1711  
1712 2 ▶sub _localize {
Subroutine _localize: called CC=6 SCAR=20.5
1713 2 my ( $self, $key ) = @_;
1714  
1715 my $val = exists $self->{$key} ?
1716 2 ▶ $self->{$key} :
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$key} ? : 2 0 2
1717 $self->get( $key );
1718 2 ▶ my $clone = ( blessed( $val ) && $val->can( 'clone' ) ) ?
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($val) && $val->can('clone') ? : 0 2 2
ref $val ? : 0 2 2
Condition33%1/3
builtin::blessed($val) and $val->can("clone")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($val) and $val->can("clone")
builtin::blessed($val) $val->can("clone")
Truth table33%1/3
A and B
A= builtin::blessed($val)B= $val->can("clone")
ABresult
0X0
100
111
1719 $val->clone() :
1720 ref $val ? Clone::clone( $val ) : $val;
1721  
1722 2 $self->{frame}[-1]{local}{$key} = $val;
1723 2 ▶ if ( exists $self->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$key}) { } 2 0 2
1724 2 $self->{$key} = $clone;
1725 } else {
1726 0 $self->set( $key => $clone );
1727 }
1728  
1729 2 return;
1730 }
1731  
1732 3 ▶sub location : Verb( dump! ) {
Subroutine location: called CC=1 SCAR=0.0
Pod documented
1733 3 my ( $self, $opt ) = __arguments( @_ );
1734 3 return $self->__format_data(
1735 location => $self->station(), $opt );
1736 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1737  
1738 {
1739  
1740 # TODO the %mac_cmd hash is only needed for level1 compatibility.
1741 # Once that goes away, it can too PROVIDED we also drop the
1742 # subcommand defaulting functionality.
1743 # Subcommand defaulting dropped 2021-09-20 unless explicitly level1,
1744 # after I discovered that my init file defined an unwanted macro
1745 # when I mistyped 'define' as 'defined'.
1746 20 my %mac_cmd;
1747 {
1748 20 my $stb = __PACKAGE__ . '::';
1749 20 my @cmdnam;
1750 {
1751 20 ▶ no strict qw{ refs };
Subroutine BEGIN: called CC=1 SCAR=0.0
1752 20 foreach my $entry ( keys %{ $stb } ) {
1753 8242 ▶ $entry =~ m/ \A _macro_sub_ ( \w+ ) /smx
Branch: 1 branch
BranchTrueFalseTotal
$entry =~ / \A _macro_sub_ ( \w+ ) /msx or next 100 8142 8242
1754 or next;
1755 # Strictly speaking I should make sure the {CODE} slot
1756 # is occupied here.
1757 100 push @cmdnam, $1;
1758 }
1759 }
1760 20 my %abbr = abbrev(@cmdnam);
1761 20 foreach (keys %abbr) {
1762 380 $mac_cmd{'-' . $_} = $abbr{$_};
1763 }
1764 20 foreach (@cmdnam) {
1765 100 $mac_cmd{$_} = $_;
1766 }
1767 }
1768  
1769 # NOTE that we must not define command options here, but on the
1770 # individual _macro_sub_* methods. Or at least we must not define
1771 # any command options here that get passed to the _macro_sub_*
1772 # methods.
1773 32 ▶ sub macro : Verb() Tweak( -completion _readline_complete_subcommand ) {
Subroutine macro: called CC=7 SCAR=21.8
Pod documented
1774 32 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
1775 32 my $cmd;
1776 32 ▶ if (!@args) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @args) { } 0 32 32
elsif ($self->{'frame'}[-1]{'level1'}) { } 8 24 32
1777 0 $cmd = 'brief';
1778 } elsif ( $self->{frame}[-1]{level1} ) {
1779 8 ▶ if ($mac_cmd{$args[0]}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mac_cmd{$args[0]}) { } 0 8 8
elsif (@args > 1) { } 8 0 8
1780 0 $cmd = $mac_cmd{shift @args};
1781 } elsif (@args > 1) {
1782 8 $cmd = 'define';
1783 } else {
1784 0 $cmd = 'list';
1785 }
1786 } else {
1787 24 ▶ defined( $cmd = $mac_cmd{ $args[0] } )
Branch: 1 branch
BranchTrueFalseTotal
defined($cmd = $mac_cmd{$args[0]}) or $cmd = $args[0] 24 0 24
1788 or $cmd = $args[0];
1789 24 shift @args;
1790 }
1791  
1792 32 ▶ my $code = $self->can( "_macro_sub_$cmd" )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can("_macro_sub_$cmd") or $self->wail("Subcommand '${cmd}' unknown") 32 0 32
1793 or $self->wail( "Subcommand '$cmd' unknown" );
1794 32 return $code->( $self, @args );
1795 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
1796 }
1797  
1798 # Calls to the following _macro_sub_... methods are generated dynamically
1799 # above, so there is no way Perl::Critic can find them.
1800 20 ▶sub _macro_sub_brief : Verb() Tweak( -completion _macro_list_complete ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_sub_brief: called CC=4 SCAR=14.1
1801 3 my ( $self, undef, @args ) = __arguments( @_ );
1802 3 my $output;
1803 3 ▶ foreach my $name (sort @args ? @args : keys %{$self->{macro}}) {
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 3 3
1804 1 ▶ $self->{macro}{$name} and $output .= $name . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"macro"}{$name} and $output .= $name . "\n" 1 0 1
1805 }
1806 3 return $output;
1807 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1808  
1809 19 ▶sub _macro_sub_define : Verb( completion=s@ ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_sub_define: called CC=5 SCAR=17.5
1810 19 my ( $self, $opt, $name, @args ) = __arguments( @_ );
1811 19 my $output;
1812 19 ▶ defined $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name or return $self->__wail("You must provide a name for the macro") 19 0 19
1813 or return $self->__wail( 'You must provide a name for the macro' );
1814 @args
1815 19 ▶ or return $self->__wail( 'You must provide a definition for the macro' );
Branch: 1 branch
BranchTrueFalseTotal
@args or return $self->__wail("You must provide a definition for the macro") 19 0 19
1816  
1817 19 ▶ $name !~ m/ \W /smx
Branch: 1 branch
BranchTrueFalseTotal
$name =~ / \W /msx || $name =~ / \A _ /msx and return $self->__wail("Invalid macro name '${name}'") 0 19 19
Condition33%1/3
$name =~ / \W /msx or $name =~ / \A _ /msx
l!l&&r!l&&!r
0019
MC/DC0%0/2
$name =~ / \W /msx or $name =~ / \A _ /msx
$name =~ / \W /msx $name =~ / \A _ /msx
Truth table33%1/3
A or B
A= $name =~ / \W /msxB= $name =~ / \A _ /msx
ABresult
1X1
011
000
1818 and $name !~ m/ \A _ /smx
1819 or return $self->__wail("Invalid macro name '$name'");
1820  
1821 # NOTE the value of {def} used to be unescaped, but I do not now
1822 # know why, and the implementation of \U and friends is more natural
1823 # with this stripped out.
1824 $self->{macro}{$name} =
1825 Astro::App::Satpass2::Macro::Command->new(
1826 name => $name,
1827 parent => $self,
1828 completion => $opt->{completion},
1829 def => \@args,
1830 generate => \&_macro_define_generator,
1831 level1 => $self->{frame}[-1]{level1},
1832 warner => $self->{_warner},
1833 19 );
1834 19 return $output;
1835 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1836  
1837 9 ▶sub _macro_define_generator {
Subroutine _macro_define_generator: called CC=3 SCAR=11.2
1838 9 my ( $self, @args ) = @_; # $self if Macro object
1839 9 my $output;
1840 9 foreach my $macro ( @args ) {
1841 9 ▶ if ( my $comp = $self->completion() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $self->completion) { } 0 9 9
1842 0 $output .= "macro define \\\n " .
1843 "--completion '@$comp' \\\n " .
1844 "$macro \\\n ";
1845 } else {
1846 9 $output .= "macro define $macro \\\n ";
1847 }
1848 9 $output .= join( " \\\n ", map { quoter( $_ ) } $self->def() ) .
1849 "\n";
1850 }
1851 9 return $output;
1852 }
1853  
1854 1 ▶sub _macro_sub_delete : Verb() Tweak( -completion _macro_list_complete ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_sub_delete: called CC=3 SCAR=11.4
1855 1 my ( $self, undef, @args ) = __arguments( @_ );
1856 1 my $output;
1857 0 ▶ foreach my $name (@args ? @args : keys %{$self->{macro}}) {
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
1858 1 delete $self->{macro}{$name};
1859 }
1860 1 return $output;
1861 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1862  
1863 9 ▶sub _macro_sub_list : Verb() Tweak( -completion _macro_list_complete ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_sub_list: called CC=4 SCAR=13.9
1864 9 my ( $self, undef, @args ) = __arguments( @_ );
1865 9 my $output;
1866 9 ▶ foreach my $name (sort @args ? @args : keys %{$self->{macro}}) {
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 8 1 9
1867 9 ▶ $self->{macro}{$name}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"macro"}{$name} or next 9 0 9
1868 or next;
1869 9 $output .= $self->{macro}{$name}->generator( $name );
1870 }
1871 9 return $output;
1872 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1873  
1874 0 ▶sub _macro_sub_load : Verb( lib=s verbose! ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_sub_load: not called CC=10 SCAR=47.0
1875 0 my ( $self, $opt, $name, @args ) = __arguments( @_ );
1876 0 my $output;
1877 0 ▶ defined $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $self->wail("Must provide name of macro to load") 0 0 0
1878 or $self->wail( 'Must provide name of macro to load' );
1879 my %marg = (
1880 name => $name,
1881 parent => $self,
1882 generate => \&_macro_load_generator,
1883 warner => $self->{_warner},
1884 0 );
1885 exists $opt->{lib}
1886 0 ▶ and $marg{lib} = $opt->{lib};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"lib"} and $marg{"lib"} = $opt->{"lib"} 0 0 0
1887 0 ▶ my $obj = $self->{_macro_load}{$name} ||=
Condition0%0/3
$self->{"_macro_load"}{$name} ||= "Astro::App::Satpass2::Macro::Code"->new(%marg)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_macro_load"}{$name} ||= "Astro::App::Satpass2::Macro::Code"->new(%marg)
$self->{"_macro_load"}{$name} "Astro::App::Satpass2::Macro::Code"->new(%marg)
Truth table0%0/3
A ||= B
A= $self->{"_macro_load"}{$name}B= "Astro::App::Satpass2::Macro::Code"->new(%marg)
ABresult
1X1
011
000
1888 Astro::App::Satpass2::Macro::Code->new( %marg );
1889 0 ▶ foreach my $mn ( @args ? @args : $obj->implements() ) {
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
1890 $obj->implements( $mn, required => 1 )
1891 0 ▶ and $self->{macro}{$mn} = $obj;
Branch: 1 branch
BranchTrueFalseTotal
$obj->implements($mn, "required", 1) and $self->{"macro"}{$mn} = $obj 0 0 0
1892 }
1893 0 ▶ if ( $opt->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"verbose"}) 0 0 0
1894 0 ( my $fn = "$name.pm" ) =~ s| :: |/|smxg;
1895 0 $output .= "Macro $name\n loaded from $INC{$fn}\n";
1896 0 $output .= " implements:\n";
1897 0 $output .= " $_\n" for sort $obj->implements();
1898 }
1899 0 ▶ $obj->implements( 'after_load', required => 0 )
Branch: 1 branch
BranchTrueFalseTotal
$obj->implements("after_load", "required", 0) and $output .= $self->dispatch("after_load", $opt, $name, @args) 0 0 0
1900 and $output .= $self->dispatch( after_load => $opt, $name, @args );
1901 0 return $output;
1902 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1903  
1904 2 ▶sub _macro_load_generator {
Subroutine _macro_load_generator: called CC=4 SCAR=14.0
1905 2 my ( $self, @args ) = @_;
1906 2 my @preamble = qw{ macro load };
1907 2 ▶ if ( $self->has_lib() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_lib) 2 0 2
1908 2 push @preamble, '-lib', $self->lib();
1909 2 ▶ $self->relative()
Branch: 1 branch
BranchTrueFalseTotal
$self->relative and push @preamble, "-relative" 2 0 2
1910 and push @preamble, '-relative';
1911 }
1912 2 push @preamble, $self->name();
1913 2 my $output;
1914 2 foreach my $macro ( @args ) {
1915 6 $output .= quoter( @preamble, $macro ) . "\n";
1916 }
1917 2 return $output;
1918 }
1919  
1920 0 ▶sub magnitude_table : Verb( name! reload! ) {
Subroutine magnitude_table: not called CC=6 SCAR=37.4
Pod documented
1921 0 my ( undef, undef, @args ) = __arguments( @_ ); # Invocant, $opt unused
1922  
1923 0 ▶ @args or @args = qw{show};
Branch: 1 branch
BranchTrueFalseTotal
@args or @args = "show" 0 0 0
1924  
1925 0 ▶ my $verb = lc (shift (@args) || 'show');
Condition0%0/2
shift @args || 'show'
l!l
00
MC/DC0%0/1
shift @args || 'show'
shift @args
Truth table0%0/2
A
A= shift @args
Aresult
11
00
1926  
1927 0 my $output;
1928  
1929 0 ▶ if ( $verb eq 'show' || $verb eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq 'show' or $verb eq 'list') { } 0 0 0
Condition0%0/3
$verb eq "show" or $verb eq "list"
l!l&&r!l&&!r
000
MC/DC0%0/2
$verb eq "show" or $verb eq "list"
$verb eq "show" $verb eq "list"
Truth table0%0/3
A or B
A= $verb eq "show"B= $verb eq "list"
ABresult
1X1
011
000
1930  
1931 0 my %data = Astro::Coord::ECI::TLE->magnitude_table( 'show', @args );
1932  
1933 0 foreach my $oid ( sort keys %data ) {
1934 0 $output .= quoter( 'status', 'add', $oid, $data{$oid} )
1935 . "\n";
1936 }
1937  
1938 } else {
1939 0 Astro::Coord::ECI::TLE->magnitude_table( $verb, @args );
1940 }
1941  
1942 0 return $output;
1943  
1944 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1945  
1946 # Attributes must all be on one line to process correctly under Perl
1947 # 5.8.8.
1948 20 ▶sub pass : Verb( :compute __pass_options ) {
Subroutine pass: called CC=34 SCAR=39.6
Pod documented
1949 20 my ( $self, $opt, @args ) = __arguments( @_ );
1950  
1951 $opt->{ephemeris}
1952 20 ▶ and $opt->{almanac} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"ephemeris"} and $opt->{"almanac"} = 1 1 19 20
1953 $opt->{almanac}
1954 and not defined $opt->{ephemeris}
1955 and $opt->{ephemeris} = {
1956 pass_ics => 1,
1957 20 ▶ }->{$opt->{_template}};
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"almanac"} and not defined $opt->{"ephemeris"} and $opt->{"ephemeris"} = {"pass_ics", 1}->{$opt->{"_template"}} 3 17 20
Condition100%3/3
$opt->{"almanac"} and not defined $opt->{"ephemeris"}
!ll&&!rl&&r
1613
MC/DC100%2/2
$opt->{"almanac"} and not defined $opt->{"ephemeris"}
$opt->{"almanac"} not defined $opt->{"ephemeris"}
Truth table100%3/3
A and not(B)
A= $opt->{"almanac"}B= not defined $opt->{"ephemeris"}
ABresult
0X0
100
111
1958  
1959 20 $self->_apply_boolean_default(
1960 $opt, 0, qw{ horizon illumination transit appulse } );
1961 20 $self->_apply_boolean_default( $opt, 0, qw{ am pm } );
1962 20 ▶ $opt->{am} or $opt->{pm} or $opt->{am} = $opt->{pm} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"am"} or $opt->{"pm"} or $opt->{"am"} = $opt->{"pm"} = 1 20 0 20
Condition66%2/3
$opt->{"am"} or $opt->{"pm"}
l!l&&r!l&&!r
1910
MC/DC0%0/2
$opt->{"am"} or $opt->{"pm"}
$opt->{"am"} $opt->{"pm"}
Truth table66%2/3
A or B
A= $opt->{"am"}B= $opt->{"pm"}
ABresult
1X1
011
000
1963 20 my $pass_start = $self->__parse_time (
1964 shift @args, $self->_get_day_noon());
1965 20 ▶ my $pass_end = $self->__parse_time (shift @args || '+7');
Condition100%2/2
shift @args || '+7'
l!l
146
MC/DC100%1/1
shift @args || '+7'
shift @args
Truth table100%2/2
A
A= shift @args
Aresult
11
00
1966 20 ▶ $pass_start >= $pass_end
Branch: 1 branch
BranchTrueFalseTotal
$pass_start >= $pass_end and $self->wail("End time must be after start time") 0 20 20
1967 and $self->wail( 'End time must be after start time' );
1968  
1969 20 my $sta = $self->station();
1970 my @bodies = $self->__choose( $opt->{choose}, $self->{bodies} )
1971 20 ▶ or $self->wail( 'No bodies selected' );
Branch: 1 branch
BranchTrueFalseTotal
my(@bodies) = $self->__choose($opt->{"choose"}, $self->{"bodies"}) or $self->wail("No bodies selected") 20 0 20
1972 20 ▶ my $pass_step = shift @args || 60;
Condition50%1/2
shift @args || 60
l!l
020
MC/DC0%0/1
shift @args || 60
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
1973  
1974 # Decide which model to use.
1975  
1976 20 my $model = $self->{model};
1977  
1978 # Set the station for the objects in the sky.
1979  
1980 20 foreach my $body ( @{ $self->{sky} } ) {
1981 41 $body->set( station => $sta );
1982 }
1983  
1984 # Pick up horizon and appulse distance.
1985  
1986 20 my $horizon = deg2rad ($self->{horizon});
1987 20 my $appulse = deg2rad ($self->{appulse});
1988 20 my $pass_threshold = deg2rad( $self->{pass_threshold} );
1989  
1990 # In order that the interface not be completely rude, the interface
1991 # allows -brightest to specify that you want the 'brightest' event.
1992 # But this is controlled by the pass_variant attribute. So if
1993 # -brightest appears, the pass_variant from it; otherwise we default
1994 # -brightest from the pass_variant attribute. We localize the
1995 # pass_variant attribute before modifying it, since the -brightest
1996 # option is to hold for this call only. We modify it (rather than
1997 # just passing a local copy to the bodies) because
1998 # Formatter::Template needs to know what it is, and modifying this
1999 # object is the obvious way to pass the information.
2000 20 local $self->{pass_variant} = $self->{pass_variant};
2001 20 ▶ if ( $opt->{brightest} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->{'brightest'}) { } 0 20 20
elsif (exists $opt->{'brightest'}) { } 0 20 20
2002 0 $self->{pass_variant} |= PASS_VARIANT_BRIGHTEST;
2003 } elsif ( exists $opt->{brightest} ) {
2004 0 $self->{pass_variant} &= ~ PASS_VARIANT_BRIGHTEST;
2005 } else {
2006 20 $opt->{brightest} = $self->{pass_variant} & PASS_VARIANT_BRIGHTEST;
2007 }
2008 20 my $pass_variant = $self->{pass_variant};
2009  
2010 # Foreach body to be modelled
2011  
2012 20 my @accumulate; # For chronological output.
2013 20 foreach my $tle ( $self->_aggregate( \@bodies ) ) {
2014  
2015 {
2016 39 ▶ my $mdl = $tle->get('inertial') ? $model :
Branch: 1 branch
BranchTrueFalseTotal
$tle->get('inertial') ? : 39 0 39
2017 $tle->get('model');
2018 $tle->set (
2019 appulse => $appulse,
2020 backdate => $self->{backdate},
2021 debug => $self->{debug},
2022 edge_of_earths_shadow => $self->{edge_of_earths_shadow},
2023 geometric => $self->{geometric},
2024 horizon => $horizon,
2025 interval => ( $self->{verbose} ? $pass_step : 0 ),
2026 model => $mdl,
2027 pass_threshold => $pass_threshold,
2028 pass_variant => $pass_variant,
2029 station => $sta,
2030 twilight => $self->{_twilight},
2031 visible => $self->{visible},
2032 39 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'verbose'} ? : 0 39 39
2033 }
2034  
2035 eval {
2036 push @accumulate, $self->_pass_select_event( $opt, $tle->pass (
2037 39 $pass_start, $pass_end, $self->{sky} ) );
2038 39 1;
2039 39 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { push @accumulate, $self->_pass_select_event($opt, $tle->pass($pass_start, $pass_end, $self->{"sky"})); 1 } } or do { $@ =~ / \Q$interrupted\E /mosx and $self->wail($@); $opt->{"quiet"} or $self->whinge($@) } 39 0 39
2040 0 ▶ $@ =~ m/ \Q$interrupted\E /smxo and $self->wail($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ =~ / \Q$interrupted\E /mosx and $self->wail($@) 0 0 0
2041 0 ▶ $opt->{quiet} or $self->whinge($@);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"quiet"} or $self->whinge($@) 0 0 0
2042 };
2043 }
2044  
2045 20 @accumulate = $self->__pass_filter_am_pm( $opt, @accumulate );
2046  
2047 $opt->{chronological}
2048 0 ▶ and @accumulate = sort { $a->{time} <=> $b->{time} }
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"chronological"} and @accumulate = sort {$Astro::App::Satpass2::a->{"time"} <=> $Astro::App::Satpass2::b->{"time"};} @accumulate 3 17 20
2049 @accumulate;
2050  
2051 # Record number of events found.
2052 # NOTE that in this case an event is an entire pass.
2053  
2054 20 $self->{events} += @accumulate;
2055  
2056 20 ▶ if ( $opt->{almanac} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"almanac"}) 4 16 20
2057 4 my %almanac;
2058 4 foreach my $pass ( @accumulate ) {
2059 6 my $illum = $pass->{body}->get( 'illum' );
2060 6 my $noon = $self->_get_day_noon( $pass->{time} );
2061 6 ▶ $almanac{$noon}{$illum} ||= do {
Condition33%1/3
$almanac{$noon}{$illum} ||= do { my @day; my(@events) = grep({{"horizon", 1, "twilight", 1}->{$_->{"almanac"}{"event"}};} $illum->almanac_hash($self->_get_day_midnight($pass->{"time"}))); _almanac_localize(@events); foreach my $evt (@events) { $evt->{"event"} = "almanac"; my $pm = $evt->{"time"} >= $noon ? 1 : 0; push @{$day[$pm];}, $evt; } ; \@day }
l!l&&r!l&&!r
060
MC/DC0%0/2
$almanac{$noon}{$illum} ||= do { my @day; my(@events) = grep({{"horizon", 1, "twilight", 1}->{$_->{"almanac"}{"event"}};} $illum->almanac_hash($self->_get_day_midnight($pass->{"time"}))); _almanac_localize(@events); foreach my $evt (@events) { $evt->{"event"} = "almanac"; my $pm = $evt->{"time"} >= $noon ? 1 : 0; push @{$day[$pm];}, $evt; } ; \@day }
$almanac{$noon}{$illum} do { my @day; my(@events) = grep({{"horizon", 1, "twilight", 1}->{$_->{"almanac"}{"event"}};} $illum->almanac_hash($self->_get_day_midnight($pass->{"time"}))); _almanac_localize(@events); foreach my $evt (@events) { $evt->{"event"} = "almanac"; my $pm = $evt->{"time"} >= $noon ? 1 : 0; push @{$day[$pm];}, $evt; } ; \@day }
Truth table33%1/3
A ||= B
A= $almanac{$noon}{$illum}B= do { my @day; my(@events) = grep({{"horizon", 1, "twilight", 1}->{$_->{"almanac"}{"event"}};} $illum->almanac_hash($self->_get_day_midnight($pass->{"time"}))); _almanac_localize(@events); foreach my $evt (@events) { $evt->{"event"} = "almanac"; my $pm = $evt->{"time"} >= $noon ? 1 : 0; push @{$day[$pm];}, $evt; } ; \@day }
ABresult
1X1
011
000
2062 6 my @day;
2063  
2064 my @events = grep { {
2065 horizon => 1,
2066 twilight => 1,
2067 }->{$_->{almanac}{event}}
2068 36 } $illum->almanac_hash(
2069 6 $self->_get_day_midnight( $pass->{time} ) );
2070  
2071 6 _almanac_localize( @events );
2072  
2073 6 foreach my $evt ( @events ) {
2074 24 $evt->{event} = 'almanac';
2075 24 ▶ my $pm = $evt->{time} >= $noon ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$evt->{'time'} >= $noon ? : 12 12 24
2076 24 push @{ $day[$pm] }, $evt;
2077 }
2078  
2079 6 \@day;
2080 };
2081  
2082 6 ▶ $pass->{_pm} = my $pm = $pass->{time} >= $noon ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$pass->{'time'} >= $noon ? : 0 6 6
2083 # TODO this way ALL passes get the almanac events. Is this
2084 # what I want? It varies. For --ics it is. For --events it
2085 # is not. For neither it's probably not.
2086 6 ▶ if ( $opt->{ephemeris} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"ephemeris"}) 3 3 6
2087 3 @{ $pass->{events} } = sort { $a->{time} <=> $b->{time}
2088 3 } @{ $pass->{events} }, @{ $almanac{$noon}{$illum}[$pm] };
2089 }
2090 }
2091  
2092 4 ▶ unless( $opt->{ephemeris} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"ephemeris"}) 2 2 4
2093 2 foreach my $pass ( @accumulate ) {
2094 $pass->{_pm}
2095 3 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
$pass->{"_pm"} or next 0 3 3
2096 0 my $illum = $pass->{body}->get( 'illum' );
2097 0 my $noon = $self->_get_day_noon( $pass->{time} );
2098 0 ▶ $almanac{$noon}{$illum}[1]
Branch: 1 branch
BranchTrueFalseTotal
$almanac{$noon}{$illum}[1] or next 0 0 0
2099 or next;
2100 0 @{ $pass->{events} } = sort { $a->{time} <=> $b->{time} }
2101 0 @{ $pass->{events} },
2102 0 @{ $almanac{$noon}{$illum}[1] };
2103 0 $almanac{$noon}{$illum}[1] = undef;
2104 }
2105 2 foreach my $pass ( reverse @accumulate ) {
2106 $pass->{_pm}
2107 3 ▶ and next;
Branch: 1 branch
BranchTrueFalseTotal
$pass->{"_pm"} and next 0 3 3
2108 3 my $illum = $pass->{body}->get( 'illum' );
2109 3 my $noon = $self->_get_day_noon( $pass->{time} );
2110 3 ▶ $almanac{$noon}{$illum}[0]
Branch: 1 branch
BranchTrueFalseTotal
$almanac{$noon}{$illum}[0] or next 3 0 3
2111 or next;
2112 26 @{ $pass->{events} } = sort { $a->{time} <=> $b->{time} }
2113 3 @{ $pass->{events} },
2114 3 @{ $almanac{$noon}{$illum}[0] };
2115 3 $almanac{$noon}{$illum}[0] = undef;
2116 }
2117 }
2118 }
2119  
2120 return $self->__format_data(
2121 20 $opt->{_template} => \@accumulate, $opt );
2122  
2123 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2124  
2125 20 ▶sub __pass_filter_am_pm {
Subroutine __pass_filter_am_pm: called CC=5 SCAR=16.6
2126 20 my ( $self, $opt, @accumulate ) = @_;
2127 20 ▶ $opt ||= {};
Condition50%1/2
$opt ||= {}
l!l
200
MC/DC0%0/1
$opt ||= {}
$opt
Truth table50%1/2
A
A= $opt
Aresult
11
00
2128 $opt->{am} xor $opt->{pm}
2129 20 ▶ or return @accumulate;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"am"} xor $opt->{"pm"} or return @accumulate 2 18 20
Condition75%3/4
$opt->{"am"} xor $opt->{"pm"}
l&&rl&&!r!l&&r!l&&!r
18110
MC/DC100%2/2
$opt->{"am"} xor $opt->{"pm"}
$opt->{"am"} $opt->{"pm"}
Truth table75%3/4
A xor B
A= $opt->{"am"}B= $opt->{"pm"}
ABresult
110
101
011
000
2130 return (
2131 6 map { $_->[0] }
2132 12 ▶ grep { $opt->{am} xor $_->[1] }
Condition50%2/4
$opt->{"am"} ^^ $_->[1]
l&&rl&&!r!l&&r!l&&!r
0606
MC/DC50%1/2
$opt->{"am"} ^^ $_->[1]
$opt->{"am"} $_->[1]
Truth table50%2/4
A ^^ B
A= $opt->{"am"}B= $_->[1]
ABresult
110
101
011
000
2133 2 map { [
2134 $_,
2135 $_->{time} >= $self->_get_day_noon( $_->{time} )
2136 12 ] } @accumulate
2137 );
2138 }
2139  
2140 20 ▶sub __pass_options {
Subroutine __pass_options: called CC=1 SCAR=0.0
2141 20 my ( $self, $opt ) = @_;
2142 return [
2143 20 qw{
2144 almanac! am! appulse! brightest|magnitude! choose=s@
2145 chronological! ephemeris! dump! horizon|rise|set!
2146 illumination! pm!
2147 quiet! transit|maximum|culmination!
2148 },
2149 $self->_templates_to_options( pass => $opt ),
2150 ];
2151 }
2152  
2153 {
2154 20 my @selector;
2155 20 $selector[ PASS_EVENT_SHADOWED ] = 'illumination';
2156 20 $selector[ PASS_EVENT_LIT ] = 'illumination';
2157 20 $selector[ PASS_EVENT_DAY ] = 'illumination';
2158 20 $selector[ PASS_EVENT_RISE ] = 'horizon';
2159 20 $selector[ PASS_EVENT_MAX ] = 'transit';
2160 20 $selector[ PASS_EVENT_SET ] = 'horizon';
2161 20 $selector[ PASS_EVENT_APPULSE ] = 'appulse';
2162 20 $selector[ PASS_EVENT_START ] = 'horizon';
2163 20 $selector[ PASS_EVENT_END ] = 'horizon';
2164 20 $selector[ PASS_EVENT_BRIGHTEST ] = 'brightest';
2165  
2166 # Remove from the pass data any events that are not wanted. The
2167 # arguments are $self, the $opt hash reference that (among other
2168 # things) specifies the desired events, and the passes, each pass
2169 # being an argument. The modified passes are returned.
2170 39 ▶ sub _pass_select_event {
Subroutine _pass_select_event: called CC=3 SCAR=11.0
2171 39 my ( undef, $opt, @passes ) = @_; # Invocant unused
2172 39 my @rslt;
2173 39 foreach my $pass ( @passes ) {
2174 38 @{ $pass->{events} } = grep {
2175 _pass_select_event_code( $opt, $_->{event} )
2176 38 ▶ } @{ $pass->{events} }
Branch: 1 branch
BranchTrueFalseTotal
@{$$pass{"events"};} = grep({_pass_select_event_code($opt, $_->{"event"});} @{$$pass{"events"};}) and push @rslt, $pass 38 0 38
2177 and push @rslt, $pass;
2178 }
2179 return @rslt
2180 39 }
2181  
2182 # Determine whether an event is to be reported for the pass. The
2183 # arguments are the $opt hash reference and the event code or name.
2184 # Anything that is not a dualvar and not an integer is accepted, on
2185 # the presumption that it is an ad-hoc event provided by some
2186 # subclass. The null event is always accepted on the presumption
2187 # that if the user did not want it he or she would not have asked
2188 # for it. Anything that is left is accepted or rejected based on the
2189 # option hash and the @selector array (defined above).
2190 136 ▶ sub _pass_select_event_code {
Subroutine _pass_select_event_code: called CC=5 SCAR=18.1
2191 136 my ( $opt, $event ) = @_;
2192 136 ▶ isdual( $event )
Branch: 1 branch
BranchTrueFalseTotal
&isdual($event) or not $event =~ / \D /msx or return 1 136 0 136
Condition33%1/3
&isdual($event) or not $event =~ / \D /msx
l!l&&r!l&&!r
13600
MC/DC0%0/2
&isdual($event) or not $event =~ / \D /msx
&isdual($event) not $event =~ / \D /msx
Truth table33%1/3
A or not(B)
A= &isdual($event)B= not $event =~ / \D /msx
ABresult
1X1
011
000
2193 or $event !~ m/ \D /smx
2194 or return 1;
2195 136 ▶ $event == PASS_EVENT_NONE
Branch: 1 branch
BranchTrueFalseTotal
$event == "" and return 1 0 136 136
2196 and return 1;
2197 136 ▶ return defined $selector[ $event ] && $opt->{ $selector[ $event ] };
Condition66%2/3
defined $selector[$event] && $$opt{$selector[$event]}
!ll&&!rl&&r
02134
MC/DC50%1/2
defined $selector[$event] && $$opt{$selector[$event]}
defined $selector[$event] $$opt{$selector[$event]}
Truth table66%2/3
A && B
A= defined $selector[$event]B= $$opt{$selector[$event]}
ABresult
0X0
100
111
2198 }
2199 }
2200  
2201 20 ▶sub perl : Tokenize( -noexpand_tilde ) : Verb( eval! setup! ) {
Subroutine perl: called CC=8 SCAR=22.3
Pod documented
2202 2 my ( $self, $opt, $file, @args ) = __arguments( @_ );
2203 2 ▶ defined $file
Branch: 1 branch
BranchTrueFalseTotal
defined $file or $self->wail("At least one argument is required") 2 0 2
2204 or $self->wail( 'At least one argument is required' );
2205 $opt->{setup}
2206 0 ▶ and push @{ $self->{_perl} ||= [] }, [ $opt, $file, @args ];
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"setup"} and push @{$self->{"_perl"} ||= [];}, [$opt, $file, @args] 0 2 2
Condition0%0/2
$self->{"_perl"} ||= []
l!l
00
MC/DC0%0/1
$self->{"_perl"} ||= []
$self->{"_perl"}
Truth table0%0/2
A
A= $self->{"_perl"}
Aresult
11
00
2207 0 local @ARGV = ( $self, map { $self->expand_tilde( $_ ) } @args );
2208 $opt->{eval}
2209 2 ▶ or local $0 = $self->expand_tilde( $file );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"eval"} or local $0 = $self->expand_tilde($file) 1 1 2
2210  
2211 my $data = $opt->{eval} ?
2212 2 ▶ $file :
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'eval'} ? : 1 1 2
2213 $self->_file_reader( $file, { glob => 1 } );
2214 2 my $rslt;
2215 {
2216 # "random" package to prevent whoopsies in our own name space
2217 2 package qq_eval_namespace; ## no critic (Modules::ProhibitMultiplePackages)
2218 2 $rslt = eval $data; ## no critic (BuiltinFunctions::ProhibitStringyEval)
2219 2 ▶ $@
Branch: 1 branch
BranchTrueFalseTotal
$@ and $self->wail("Failed to eval '${file}': $@") 1 1 2
2220 and $self->wail( "Failed to eval '$file': $@" );
2221 }
2222 1 ▶ instance( $rslt, 'Astro::App::Satpass2' )
Branch: 1 branch
BranchTrueFalseTotal
instance($rslt, "Astro::App::Satpass2") or return $rslt 0 1 1
2223 or return $rslt;
2224 0 return;
2225 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2226  
2227 1 ▶sub phase : Verb( choose=s@ ) {
Subroutine phase: called CC=2 SCAR=7.0
Pod documented
2228 1 my ( $self, $opt, @args ) = __arguments( @_ );
2229  
2230 1 my $time = $self->__parse_time (shift @args, time );
2231  
2232 my @sky = $self->__choose( $opt->{choose}, $self->{sky} )
2233 1 ▶ or $self->wail( 'No bodies selected' );
Branch: 1 branch
BranchTrueFalseTotal
my(@sky) = $self->__choose($opt->{"choose"}, $self->{"sky"}) or $self->wail("No bodies selected") 1 0 1
2234 return $self->__format_data(
2235 phase => [
2236 1 map { { body => $_->universal( $time ), time => $time } }
2237 1 grep { $_->can( 'phase' ) }
2238 @sky
2239 ], $opt );
2240 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2241  
2242 4 ▶sub position : Verb( choose=s@ questionable|spare! quiet! ) {
Subroutine position: called CC=8 SCAR=21.1
Pod documented
2243 4 my ( $self, $opt, $time ) = __arguments( @_ );
2244  
2245 4 ▶ if ( defined $time ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) { } 4 0 4
2246 4 $time = $self->__parse_time($time);
2247 } else {
2248 0 $time = time;
2249 }
2250  
2251 # Define the observing station.
2252  
2253 4 my $sta = $self->station();
2254 4 $sta->universal( $time );
2255  
2256 my @list = $self->__choose( { bodies => 1, sky => 1 },
2257 4 $opt->{choose} );
2258  
2259 4 my @good;
2260 4 my $horizon = deg2rad ($self->{horizon});
2261 4 foreach my $body (@list) {
2262 13 ▶ if ( $body->represents( 'Astro::Coord::ECI::TLE' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body->represents("Astro::Coord::ECI::TLE")) 4 9 13
2263 $body->set (
2264 backdate => $self->{backdate},
2265 debug => $self->{debug},
2266 edge_of_earths_shadow => $self->{edge_of_earths_shadow},
2267 geometric => $self->{geometric},
2268 horizon => $horizon,
2269 station => $sta,
2270 twilight => $self->{_twilight},
2271 4 );
2272 $body->get('inertial')
2273 4 ▶ and $body->set( model => $self->{model} );
Branch: 1 branch
BranchTrueFalseTotal
$body->get("inertial") and $body->set("model", $self->{"model"}) 4 0 4
2274 }
2275 eval {
2276 13 $body->universal ($time);
2277 10 push @good, $body;
2278 10 1;
2279 13 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $body->universal($time); push @good, $body; 1 } } or do { $@ =~ / \Q$interrupted\E /mosx and $self->wail($@); $opt->{"quiet"} or $self->whinge($@) } 10 3 13
2280 3 ▶ $@ =~ m/ \Q$interrupted\E /smxo and $self->wail($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ =~ / \Q$interrupted\E /mosx and $self->wail($@) 0 3 3
2281 3 ▶ $opt->{quiet} or $self->whinge($@);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"quiet"} or $self->whinge($@) 0 3 3
2282 };
2283 }
2284  
2285 return $self->__format_data(
2286 position => {
2287 bodies => \@good,
2288 questionable => $opt->{questionable},
2289 station => $self->station()->universal(
2290 $time ),
2291 time => $time,
2292 twilight => $self->{_twilight},
2293 4 }, $opt );
2294 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2295  
2296 1 ▶sub pwd : Verb() {
Subroutine pwd: called CC=1 SCAR=0.0
Pod documented
2297 1 return Cwd::cwd() . "\n";
2298 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2299  
2300 {
2301 20 my @quarter_name = map { "q$_" } 0 .. 3;
2302  
2303 1 ▶ sub quarters : Verb( choose=s@ dump! q0|new|spring! q1|first|summer! q2|full|fall q3|last|winter ) {
Subroutine quarters: called CC=8 SCAR=21.0
Pod documented
2304 1 my ( $self, $opt, @args ) = __arguments( @_ );
2305  
2306 1 my $start = $self->__parse_time (
2307 $args[0], $self->_get_day_midnight() );
2308 1 ▶ my $end = $self->__parse_time ($args[1] || '+30');
Condition50%1/2
$args[1] || '+30'
l!l
01
MC/DC0%0/1
$args[1] || '+30'
$args[1]
Truth table50%1/2
A
A= $args[1]
Aresult
11
00
2309  
2310 1 $self->_apply_boolean_default( $opt, 0, map { "q$_" } 0 .. 3 );
2311  
2312 my @sky = $self->__choose( $opt->{choose}, $self->{sky} )
2313 1 ▶ or $self->wail( 'No bodies selected' );
Branch: 1 branch
BranchTrueFalseTotal
my(@sky) = $self->__choose($opt->{"choose"}, $self->{"sky"}) or $self->wail("No bodies selected") 1 0 1
2314  
2315 1 my @almanac;
2316  
2317 # Iterate over any background objects, accumulating all
2318 # quarter-phases of each until we get one after the end time. We
2319 # silently ignore bodies that do not support the next_quarter()
2320 # method.
2321  
2322 1 foreach my $body ( @sky ) {
2323 2 ▶ next unless $body->can ('next_quarter_hash');
Branch: 1 branch
BranchTrueFalseTotal
unless $body->can("next_quarter_hash") 0 2 2
2324 2 $body->universal ($start);
2325  
2326 2 while (1) {
2327 7 my $hash = $body->next_quarter_hash();
2328 7 ▶ $hash->{time} > $end and last;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{"time"} > $end and last 2 5 7
2329 5 ▶ $opt->{$quarter_name[$hash->{almanac}{detail}]}
Branch: 1 branch
BranchTrueFalseTotal
$$opt{$quarter_name[$hash->{"almanac"}{"detail"}]} or next 5 0 5
2330 or next;
2331 5 push @almanac, $hash;
2332 }
2333 }
2334  
2335 # Localize the event descriptions if appropriate.
2336  
2337 1 foreach my $event ( @almanac ) {
2338 $event->{almanac}{description} = __localize(
2339 text => [ almanac => $event->{body}->get( 'name' ),
2340 $event->{almanac}{event}, $event->{almanac}{detail}
2341 ],
2342 default => $event->{almanac}{description},
2343 argument => $event->{body},
2344 5 );
2345 }
2346  
2347 # Record number of events found
2348  
2349 1 $self->{events} += @almanac;
2350  
2351 # Sort and display the quarter-phase information.
2352  
2353 return $self->__format_data(
2354 almanac => [
2355 1 sort { $a->{time} <=> $b->{time} }
2356 @almanac
2357 ], $opt );
2358  
2359 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
2360 }
2361  
2362 {
2363 20 my $go;
2364  
2365 0 ▶ sub run {
Subroutine run: not called CC=15 SCAR=54.8
Pod documented
2366 0 my ( $self, @args ) = @_;
2367  
2368 # We can be called statically. If we are, instantiate.
2369 0 ▶ ref $self or $self = $self->new(warning => 1);
Branch: 1 branch
BranchTrueFalseTotal
ref $self or $self = $self->new("warning", 1) 0 0 0
2370  
2371 # Put all the I/O into UTF-8 mode.
2372 0 binmode STDIN, ':encoding(UTF-8)';
2373 0 binmode STDOUT, DEFAULT_STDOUT_LAYERS;
2374 0 binmode STDERR, ':encoding(UTF-8)';
2375  
2376 # If the undocumented first option is a code reference, use it to
2377 # get input.
2378 0 my $in;
2379 0 ▶ CODE_REF eq ref $args[0]
Branch: 1 branch
BranchTrueFalseTotal
"CODE" eq ref $args[0] and $in = shift @args 0 0 0
2380 and $in = shift @args;
2381  
2382 # Parse the command options. -level1 is undocumented.
2383 0 my %opt;
2384 0 ▶ $go ||= Getopt::Long::Parser->new();
Condition0%0/3
$go ||= "Getopt::Long::Parser"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$go ||= "Getopt::Long::Parser"->new
$go "Getopt::Long::Parser"->new
Truth table0%0/3
A ||= B
A= $goB= "Getopt::Long::Parser"->new
ABresult
1X1
011
000
2385 0 ▶ $go->getoptionsfromarray(
Branch: 1 branch
BranchTrueFalseTotal
$go->getoptionsfromarray(\@args, \%opt, ("echo!", "filter!", "gmt!", "help", "initialization_file|initfile=s", "level1!", "version")) or $self->wail("See the help method for valid options") 0 0 0
2386 \@args,
2387 \%opt,
2388 qw{
2389 echo! filter! gmt! help initialization_file|initfile=s
2390 level1! version
2391 },
2392 )
2393 or $self->wail( 'See the help method for valid options' );
2394  
2395 # If -version, do it and return.
2396 0 ▶ if ( $opt{version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"version"}) 0 0 0
2397 0 print $self->version();
2398 0 return;
2399 }
2400  
2401 # If -help, do it and return.
2402 0 ▶ if ( $opt{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"help"}) 0 0 0
2403 0 $self->help();
2404 0 return;
2405 }
2406  
2407 # Get an input routine if we do not already have one.
2408 0 ▶ $in ||= $self->_get_readline();
Condition0%0/3
$in ||= $self->_get_readline
l!l&&r!l&&!r
000
MC/DC0%0/2
$in ||= $self->_get_readline
$in $self->_get_readline
Truth table0%0/3
A ||= B
A= $inB= $self->_get_readline
ABresult
1X1
011
000
2409  
2410 # Some options get processed before we initialize.
2411 0 foreach my $name ( qw{ echo filter } ) {
2412 exists $opt{$name}
2413 0 ▶ and $self->set( $name => delete( $opt{$name} ) );
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{$name} and $self->set($name, delete $opt{$name}) 0 0 0
2414 }
2415  
2416 # Display the front matter if desired.
2417 0 ▶ (!$self->get('filter') && $self->_get_interactive())
Branch: 1 branch
BranchTrueFalseTotal
not $self->get("filter") and $self->_get_interactive and print $self->version 0 0 0
Condition0%0/3
not $self->get("filter") and $self->_get_interactive
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->get("filter") and $self->_get_interactive
not $self->get("filter") $self->_get_interactive
Truth table0%0/3
not(A) and B
A= not $self->get("filter")B= $self->_get_interactive
ABresult
0X0
100
111
2418 and print $self->version();
2419  
2420 # Execute the initialization file.
2421 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_execute_output($self->init({"level1", delete $opt{"level1"}}, delete $opt{"initialization_file"}), $self->get("stdout")); 1 } } or warn $@ 0 0 0
2422 $self->_execute_output( $self->init(
2423 { level1 => delete $opt{level1} },
2424 delete $opt{initialization_file},
2425 0 ), $self->get( 'stdout' ) );
2426 0 1;
2427 } or warn $@; # Not whinge, since presumably we already did.
2428  
2429 # The remaining options set the corresponding attributes.
2430 0 ▶ %opt and $self->set(%opt);
Branch: 1 branch
BranchTrueFalseTotal
%opt and $self->set(%opt) 0 0 0
2431  
2432 # Execution loop. What exit() really does is a last on this.
2433 SATPASS2_EXECUTE:
2434 {
2435 0 $self->_execute( @args );
2436 0 ▶ while ( defined ( my $buffer = $in->( $self->get( 'prompt' ) ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $buffer = &$in($self->get("prompt")))) 0 0 0
2437 0 $self->_execute( $in, $buffer );
2438 }
2439 }
2440 0 $self->_execute( q{echo ''} ); # The lazy way to be sure we
2441 # have a newline before exit.
2442 0 return;
2443 }
2444 }
2445  
2446 20 ▶sub save : Verb( changes! overwrite! ) {
Subroutine save: not called CC=17 SCAR=56.8
Pod documented
2447 0 my ( $self, $opt, $fn ) = __arguments( @_ );
2448  
2449 0 ▶ defined $fn or $fn = $self->initfile( { 'create-directory' => 1 } );
Branch: 1 branch
BranchTrueFalseTotal
defined $fn or $fn = $self->initfile({"create-directory", 1}) 0 0 0
2450 0 chomp $fn; # because initfile() adds a newline for printing
2451 0 ▶ if ($fn ne '-' && -e $fn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn ne "-" and -e $fn) 0 0 0
Condition0%0/3
$fn ne "-" and -e $fn
!ll&&!rl&&r
000
MC/DC0%0/2
$fn ne "-" and -e $fn
$fn ne "-" -e $fn
Truth table0%0/3
A and B
A= $fn ne "-"B= -e $fn
ABresult
0X0
100
111
2452 0 ▶ -f $fn or $self->wail(
Branch: 1 branch
BranchTrueFalseTotal
-f $fn or $self->wail("Can not overwrite ${fn}: not an ordinary file") 0 0 0
2453 "Can not overwrite $fn: not an ordinary file");
2454 0 ▶ $opt->{overwrite} or do {
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"overwrite"} or do { my $rslt = $self->_get_readline->("File $fn exists. Overwrite [y/N]? "); "y" eq lc substr($rslt, 0, 1) or return } 0 0 0
2455 0 my $rslt = $self->_get_readline()->(
2456 "File $fn exists. Overwrite [y/N]? ");
2457 0 ▶ 'y' eq lc substr($rslt, 0, 1)
Branch: 1 branch
BranchTrueFalseTotal
"y" eq lc substr($rslt, 0, 1) or return 0 0 0
2458 or return;
2459 };
2460 }
2461 0 my @show_opt;
2462 0 my $title = 'settings';
2463 0 ▶ if ($opt->{changes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"changes"}) 0 0 0
2464 0 push @show_opt, '-changes';
2465 0 $title = 'setting changes';
2466 }
2467  
2468 0 my $output = <<"EOD" .
2469  
2470 # Astro::App::Satpass2 $title
2471  
2472 EOD
2473 $self->show( @show_opt, qw{ -nodeprecated -noreadonly } ) .
2474 <<"EOD" . $self->macro('list');
2475  
2476 # Astro::App::Satpass2 macros
2477  
2478 EOD
2479  
2480 0 ▶ if ( $self->{_perl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_perl"}) 0 0 0
2481 0 $output .= <<'EOD';
2482  
2483 # Astro::App::Satpass2 setup
2484  
2485 EOD
2486 0 foreach my $item ( @{ $self->{_perl} } ) {
2487 0 my ( $opt, @arg ) = @{ $item };
2488 0 my @cmd = ( 'perl' );
2489 0 push @cmd, map { "-$_" } grep { $opt->{$_} } sort keys %{ $opt };
2490 0 $output .= join ' ', quoter( @cmd, @arg );
2491 0 $output .= "\n";
2492 }
2493 }
2494  
2495 0 foreach my $attribute ( qw{ formatter spacetrack time_parser } ) {
2496 0 ▶ my $obj = $self->get( $attribute ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $self->get($attribute) or next 0 0 0
2497 0 ▶ my $class = $obj->can( 'class_name_of_record' ) ?
Branch: 1 branch
BranchTrueFalseTotal
$obj->can('class_name_of_record') ? : 0 0 0
Condition0%0/3
ref $obj or $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $obj or $obj
ref $obj $obj
Truth table0%0/3
A or B
A= ref $objB= $obj
ABresult
1X1
011
000
2498 $obj->class_name_of_record() :
2499 ref $obj || $obj;
2500 0 ▶ $output .= <<"EOD" .
Condition0%0/2
$self->$attribute($opt, 'config') || "# none\n"
l!l
00
MC/DC0%0/1
$self->$attribute($opt, 'config') || "# none\n"
$self->$attribute($opt, 'config')
Truth table0%0/2
A
A= $self->$attribute($opt, 'config')
Aresult
11
00
2501  
2502 # $class $title
2503  
2504 EOD
2505 ( $self->$attribute( $opt, 'config' ) || "# none\n" );
2506 }
2507  
2508 0 $output .= $self->_save_sky( $opt );
2509  
2510 0 ▶ if ($fn ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn ne "-") 0 0 0
2511 0 ▶ my $fh = IO::File->new( $fn, '>:encoding(utf-8)')
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($fn, ">:encoding(utf-8)") or $self->wail("Unable to open ${fn}: $!") 0 0 0
2512 or $self->wail("Unable to open $fn: $!");
2513 0 print { $fh } $output;
2514 0 $output = "$fn\n";
2515 }
2516 0 return $output;
2517 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2518  
2519 # Formats the commands to reconstitute the sky. This is only called from
2520 # save(), but it is a subroutine for organizational reasons.
2521 0 ▶sub _save_sky {
Subroutine _save_sky: not called CC=12 SCAR=50.5
2522 0 my ( $self, $opt ) = @_;
2523  
2524 0 my $output = <<'EOD';
2525  
2526 # Astro::App::Satpass2 sky
2527  
2528 EOD
2529  
2530 0 foreach my $body ( sort keys %{ $self->{sky_class} } ) {
2531 $opt->{changes}
2532 and $sky_class{$body}
2533 0 ▶ and $sky_class{$body} eq $self->{sky_class}{$body}
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"changes"} and $sky_class{$body} and $sky_class{$body} eq $self->{"sky_class"}{$body} and next 0 0 0
Condition0%0/6
$opt->{"changes"} and $sky_class{$body} and $sky_class{$body} eq $self->{"sky_class"}{$body}
!ll&&!rl&&r
000
$opt->{"changes"} and $sky_class{$body}
!ll&&!rl&&r
000
MC/DC0%0/3
$opt->{"changes"} and $sky_class{$body} and $sky_class{$body} eq $self->{"sky_class"}{$body}
$opt->{"changes"} $sky_class{$body} $sky_class{$body} eq $self->{"sky_class"}{$body}
Truth table0%0/4
A and B and C
A= $opt->{"changes"}B= $sky_class{$body}C= $sky_class{$body} eq $self->{"sky_class"}{$body}
ABCresult
0XX0
10X0
1100
1111
2534 and next;
2535 0 $output .= $self->_sky_class_components( $body ) . "\n";
2536 }
2537 0 foreach my $body ( sort keys ( %sky_class ) ) {
2538 0 ▶ $self->{sky_class}{$body}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"sky_class"}{$body} or $output .= $self->_sky_class_components($body) . "\n" 0 0 0
2539 or $output .= $self->_sky_class_components( $body ) . "\n";
2540 }
2541  
2542 0 my %exclude;
2543 0 ▶ if ( $opt->{changes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'changes'}) { } 0 0 0
2544 0 %exclude = map { $_ => 1 }
2545 SUN_CLASS_DEFAULT, 'Astro::Coord::ECI::Moon';
2546 0 foreach my $name ( qw{ sun moon } ) {
2547 0 ▶ defined $self->_find_in_sky( $name )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_find_in_sky($name) or $output .= "sky drop $name\n" 0 0 0
2548 or $output .= "sky drop $name\n";
2549 }
2550 } else {
2551 0 $output .= "sky clear\n";
2552 }
2553 0 foreach my $body ( @{ $self->{sky} } ) {
2554 0 ▶ $exclude{ ref $body }
Branch: 1 branch
BranchTrueFalseTotal
$exclude{ref $body} and next 0 0 0
2555 and next;
2556 0 $output .= _sky_list_body( $body );
2557 }
2558  
2559 0 return $output;
2560 }
2561  
2562 72 ▶sub set : Verb() {
Subroutine set: called CC=7 SCAR=19.7
2563 72 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
2564  
2565 72 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 351 71 422
2566 351 my ( $name, $value ) = splice @args, 0, 2;
2567 351 $self->_attribute_exists( $name );
2568 351 ▶ if ( _is_interactive() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_interactive()) 28 323 351
2569 28 ▶ $nointeractive{$name}
Branch: 1 branch
BranchTrueFalseTotal
$nointeractive{$name} and $self->wail("Attribute '${name}' may not be set interactively") 1 27 28
2570 and $self->wail(
2571 "Attribute '$name' may not be set interactively");
2572 27 ▶ defined $value and $value eq 'undef'
Branch: 1 branch
BranchTrueFalseTotal
defined $value and $value eq "undef" and $value = undef 0 27 27
Condition66%2/3
defined $value and $value eq "undef"
!ll&&!rl&&r
2250
MC/DC0%0/2
defined $value and $value eq "undef"
defined $value $value eq "undef"
Truth table66%2/3
A and B
A= defined $valueB= $value eq "undef"
ABresult
0X0
100
111
2573 and $value = undef;
2574 }
2575 350 ▶ if ( $mutator{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mutator{$name}) { } 350 0 350
2576 350 $self->_deprecation_notice( attribute => $name );
2577 350 $mutator{$name}->($self, $name, $value);
2578 } else {
2579 0 $self->wail("Read-only attribute '$name'");
2580 }
2581 }
2582 71 return;
2583 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2584  
2585 7 ▶sub _set_almanac_horizon {
Subroutine _set_almanac_horizon: called CC=2 SCAR=7.0
2586 7 my ( $self, $name, $value ) = @_;
2587 7 my $parsed = $self->__parse_angle( { accept => 1 }, $value );
2588 7 ▶ my $internal = looks_like_number( $parsed ) ? deg2rad( $parsed ) :
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($parsed) ? : 7 0 7
2589 $parsed;
2590 7 my $eci = Astro::Coord::ECI->new();
2591 7 $eci->set( $name => $internal ); # To validate.
2592 7 $self->{"_$name"} = $internal;
2593 7 return( $self->{$name} = $parsed );
2594 }
2595  
2596 {
2597 12 ▶ my $plus_or_minus_90 = sub { $_[0] >= -90 && $_[0] <= 90 };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= -90 and $_[0] <= 90 12 0 12
2598 my %validate = (
2599 horizon => $plus_or_minus_90,
2600 latitude => $plus_or_minus_90,
2601 3 ▶ longitude => sub {
Subroutine __ANON__: called CC=4 SCAR=14.3
2602 3 ▶ $_[0] > 360
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > 360 and return 0 0 3 3
2603 and return 0;
2604 3 ▶ $_[0] > 180
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > 180 and $_[0] -= 360 1 2 3
2605 and $_[0] -= 360;
2606 3 ▶ $_[0] >= -180 && $_[0] <= 180;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= -180 and $_[0] <= 180 3 0 3
2607 },
2608 20 );
2609 31 ▶ sub _set_angle {
Subroutine _set_angle: called CC=5 SCAR=17.0
2610 31 my ( $self, $name, $value ) = @_;
2611 31 my $angle = $self->__parse_angle( $value );
2612 31 ▶ if ( my $code = $validate{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $validate{$name}) 15 16 31
2613 15 ▶ defined $angle or $self->weep(
Branch: 2 branches
BranchTrueFalseTotal
defined $angle or $self->weep("$name angle is undef for value ", defined $value ? $value : "undef") 15 0 15
defined $value ? : 0 0 0
2614 "$name angle is undef for value ", defined $value ? $value : 'undef' );
2615 15 ▶ $code->( $angle )
Branch: 1 branch
BranchTrueFalseTotal
&$code($angle) or $self->wail("Value $value is invalid for $name") 15 0 15
2616 or $self->wail( "Value $value is invalid for $name" );
2617 }
2618 31 $self->{"_$name"} = deg2rad( $angle );
2619 31 return ( $self->{$name} = $angle );
2620 }
2621 }
2622  
2623 20 ▶sub _set_angle_or_undef {
Subroutine _set_angle_or_undef: called CC=3 SCAR=11.0
2624 21 my ( $self, $name, $value ) = @_;
2625 21 ▶ defined $value and 'undef' ne $value and goto &_set_angle;
Branch: 1 branch
BranchTrueFalseTotal
defined $value and "undef" ne $value and goto \&Astro::App::Satpass2::_set_angle 6 15 21
Condition66%2/3
defined $value and "undef" ne $value
!ll&&!rl&&r
1506
MC/DC50%1/2
defined $value and "undef" ne $value
defined $value "undef" ne $value
Truth table66%2/3
A and B
A= defined $valueB= "undef" ne $value
ABresult
0X0
100
111
2626 15 return ( $self->{$name} = undef );
2627 }
2628  
2629 11 ▶sub _set_code_ref {
Subroutine _set_code_ref: called CC=2 SCAR=7.2
2630 11 ▶ CODE_REF eq ref $_[2]
Branch: 1 branch
BranchTrueFalseTotal
"CODE" eq ref $_[2] or $_[0]->wail("Attribute $_[1] must be a code reference") 11 0 11
2631 or $_[0]->wail( "Attribute $_[1] must be a code reference" );
2632 11 return( $_[0]{$_[1]} = $_[2] );
2633 }
2634  
2635 # Set an attribute whose value is an Astro::App::Satpass2::Copier object
2636 # %arg is a hash of argument name/value pairs:
2637 # {name} is the required name of the attribute to set;
2638 # {value} is the required value of the attribute to set;
2639 # {class} is the optional class that the object must be;
2640 # {default} is the optional default value if the required value is
2641 # undef or '';
2642 # {undefined} is an optional value which, if true, permits the
2643 # attribute to be set to undef;
2644 # {nocopy} is an optional value which, if true, causes the old
2645 # object's attributes not to be copied to the new object;
2646 # {message} is an optional message to emit if the object can not be
2647 # instantiated;
2648 # {prefix} is an optional reference to an array of name prefixes to
2649 # try if the named module does not load.
2650  
2651 14 ▶sub _set_copyable {
Subroutine _set_copyable: called CC=21 SCAR=42.7
2652 14 my ( $self, %arg ) = @_;
2653 14 my $old = $self->{$arg{name}};
2654 14 my $obj;
2655 14 ▶ if ( ref $arg{value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg{'value'}) { } 0 14 14
2656 blessed( $arg{value} )
2657 0 ▶ or $self->wail( "$arg{name} may not be unblessed reference" );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($arg{"value"}) or $self->wail(qq[$arg{"name"} may not be unblessed reference]) 0 0 0
2658 0 $obj = $arg{value};
2659 $obj->can( 'warner' )
2660 0 ▶ and $obj->warner( $self->{_warner} );
Branch: 1 branch
BranchTrueFalseTotal
$obj->can("warner") and $obj->warner($self->{"_warner"}) 0 0 0
2661 } else {
2662 14 ▶ if ( defined $arg{default} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg{"default"}) 14 0 14
2663 defined $arg{value}
2664 and '' ne $arg{value}
2665 14 ▶ or $arg{value} = $arg{default};
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{"value"} and "" ne $arg{"value"} or $arg{"value"} = $arg{"default"} 14 0 14
Condition33%1/3
defined $arg{"value"} and "" ne $arg{"value"}
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $arg{"value"} and "" ne $arg{"value"}
defined $arg{"value"} "" ne $arg{"value"}
Truth table33%1/3
A and B
A= defined $arg{"value"}B= "" ne $arg{"value"}
ABresult
0X0
100
111
2666 }
2667 14 ▶ if ( ! defined $arg{value} || $arg{value} eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $arg{"value"} or $arg{"value"} eq "") 0 14 14
Condition33%1/3
not defined $arg{"value"} or $arg{"value"} eq ""
l!l&&r!l&&!r
0014
MC/DC0%0/2
not defined $arg{"value"} or $arg{"value"} eq ""
not defined $arg{"value"} $arg{"value"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $arg{"value"}B= $arg{"value"} eq ""
ABresult
1X1
011
000
2668 $arg{undefined}
2669 0 ▶ or $self->wail(
Branch: 1 branch
BranchTrueFalseTotal
$arg{"undefined"} or $self->wail(qq[$arg{"name"} must be defined and not empty]) 0 0 0
2670 "$arg{name} must be defined and not empty",
2671 );
2672 0 return ( $self->{$arg{name}} = $arg{value} = undef );
2673 }
2674 14 my ( $pkg, @args ) = $self->__parse_class_and_args( $arg{value} );
2675 my $cls = $self->load_package(
2676 14 ▶ { fatal => 'wail' }, $pkg, @{ $arg{prefix} || [] } );
Condition50%1/2
$arg{'prefix'} || []
l!l
140
MC/DC0%0/1
$arg{'prefix'} || []
$arg{'prefix'}
Truth table50%1/2
A
A= $arg{'prefix'}
Aresult
11
00
2677 14 ▶ not $cls->can( 'init' )
Branch: 1 branch
BranchTrueFalseTotal
not $cls->can("init") and _is_case_tolerant() and $self->wail("$cls is missing methods. This can happen on a ", "case-tolerant system if you specify the class ", "name in the wrong case.") 0 14 14
Condition33%1/3
not $cls->can("init") and _is_case_tolerant()
!ll&&!rl&&r
1400
MC/DC0%0/2
not $cls->can("init") and _is_case_tolerant()
not $cls->can("init") _is_case_tolerant()
Truth table33%1/3
not(A) and B
A= not $cls->can("init")B= _is_case_tolerant()
ABresult
0X0
100
111
2678 and _is_case_tolerant()
2679 and $self->wail(
2680 "$cls is missing methods. This can happen on a ",
2681 'case-tolerant system if you specify the class ',
2682 'name in the wrong case.' );
2683 14 ▶ $cls->can( 'parent' )
Branch: 1 branch
BranchTrueFalseTotal
$cls->can("parent") and push @args, "parent", $self 7 7 14
2684 and push @args, parent => $self;
2685 $obj = $cls->new(
2686 warner => $self->{_warner},
2687 @args,
2688 )
2689 or $self->wail( $arg{message} ||
2690 14 ▶ "Can not instantiate object from '$arg{value}'" );
Branch: 1 branch
BranchTrueFalseTotal
$obj = $cls->new("warner", $self->{"_warner"}, @args) or $self->wail($arg{"message"} || qq[Can not instantiate object from '$arg{"value"}']) 14 0 14
Condition0%0/2
$arg{'message'} || "Can not instantiate object from '$arg{'value'}'"
l!l
00
MC/DC0%0/1
$arg{'message'} || "Can not instantiate object from '$arg{'value'}'"
$arg{'message'}
Truth table0%0/2
A
A= $arg{'message'}
Aresult
11
00
2691 }
2692 defined $arg{class}
2693 and not $obj->isa( $arg{class} )
2694 14 ▶ and $self->wail( "$arg{name} must be of class $arg{class}" );
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{"class"} and not $obj->isa($arg{"class"}) and $self->wail(qq[$arg{"name"} must be of class $arg{"class"}]) 0 14 14
Condition66%2/3
defined $arg{"class"} and not $obj->isa($arg{"class"})
!ll&&!rl&&r
770
MC/DC0%0/2
defined $arg{"class"} and not $obj->isa($arg{"class"})
defined $arg{"class"} not $obj->isa($arg{"class"})
Truth table66%2/3
A and not(B)
A= defined $arg{"class"}B= not $obj->isa($arg{"class"})
ABresult
0X0
100
111
2695 blessed( $old )
2696 and not $arg{nocopy}
2697 14 ▶ and $old->can( 'copy' )
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($old) and not $arg{"nocopy"} and $old->can("copy") and $old->copy($obj) 0 14 14
Condition33%2/6
builtin::blessed($old) and not $arg{"nocopy"} and $old->can("copy")
!ll&&!rl&&r
1400
builtin::blessed($old) and not $arg{"nocopy"}
!ll&&!rl&&r
1400
MC/DC0%0/3
builtin::blessed($old) and not $arg{"nocopy"} and $old->can("copy")
builtin::blessed($old) not $arg{"nocopy"} $old->can("copy")
Truth table25%1/4
A and not(B) and C
A= builtin::blessed($old)B= not $arg{"nocopy"}C= $old->can("copy")
ABCresult
0XX0
10X0
1100
1111
2698 and $old->copy( $obj );
2699 14 $self->{$arg{name}} = $obj;
2700 14 return $arg{value};
2701 }
2702  
2703 9 ▶sub _set_distance_meters {
Subroutine _set_distance_meters: called CC=2 SCAR=6.9
2704 9 ▶ return ( $_[0]{$_[1]} = defined $_[2] ?
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 2 7 9
2705 ( $_[0]->__parse_distance( $_[2], '0m' ) * 1000 ) : $_[2] );
2706 }
2707  
2708 7 ▶sub _set_ellipsoid {
Subroutine _set_ellipsoid: called CC=1 SCAR=0.0
2709 7 my ($self, $name, $val) = @_;
2710 7 Astro::Coord::ECI->set (ellipsoid => $val);
2711 7 return ($self->{$name} = $val);
2712 }
2713  
2714 7 ▶sub _set_formatter {
Subroutine _set_formatter: called CC=1 SCAR=0.0
2715 7 my ( $self, $name, $val ) = @_;
2716 7 return $self->_set_copyable(
2717 name => $name,
2718 value => $val,
2719 message => 'Unknown formatter',
2720 default => 'Astro::App::Satpass2::Format::Template',
2721 prefix => [ 'Astro::App::Satpass2::Format' ]
2722 );
2723 }
2724  
2725 24 ▶sub _set_formatter_attribute {
Subroutine _set_formatter_attribute: called CC=1 SCAR=0.0
2726 24 my ( $self, $name, $val ) = @_;
2727 24 $self->get( 'formatter' )->$name( $val );
2728 24 return $val;
2729 }
2730  
2731 0 ▶sub _set_geocoder {
Subroutine _set_geocoder: not called CC=1 SCAR=6.9
2732 0 my ( $self, $name, $val ) = @_;
2733 0 return $self->_set_copyable(
2734 name => $name,
2735 value => $val,
2736 class => 'Astro::App::Satpass2::Geocode',
2737 message => 'Unknown formatter',
2738 default => $default_geocoder->(),
2739 undefined => 1,
2740 nocopy => 1,
2741 prefix => [ 'Astro::App::Satpass2::Geocode' ]
2742 );
2743 }
2744  
2745 7 ▶sub _set_illum_class {
Subroutine _set_illum_class: called CC=5 SCAR=17.0
2746 7 my ( $self, $name, $class ) = @_;
2747 7 my $want_class = 'Astro::Coord::ECI';
2748 7 ▶ ref $class and $self->wail( "$name must not be a reference" );
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $self->wail("$name must not be a reference") 0 7 7
2749 7 ▶ if ( defined $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) { } 7 0 7
2750 7 $self->load_package( { fatal => 'wail' }, $class );
2751 7 ▶ $class->isa( $want_class )
Branch: 1 branch
BranchTrueFalseTotal
$class->isa($want_class) or $self->wail("$name must be an $want_class") 7 0 7
2752 or $self->wail( "$name must be an $want_class" );
2753 } else {
2754 0 $class = $want_class;
2755 }
2756 7 $self->{$name} = $class;
2757 7 $self->{_help_module}{$name} = $class;
2758 7 foreach my $body ( @{ $self->{bodies} } ) {
2759 0 $body->set( $name => $class );
2760 }
2761 7 return;
2762 }
2763  
2764 7 ▶sub _set_model {
Subroutine _set_model: called CC=3 SCAR=11.4
2765 7 my ( $self, $name, $val ) = @_;
2766 7 ▶ Astro::Coord::ECI::TLE->is_valid_model( $val )
Branch: 1 branch
BranchTrueFalseTotal
"Astro::Coord::ECI::TLE"->is_valid_model($val) or $self->wail("'${val}' is not a valid Astro::Coord::ECI::TLE model") 7 0 7
2767 or $self->wail(
2768 "'$val' is not a valid Astro::Coord::ECI::TLE model" );
2769 7 foreach my $body ( @{ $self->{bodies} } ) {
2770 0 $body->set( model => $val );
2771 }
2772 7 return ( $self->{$name} = $val );
2773 }
2774  
2775 7 ▶sub _set_output_layers {
Subroutine _set_output_layers: called CC=4 SCAR=15.2
2776 7 my ( $self, $name, $val ) = @_;
2777  
2778 7 ▶ if ( defined $val && '' ne $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and "" ne $val) 7 0 7
Condition33%1/3
defined $val and "" ne $val
!ll&&!rl&&r
007
MC/DC0%0/2
defined $val and "" ne $val
defined $val "" ne $val
Truth table33%1/3
A and B
A= defined $valB= "" ne $val
ABresult
0X0
100
111
2779 7 ▶ open my $fh, ">$val", File::Spec->devnull()
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$val", "File::Spec"->devnull or $self->wail("Invalid $name value '${val}'") 7 0 7
2780 or $self->wail( "Invalid $name value '$val'" );
2781 7 close $fh;
2782 }
2783 7 return ( $self->{$name} = $val );
2784 }
2785  
2786 {
2787 20 my %variant_def = (
2788 visible_events => PASS_VARIANT_VISIBLE_EVENTS,
2789 fake_max => PASS_VARIANT_FAKE_MAX,
2790 start_end => PASS_VARIANT_START_END,
2791 no_illumination => PASS_VARIANT_NO_ILLUMINATION,
2792 brightest => PASS_VARIANT_BRIGHTEST,
2793 );
2794  
2795 20 my @option_names;
2796 20 foreach my $key ( keys %variant_def ) {
2797 100 ▶ if ( $key =~ m/ _ /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ / _ /msx) 80 20 100
2798 80 ( my $dashed = $key ) =~ s/ _ /-/smxg;
2799 80 $key = "$key|$dashed";
2800 }
2801 100 push @option_names, "$key!";
2802 }
2803  
2804 20 my $go;
2805  
2806 8 ▶ sub _set_pass_variant {
Subroutine _set_pass_variant: called CC=6 SCAR=18.7
2807 8 my ( $self, $name, $val ) = @_;
2808 8 ▶ if ( $val =~ m/ \A (?: 0 x? ) [0-9]* \z /smx ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ / \A (?: 0 x? ) [0-9]* \z /msx) { } 7 1 8
elsif (not $val =~ / \A [0-9]+ \z /msx) { } 1 0 1
2809 7 $val = oct $val;
2810 } elsif ( $val !~ m/ \A [0-9]+ \z /smx ) {
2811 1 my @args = split qr{ [^\w-] }smx, $val;
2812 1 foreach ( @args ) {
2813 1 s/ \A (?! - ) /-/smx;
2814 }
2815 1 ▶ $go ||= Getopt::Long::Parser->new();
Condition33%1/3
$go ||= "Getopt::Long::Parser"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$go ||= "Getopt::Long::Parser"->new
$go "Getopt::Long::Parser"->new
Truth table33%1/3
A ||= B
A= $goB= "Getopt::Long::Parser"->new
ABresult
1X1
011
000
2816 1 $val = $self->get( $name );
2817 $go->getoptionsfromarray( \@args,
2818 0 ▶ none => sub { $val = PASS_VARIANT_NONE },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2819 1 ▶ map { $_ => sub {
Subroutine __ANON__: called CC=2 SCAR=7.3
Branch: 1 branch
BranchTrueFalseTotal
$go->getoptionsfromarray(\@args, "none", sub { $val = 0; } , map({$_, sub { my($name, $value) = @_; my $mask = $variant_def{$name}; if ($value) { $val |= $mask; } else { $val &= ~$mask; } ; return; } ;} @option_names)) or $self->wail("Invalid $name value '${val}'") 1 0 1
2820 1 my ( $name, $value ) = @_;
2821 1 my $mask = $variant_def{$name};
2822 1 ▶ if ( $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 1 1
2823 0 $val |= $mask;
2824 } else {
2825 1 $val &= ~ $mask;
2826 }
2827 1 return;
2828 }
2829 5 } @option_names )
2830 or $self->wail( "Invalid $name value '$val'" );
2831 }
2832 8 return ( $self->{$name} = $val );
2833 }
2834  
2835 1 ▶ sub _show_pass_variant {
Subroutine _show_pass_variant: called CC=4 SCAR=14.1
2836 1 my ( $self, $name ) = @_;
2837 1 my $val = $self->get( $name );
2838 1 my @options;
2839 1 foreach my $key ( keys %variant_def ) {
2840 5 ▶ $val & $variant_def{$key}
Branch: 1 branch
BranchTrueFalseTotal
$val & $variant_def{$key} and push @options, "$key" 0 5 5
2841 and push @options, "$key";
2842 }
2843 @options
2844 1 ▶ or push @options, 'none';
Branch: 1 branch
BranchTrueFalseTotal
@options or push @options, "none" 0 1 1
2845 1 return ( set => $name, join ',', @options );
2846 }
2847  
2848 138 ▶ sub want_pass_variant {
Subroutine want_pass_variant: called CC=2 SCAR=7.0
Pod documented
2849 138 my ( $self, $variant ) = @_;
2850 138 ▶ $variant_def{$variant}
Branch: 1 branch
BranchTrueFalseTotal
$variant_def{$variant} or $self->wail("Invalid pass_variant name '${variant}'") 138 0 138
2851 or $self->wail( "Invalid pass_variant name '$variant'" );
2852 138 my $val = $self->get( 'pass_variant' ) & $variant_def{$variant};
2853 138 return $val;
2854 }
2855  
2856 }
2857  
2858 20 ▶sub _set_spacetrack {
Subroutine _set_spacetrack: not called CC=4 SCAR=28.2
2859 0 my ($self, $name, $val) = @_;
2860 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
2861 0 ▶ instance($val, 'Astro::SpaceTrack')
Branch: 1 branch
BranchTrueFalseTotal
instance($val, "Astro::SpaceTrack") or $self->wail("$name must be an Astro::SpaceTrack instance") 0 0 0
2862 or $self->wail("$name must be an Astro::SpaceTrack instance");
2863 0 my $version = $val->VERSION();
2864 0 $version =~ s/ _ //smxg;
2865 0 ▶ $version >= ASTRO_SPACETRACK_VERSION
Branch: 1 branch
BranchTrueFalseTotal
$version >= "0.105" or $self->wail("$name must be Astro::SpaceTrack version ", "0.105", " or greater") 0 0 0
2866 or $self->wail("$name must be Astro::SpaceTrack version ",
2867 ASTRO_SPACETRACK_VERSION, ' or greater' );
2868 }
2869 0 return ($self->{$name} = $val);
2870 }
2871  
2872 15 ▶sub _set_stdout {
Subroutine _set_stdout: called CC=2 SCAR=7.1
2873 15 my ($self, $name, $val) = @_;
2874 $self->{frame}
2875 15 ▶ and $self->{frame}[-1]{$name} = $val;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"frame"} and $self->{"frame"}[-1]{$name} = $val 15 0 15
2876 15 return ($self->{$name} = $val);
2877 }
2878  
2879 0 ▶sub _set_sun_class {
Subroutine _set_sun_class: not called CC=1 SCAR=6.9
2880 0 my ( $self, $name, $val ) = @_;
2881 0 $self->_attribute_exists( $name );
2882 0 return $self->sky( class => $name, $val );
2883 }
2884  
2885 7 ▶sub _set_time_parser {
Subroutine _set_time_parser: called CC=4 SCAR=17.9
2886 7 my ( $self, $name, $val ) = @_;
2887  
2888 7 ▶ if ( CODE_REF eq ref $val ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('CODE' eq ref $val) { } 0 7 7
elsif (defined $val and my $macro = $self->{'macro'}{$val}) { } 0 7 7
2889 0 $val = _set_time_parser_code( $val );
2890 ▶ } elsif ( defined $val and my $macro = $self->{macro}{$val} ) {
Condition33%1/3
defined $val and my $macro = $self->{"macro"}{$val}
!ll&&!rl&&r
070
MC/DC0%0/2
defined $val and my $macro = $self->{"macro"}{$val}
defined $val my $macro = $self->{"macro"}{$val}
Truth table33%1/3
A and B
A= defined $valB= my $macro = $self->{"macro"}{$val}
ABresult
0X0
100
111
2891 0 $val = _set_time_parser_code(
2892 $macro->implements( $val, required => 1 ),
2893 $val,
2894 );
2895 }
2896  
2897 7 return $self->_set_copyable(
2898 name => $name,
2899 value => $val,
2900 class => 'Astro::App::Satpass2::ParseTime',
2901 message => 'Unknown time parser',
2902 default => 'Astro::App::Satpass2::ParseTime',
2903 nocopy => 1,
2904 prefix => [ 'Astro::App::Satpass2::ParseTime' ],
2905 );
2906 }
2907  
2908 14 ▶sub _set_time_parser_attribute {
Subroutine _set_time_parser_attribute: called CC=3 SCAR=11.3
2909 14 my ( $self, $name, $val ) = @_;
2910 14 ▶ defined $val and $val eq 'undef' and $val = undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $val and $val eq "undef" and $val = undef 0 14 14
Condition66%2/3
defined $val and $val eq "undef"
!ll&&!rl&&r
770
MC/DC0%0/2
defined $val and $val eq "undef"
defined $val $val eq "undef"
Truth table66%2/3
A and B
A= defined $valB= $val eq "undef"
ABresult
0X0
100
111
2911 14 $self->{time_parser}->$name( $val );
2912 14 return $val;
2913 }
2914  
2915 0 ▶sub _set_time_parser_code {
Subroutine _set_time_parser_code: not called CC=1 SCAR=6.9
2916 0 my ( $code, $name ) = @_;
2917 0 require Astro::App::Satpass2::ParseTime::Code;
2918 0 my $obj = Astro::App::Satpass2::ParseTime::Code->new();
2919 0 return $obj->code( $code, $name );
2920 }
2921  
2922 20 _frame_pop_force_set ( 'twilight' ); # Force use of the set() method
2923 # in _frame_pop(), because we
2924 # need to set {_twilight} as
2925 # well.
2926 9 ▶sub _set_twilight {
Subroutine _set_twilight: called CC=3 SCAR=14.8
2927 9 my ($self, $name, $val) = @_;
2928 9 ▶ if (my $key = $twilight_abbr{lc $val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = $twilight_abbr{lc $val}) { } 9 0 9
2929 9 $self->{$name} = $key;
2930 9 $self->{_twilight} = $twilight_def{$key};
2931 } else {
2932 0 my $angle = $self->__parse_angle( { accept => 1 }, $val );
2933 0 ▶ looks_like_number( $angle )
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($angle) or $self->wail("Twilight must be number or known keyword") 0 0 0
2934 or $self->wail( 'Twilight must be number or known keyword' );
2935 0 $self->{$name} = $val;
2936 0 $self->{_twilight} = deg2rad ($angle);
2937 }
2938 9 return $val;
2939 }
2940  
2941 7 ▶sub _set_tz {
Subroutine _set_tz: called CC=1 SCAR=0.0
2942 7 my ( $self, $name, $val ) = @_;
2943 7 $self->_set_formatter_attribute( $name, $val );
2944 7 $self->_set_time_parser_attribute( $name, $val );
2945 7 return $val;
2946 }
2947  
2948 165 ▶sub _set_unmodified {
Subroutine _set_unmodified: called CC=1 SCAR=0.0
2949 165 return ($_[0]{$_[1]} = $_[2]);
2950 }
2951  
2952 0 ▶sub _set_warner_attribute {
Subroutine _set_warner_attribute: not called CC=3 SCAR=24.8
2953 0 my ( $self, $name, $val ) = @_;
2954 0 ▶ defined $val and $val eq 'undef' and $val = undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $val and $val eq "undef" and $val = undef 0 0 0
Condition0%0/3
defined $val and $val eq "undef"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val eq "undef"
defined $val $val eq "undef"
Truth table0%0/3
A and B
A= defined $valB= $val eq "undef"
ABresult
0X0
100
111
2955 0 $self->{_warner}->$name( $val );
2956 0 return $val;
2957 }
2958  
2959 7 ▶sub _set_webcmd {
Subroutine _set_webcmd: called CC=2 SCAR=7.6
2960 7 my ($self, $name, $val) = @_;
2961 # TODO warn if $val is true but not '1'.
2962 7 ▶ if ( my $st = $self->get( 'spacetrack' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $self->get("spacetrack")) 0 7 7
2963 # TODO once spacetrack supports '1', just pass $val.
2964 0 $st->set( webcmd => $self->_get_browser_command( $val ) );
2965 }
2966 7 return ($self->{$name} = $val);
2967 }
2968  
2969 23 ▶sub show : Verb( changes! deprecated! readonly! ) Tweak( -completion _readline_complete_subcommand ) {
Subroutine show: called CC=17 SCAR=44.3
Pod documented
2970 23 my ( $self, $opt, @args ) = __arguments( @_ );
2971  
2972 23 foreach my $name ( qw{ deprecated readonly } ) {
2973 46 ▶ exists $opt->{$name} or $opt->{$name} = 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{$name} or $opt->{$name} = 1 0 46 46
2974 }
2975 23 my $output;
2976  
2977 23 ▶ unless ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 23 23
2978 0 foreach my $name ( sort keys %accessor ) {
2979 0 ▶ $self->_attribute_exists( $name, query => 1 )
Branch: 1 branch
BranchTrueFalseTotal
$self->_attribute_exists($name, "query", 1) or next 0 0 0
2980 or next;
2981 0 ▶ $nointeractive{$name}
Branch: 1 branch
BranchTrueFalseTotal
$nointeractive{$name} and next 0 0 0
2982 and next;
2983 exists $mutator{$name}
2984 or $opt->{readonly}
2985 0 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
exists $mutator{$name} or $opt->{"readonly"} or next 0 0 0
Condition0%0/3
exists $mutator{$name} or $opt->{"readonly"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $mutator{$name} or $opt->{"readonly"}
exists $mutator{$name} $opt->{"readonly"}
Truth table0%0/3
A or B
A= exists $mutator{$name}B= $opt->{"readonly"}
ABresult
1X1
011
000
2986 0 my $depr;
2987 ( $depr = $self->_deprecation_in_progress( attribute =>
2988 $name ) )
2989 0 ▶ and ( not $opt->{deprecated} or $depr >= 3 )
Branch: 1 branch
BranchTrueFalseTotal
$depr = $self->_deprecation_in_progress("attribute", $name) and !$opt->{"deprecated"} || $depr >= 3 and next 0 0 0
Condition0%0/6
$depr = $self->_deprecation_in_progress("attribute", $name) and !$opt->{"deprecated"} || $depr >= 3
!ll&&!rl&&r
000
not $opt->{"deprecated"} or $depr >= 3
l!l&&r!l&&!r
000
MC/DC0%0/3
$depr = $self->_deprecation_in_progress("attribute", $name) and !$opt->{"deprecated"} || $depr >= 3
$depr = $self->_deprecation_in_progress("attribute", $name) not $opt->{"deprecated"} $depr >= 3
Truth table0%0/4
A and not(B) or C
A= $depr = $self->_deprecation_in_progress("attribute", $name)B= not $opt->{"deprecated"}C= $depr >= 3
ABCresult
0XX0
1000
11X1
1011
2990 and next;
2991 0 push @args, $name;
2992 }
2993 }
2994  
2995 23 foreach my $name (@args) {
2996 23 ▶ exists $shower{$name}
Branch: 1 branch
BranchTrueFalseTotal
exists $shower{$name} or $self->wail("No such attribute as '${name}'") 23 0 23
2997 or $self->wail("No such attribute as '$name'");
2998  
2999 23 my @val = $shower{$name}->( $self, $name );
3000 23 ▶ if ( $opt->{changes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"changes"}) 0 23 23
3001 20 ▶ no warnings qw{ uninitialized };
Subroutine BEGIN: called CC=1 SCAR=0.0
3002 0 ▶ $static{$name} eq $val[-1] and next;
Branch: 1 branch
BranchTrueFalseTotal
$static{$name} eq $val[-1] and next 0 0 0
3003 }
3004  
3005 23 ▶ exists $mutator{$name} or unshift @val, '#';
Branch: 1 branch
BranchTrueFalseTotal
exists $mutator{$name} or unshift @val, "#" 23 0 23
3006 23 $output .= quoter( @val ) . "\n";
3007 }
3008 23 return $output;
3009 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3010  
3011 0 ▶sub _show_copyable {
Subroutine _show_copyable: not called CC=1 SCAR=6.9
3012 0 my ( $self, $name ) = @_;
3013 0 my $obj = $self->get( $name );
3014 0 my $val = $obj->class_name_of_record();
3015 0 return ( 'set', $name, $val );
3016 }
3017  
3018 2 ▶sub _show_formatter_attribute {
Subroutine _show_formatter_attribute: called CC=1 SCAR=0.0
3019 2 my ( $self, $name ) = @_;
3020 2 my $val = $self->{formatter}->decode( $name );
3021 2 return ( qw{ formatter }, $name, $val );
3022 }
3023  
3024 # Calls to the following _show_sub method are generated dynamically
3025 # above, so there is no way Perl::Critic can find them.
3026  
3027 1 ▶sub _show_sub { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _show_sub: called CC=2 SCAR=7.0
3028 # my ( $app, $text, $line, $start, @arg ) = @_;
3029 1 my ( undef, undef, undef, undef, @arg ) = @_;
3030 1 ▶ @arg > 1
Branch: 1 branch
BranchTrueFalseTotal
@arg > 1 or return 1 0 1
3031 or return;
3032 1 my $re = qr/ \A \Q$arg[-1]\E /smx;
3033 1 return [ grep { $_ =~ $re } sort keys %accessor ];
3034 }
3035  
3036 0 ▶sub _show_sun_class {
Subroutine _show_sun_class: not called CC=1 SCAR=6.9
3037 0 my ( $self, $name ) = @_;
3038 0 $self->_attribute_exists( $name );
3039 0 return $self->_sky_class_components( $name );
3040 }
3041  
3042 0 ▶sub _show_time_parser {
Subroutine _show_time_parser: not called CC=2 SCAR=17.9
3043 0 my ( $self, $name ) = @_;
3044 0 my $obj = $self->get( $name );
3045 0 my $val = $obj->class_name_of_record();
3046 0 ▶ if ( my $back_end = $obj->back_end() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $back_end = $obj->back_end) 0 0 0
3047 0 $val = "$val,back_end=$back_end";
3048 }
3049 0 return ( set => $name, $val );
3050 }
3051  
3052 20 ▶sub _show_unmodified {
Subroutine _show_unmodified: called CC=1 SCAR=0.0
3053 20 my ($self, $name) = @_;
3054 20 my $val = $self->get( $name );
3055 20 return ( 'set', $name, $val );
3056 }
3057  
3058 # For proper motion, we need to convert arc seconds per year to degrees
3059 # per second. Perl::Critic does not like 'use constant' because they do
3060 # not interpolate, but they really do: "@{[SPY2DPS]}".
3061  
3062 20 ▶use constant SPY2DPS => 3600 * 365.24219 * SECSPERDAY;
Subroutine BEGIN: called CC=1 SCAR=0.0
3063  
3064 # Given a body in the sky, encodes it in 'sky add' format
3065 8 ▶sub _sky_list_body {
Subroutine _sky_list_body: called CC=3 SCAR=11.1
3066 8 my ( $body ) = @_;
3067 8 ▶ if ( embodies( $body, 'Astro::Coord::ECI::TLE' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (embodies($body, 'Astro::Coord::ECI::TLE')) { } 0 8 8
elsif ($body->isa('Astro::Coord::ECI::Star')) { } 1 7 8
3068 0 return sprintf "sky tle %s\n", quoter(
3069 $body->get( 'tle' ) );
3070 } elsif ( $body->isa( 'Astro::Coord::ECI::Star' ) ) {
3071 1 my ( $ra, $dec, $rng, $pmra, $pmdec, $vr ) = $body->position();
3072 1 $rng /= PARSEC;
3073 1 $pmra = rad2deg( $pmra / 24 * 360 * cos( $ra ) ) * SPY2DPS;
3074 1 $pmdec = rad2deg( $pmdec ) * SPY2DPS;
3075 1 return sprintf
3076 "sky add %s %s %7.3f %.2f %.4f %.5f %s\n",
3077 quoter( $body->get( 'name' ) ), _rad2hms( $ra ),
3078 rad2deg( $dec ), $rng, $pmra, $pmdec, $vr;
3079 } else {
3080 7 return sprintf "sky add %s\n", quoter( $body->get( 'name' ) );
3081 }
3082 }
3083  
3084 12 ▶sub sky : Verb() Tweak( -completion _readline_complete_subcommand ) {
Subroutine sky: called CC=3 SCAR=12.7
Pod documented
3085 12 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3086  
3087 12 ▶ my $verb = lc ( shift @args || 'list' );
Condition50%1/2
shift @args || 'list'
l!l
120
MC/DC0%0/1
shift @args || 'list'
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
3088  
3089 12 ▶ if ( my $code = $self->can( "_sky_sub_$verb") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->can("_sky_sub_$verb")) { } 12 0 12
3090 12 return $code->( $self, @args );
3091 } else {
3092 0 $self->wail("'sky' subcommand '$verb' not known");
3093 }
3094 0 return; # We can't get here, but Perl::Critic does not know this.
3095 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3096  
3097 # Given the name of a potential background object, return its
3098 # definition. This is an array in list context, or a quoted string in
3099 # scalar context.
3100 0 ▶sub _sky_class_components {
Subroutine _sky_class_components: not called CC=3 SCAR=24.8
3101 0 my ( $self, $name ) = @_;
3102 0 ▶ my $info = $self->{sky_class}{ fold_case( $name ) }
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->{"sky_class"}{CORE::fc $name} or $self->weep("No class defined for $name") 0 0 0
3103 or $self->weep( "No class defined for $name" );
3104 0 my ( $class, @attr ) = @{ $info };
3105 # We rely on sky( class => $name, $class, ... ) keeping the name
3106 # last.
3107 0 $name = pop @attr;
3108 0 pop @attr; # 'name';
3109 0 my @parts = ( qw{ sky class }, $name, $class, @attr );
3110 wantarray
3111 0 ▶ and return @parts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return @parts 0 0 0
3112 0 return join ' ', map { quoter( $_ ) } @parts;
3113 }
3114  
3115 # Given the name of a potential sky object, instantiate it. Named
3116 # arguments are optional; the following are supported:
3117 # fatal = Whether failure to find the name is fatal. Default is true.
3118 12 ▶sub _sky_object {
Subroutine _sky_object: called CC=4 SCAR=14.0
3119 12 my ( $self, $name, %opt ) = @_;
3120 defined $opt{fatal}
3121 12 ▶ or $opt{fatal} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{"fatal"} or $opt{"fatal"} = 1 5 7 12
3122 12 ▶ if ( my $info = $self->{sky_class}{ fold_case( $name ) } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $info = $self->{'sky_class'}{CORE::fc $name}) { } 10 2 12
elsif ($opt{'fatal'}) { } 0 2 2
3123 10 my ( $class, @attr ) = @{ $info };
3124 10 return $class->new( @attr );
3125 } elsif ( $opt{fatal} ) {
3126 0 $self->weep( "No class defined for $name" );
3127 }
3128 2 return;
3129 }
3130  
3131 # Calls to the following _sky_sub_... methods are generated dynamically
3132 # above, so there is no way Perl::Critic can find them.
3133 #
3134 5 ▶sub _sky_sub_add : Verb() { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_add: called CC=10 SCAR=23.7
3135 5 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3136 5 ▶ my $name = shift @args
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift @args or $self->wail("You did not specify what to add") 5 0 5
3137 or $self->wail( 'You did not specify what to add' );
3138 5 ▶ defined $self->_find_in_sky( $name )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_find_in_sky($name) and return 0 5 5
3139 and return;
3140 5 ▶ if ( my $obj = $self->_sky_object( $name, fatal => 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $self->_sky_object($name, 'fatal', 0)) { } 3 2 5
3141 3 push @{ $self->{sky} }, $obj;
3142 } else {
3143 2 ▶ @args >= 2
Branch: 1 branch
BranchTrueFalseTotal
@args >= 2 or $self->wail("You must give at least right ascension and declination") 1 1 2
3144 or $self->wail(
3145 'You must give at least right ascension and declination' );
3146 1 my $ra = deg2rad( $self->__parse_angle( shift @args ) );
3147 1 my $dec = deg2rad( $self->__parse_angle( shift @args ) );
3148 1 ▶ my $rng = @args ?
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
3149 $self->__parse_distance( shift @args, '1pc' ) :
3150 10000 * PARSEC;
3151 1 ▶ my $pmra = @args ? do {
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
3152 1 my $angle = shift @args;
3153 1 ▶ $angle =~ s/ s \z //smxi
Branch: 1 branch
BranchTrueFalseTotal
$angle =~ s/ s \z //imsx or $angle *= "0.0666666666666667" / cos($ra) 0 1 1
3154 or $angle *= 24 / 360 / cos( $ra );
3155 1 deg2rad( $angle / SPY2DPS );
3156 } : 0;
3157 1 ▶ my $pmdec = @args ? deg2rad( shift( @args ) / SPY2DPS ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
3158 1 ▶ my $pmrec = @args ? shift @args : 0;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 1 0 1
3159 1 push @{ $self->{sky} }, Astro::Coord::ECI::Star->new(
3160 debug => $self->{debug},
3161 1 name => $name,
3162 sun => $self->_sky_object( 'sun' ),
3163 )->position( $ra, $dec, $rng, $pmra, $pmdec, $pmrec );
3164 }
3165 4 return;
3166 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3167  
3168 0 ▶sub _sky_sub_class : Verb( add! delete! ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_class: not called CC=16 SCAR=56.1
3169 0 my ( $self, $opt, @arg ) = __arguments( @_ );
3170  
3171 $opt->{add}
3172 and $opt->{delete}
3173 0 ▶ and $self->wail( 'May not specify both add and delete' );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"add"} and $opt->{"delete"} and $self->wail("May not specify both add and delete") 0 0 0
Condition0%0/3
$opt->{"add"} and $opt->{"delete"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->{"add"} and $opt->{"delete"}
$opt->{"add"} $opt->{"delete"}
Truth table0%0/3
A and B
A= $opt->{"add"}B= $opt->{"delete"}
ABresult
0X0
100
111
3174  
3175 0 ▶ if ( $opt->{delete} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->{'delete'}) { } 0 0 0
elsif (@arg < 2) { } 0 0 0
3176 0 foreach my $name ( @arg ) {
3177 0 ▶ $name =~ m/ \A sun \z /smxi
Branch: 1 branch
BranchTrueFalseTotal
$name =~ / \A sun \z /imsx and $self->wail("Can not remove Sun class") 0 0 0
3178 and $self->wail( 'Can not remove Sun class' );
3179 0 ▶ defined $self->_find_in_sky( $name )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_find_in_sky($name) and $self->wail("Can not remove in-use class") 0 0 0
3180 and $self->wail( 'Can not remove in-use class' );
3181 0 delete $self->{sky_class}{ fold_case( $name ) };
3182 }
3183 } elsif ( @arg < 2 ) {
3184 @arg
3185 0 ▶ or @arg = sort keys %{ $self->{sky_class} };
Branch: 1 branch
BranchTrueFalseTotal
@arg or @arg = sort(keys %{$$self{"sky_class"};}) 0 0 0
3186 return join '', map {
3187 0 $self->_sky_class_components( $_ ) . "\n" }
3188 @arg;
3189 } else {
3190 0 my ( $name, $class, @attr ) = @arg;
3191 0 $self->load_package( { fatal => 'wail' }, $class );
3192 0 ▶ my $want_class = $name =~ m/ \A sun \z /smxi ?
Branch: 1 branch
BranchTrueFalseTotal
$name =~ / \A sun \z /imsx ? : 0 0 0
3193 SUN_CLASS_DEFAULT :
3194 'Astro::Coord::ECI';
3195 0 ▶ embodies( $class, $want_class )
Branch: 1 branch
BranchTrueFalseTotal
embodies($class, $want_class) or $self->wail("Must be a subclass of $want_class") 0 0 0
3196 or $self->wail(
3197 "Must be a subclass of $want_class" );
3198 +{ @attr }->{name}
3199 0 ▶ and $self->wail( 'May not specify name explicitly' );
Branch: 1 branch
BranchTrueFalseTotal
{@attr}->{"name"} and $self->wail("May not specify name explicitly") 0 0 0
3200 # name must be last, because _sky_class_components()
3201 # needs to recover it.
3202 0 push @attr, name => $name;
3203 0 my $obj = $class->new( @attr );
3204 0 my $folded_name = fold_case( $name );
3205 0 $self->{sky_class}{$folded_name} = [ $class, @attr ];
3206 $self->_replace_in_sky( $folded_name, $obj )
3207 or $opt->{add}
3208 0 ▶ and push @{ $self->{sky} }, $obj;
Branch: 1 branch
BranchTrueFalseTotal
$self->_replace_in_sky($folded_name, $obj) or $opt->{"add"} and push @{$$self{"sky"};}, $obj 0 0 0
Condition0%0/6
$self->_replace_in_sky($folded_name, $obj) || $opt->{'add'} && push(@{$$self{'sky'};}, $obj)
l!l&&r!l&&!r
000
$opt->{"add"} and push @{$$self{"sky"};}, $obj
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_replace_in_sky($folded_name, $obj) || $opt->{'add'} && push(@{$$self{'sky'};}, $obj)
$self->_replace_in_sky($folded_name, $obj) $opt->{"add"} push @{$$self{"sky"};}, $obj
Truth table0%0/4
A || B and C
A= $self->_replace_in_sky($folded_name, $obj)B= $opt->{"add"}C= push @{$$self{"sky"};}, $obj
ABCresult
1XX1
0111
00X0
0100
3209 0 $self->{_help_module}{$folded_name} = $class;
3210 0 ▶ if ( $obj->isa( 'Astro::Coord::ECI::Sun' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Astro::Coord::ECI::Sun")) 0 0 0
3211 0 foreach my $body (
3212 0 @{ $self->{bodies} }, @{ $self->{sky} }
3213 ) {
3214 0 $body->set(
3215 sun => $self->_sky_object( 'sun' ),
3216 );
3217 }
3218 }
3219 }
3220  
3221 0 return;
3222 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3223  
3224 1 ▶sub _sky_sub_clear : Verb() { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_clear: called CC=1 SCAR=0.0
3225 1 my ( $self ) = __arguments( @_ ); # $opt and args unused
3226 1 @{ $self->{sky} } = ();
3227 1 return;
3228 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3229  
3230 1 ▶sub _sky_sub_drop : Verb() Tweak( -completion _sky_body_complete ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_drop: called CC=3 SCAR=11.1
3231 1 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3232 1 ▶ @args or $self->wail(
Branch: 1 branch
BranchTrueFalseTotal
@args or $self->wail("You must specify at least one name to drop") 1 0 1
3233 'You must specify at least one name to drop' );
3234 1 foreach my $name ( @args ) {
3235 1 $self->_drop_from_sky( $name );
3236 }
3237 1 return;
3238 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3239  
3240 5 ▶sub _sky_sub_list : Verb( verbose! ) { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_list: called CC=6 SCAR=18.8
3241 5 my ( $self, $opt ) = __arguments( @_ ); # args unused
3242 5 my $output;
3243 5 foreach my $body (
3244 8 map { $_->[1] }
3245 4 sort { $a->[0] cmp $b->[0] }
3246 8 ▶ map { [ lc( $_->get( 'name' ) || $_->get( 'id' ) ), $_ ] }
Condition33%1/3
$_->get('name') || $_->get('id')
l!l&&r!l&&!r
800
MC/DC0%0/2
$_->get('name') || $_->get('id')
$_->get('name') $_->get('id')
Truth table33%1/3
A || B
A= $_->get('name')B= $_->get('id')
ABresult
1X1
011
000
3247 5 @{$self->{sky}}
3248 ) {
3249 8 $output .= _sky_list_body( $body );
3250 8 ▶ if ( $opt->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"verbose"}) 0 8 8
3251 0 $output .= "# Class: @{[ ref $body ]}\n";
3252 }
3253 }
3254 5 ▶ unless (@{$self->{sky}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"sky"};}) 1 4 5
3255 $self->{warn_on_empty}
3256 1 ▶ and $self->whinge( 'The sky is empty' );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"warn_on_empty"} and $self->whinge("The sky is empty") 0 1 1
3257 }
3258 5 return $output;
3259 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3260  
3261 # Undocumented. That means I can revoke at any time, without notice. If
3262 # you need this functionality, please contact me.
3263 0 ▶sub _sky_sub_load : Verb() { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_load: not called CC=3 SCAR=24.8
3264 0 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3265 0 my $tle;
3266 0 foreach my $fn ( @args ) {
3267 0 local $/ = undef;
3268 0 ▶ open my $fh, '<', $fn
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fn or $self->wail("Failed to open ${fn}: $!") 0 0 0
3269 or $self->wail( "Failed to open $fn: $!" );
3270 0 $tle .= <$fh>;
3271 0 close $fh;
3272 }
3273 0 return $self->_sky_sub_tle( $tle );
3274 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3275  
3276 0 ▶sub _sky_sub_lookup : Verb() { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_sub_lookup: not called CC=2 SCAR=17.9
3277 0 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3278 0 my $output;
3279 0 my $name = shift @args;
3280 0 ▶ defined $self->_find_in_sky( $name )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_find_in_sky($name) and $self->wail("Duplicate sky entry '${name}'") 0 0 0
3281 and $self->wail( "Duplicate sky entry '$name'" );
3282 0 my ($ra, $dec, $rng, $pmra, $pmdec, $pmrec) =
3283 $self->_simbad4 ($name);
3284 0 $rng = sprintf '%.2f', $rng;
3285 0 $output .= 'sky add ' . quoter ($name) .
3286 " $ra $dec $rng $pmra $pmdec $pmrec\n";
3287 0 $ra = deg2rad ($self->__parse_angle ($ra));
3288 0 my $body = Astro::Coord::ECI::Star->new(
3289 name => $name,
3290 sun => $self->_sky_object( 'sun' ),
3291 );
3292 0 $body->position ($ra, deg2rad ($self->__parse_angle ($dec)),
3293 $rng * PARSEC, deg2rad ($pmra * 24 / 360 / cos ($ra) / SPY2DPS),
3294 deg2rad ($pmdec / SPY2DPS), $pmrec);
3295 0 push @{$self->{sky}}, $body;
3296 0 return $output;
3297 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3298  
3299 # Undocumented. That means I can revoke at any time, without notice. If
3300 # you need this functionality, please contact me.
3301 0 ▶sub _sky_sub_tle : Verb() {
Subroutine _sky_sub_tle: not called CC=3 SCAR=24.8
3302 0 my ( $self, undef, $tle ) = __arguments( @_ ); # $opt unused
3303 0 my @bodies = Astro::Coord::ECI::TLE::Set->aggregate(
3304 Astro::Coord::ECI::TLE->parse( $tle ) );
3305 0 my %extant = map { $_->get( 'id' ) => 1 }
3306 0 grep { embodies( $_, 'Astro::Coord::ECI::TLE' ) }
3307 0 @{ $self->{sky} };
3308 0 foreach my $body ( @bodies ) {
3309 0 my $id = $body->get( 'id' );
3310 0 ▶ $extant{$id}
Branch: 1 branch
BranchTrueFalseTotal
$extant{$id} and $self->wail("Duplicate sky entry $id") 0 0 0
3311 and $self->wail( "Duplicate sky entry $id" );
3312 }
3313 0 push @{ $self->{sky} }, @bodies;
3314 0 return sprintf "sky tle %s\n", quoter( $tle );
3315 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3316  
3317 8 ▶sub source : Verb( optional! ) {
Subroutine source: called CC=8 SCAR=20.8
Pod documented
3318 8 my ( $self, $opt, $src, @args ) = __arguments( @_ );
3319  
3320 8 my $output;
3321 8 ▶ my $reader = $self->_file_reader( $src, $opt )
Branch: 1 branch
BranchTrueFalseTotal
my $reader = $self->_file_reader($src, $opt) or return 6 1 7
3322 or return;
3323  
3324 6 my @level1_cache;
3325 6 my $level1_context = {};
3326 21 ▶ my $fetcher = $opt->{level1} ? sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
3327 @level1_cache
3328 21 ▶ and return shift @level1_cache;
Branch: 1 branch
BranchTrueFalseTotal
@level1_cache and return shift @level1_cache 2 19 21
3329 19 my $buffer = $reader->();
3330 19 @level1_cache = $self->_rewrite_level1_command(
3331 $buffer, $level1_context );
3332 19 return shift @level1_cache;
3333 6 ▶ } : $reader;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'level1'} ? : 4 2 6
3334  
3335 6 my $frames = $self->_frame_push( source => \@args );
3336 # Note that level1 is unsupported, and works only when the
3337 # options are passed as a hash. It will go away when support for
3338 # the original satpass script is dropped.
3339 6 $self->{frame}[-1]{level1} = $opt->{level1};
3340 6 my $err;
3341 6 ▶ my $ok = eval { while ( defined( my $input = $fetcher->() ) ) {
Branch: 2 branches
BranchTrueFalseTotal
my $ok = eval { do { while (defined(my $input = &$fetcher())) { do { if (defined(my $buffer = $self->execute($fetcher, $input))) { $output .= $buffer; } }; } ; 1 } } or $err = $@ 6 0 6
if (defined(my $input = &$fetcher())) 13 6 19
3342 13 ▶ if ( defined ( my $buffer = $self->execute( $fetcher,
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $buffer = $self->execute($fetcher, $input))) 2 11 13
3343 $input ) ) ) {
3344 2 $output .= $buffer;
3345 }
3346 }
3347 6 1;
3348 } or $err = $@;
3349  
3350 6 $self->_frame_pop( $frames );
3351 6 ▶ $ok or $self->whinge( $err );
Branch: 1 branch
BranchTrueFalseTotal
$ok or $self->whinge($err) 6 0 6
3352  
3353 6 ▶ $opt->{level1} and $self->_rewrite_level1_macros();
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"level1"} and $self->_rewrite_level1_macros 4 2 6
3354 6 return $output;
3355 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3356  
3357 {
3358  
3359 20 ▶ use constant _FORMAT_NONE => undef; # Must be undef
Subroutine BEGIN: called CC=1 SCAR=0.0
3360 20 ▶ use constant _FORMAT_DEFAULT => 'json'; # Must be defined
Subroutine BEGIN: called CC=1 SCAR=0.0
3361  
3362 20 my %default_format = (
3363 new => _FORMAT_NONE,
3364 amsat => _FORMAT_NONE,
3365 attribute_names => _FORMAT_NONE,
3366 banner => _FORMAT_NONE,
3367 box_score => _FORMAT_DEFAULT,
3368 celestrak => _FORMAT_DEFAULT,
3369 celestrak_supplemental => _FORMAT_DEFAULT,
3370 cache_hit => _FORMAT_NONE,
3371 content_source => _FORMAT_NONE,
3372 content_type => _FORMAT_NONE,
3373 content_interface => _FORMAT_NONE,
3374 country_names => _FORMAT_DEFAULT,
3375 favorite => _FORMAT_DEFAULT,
3376 file => _FORMAT_DEFAULT,
3377 get => _FORMAT_NONE,
3378 getv => _FORMAT_NONE,
3379 help => _FORMAT_NONE,
3380 iridium_status => _FORMAT_NONE,
3381 launch_sites => _FORMAT_DEFAULT,
3382 login => _FORMAT_NONE,
3383 logout => _FORMAT_NONE,
3384 mccants => _FORMAT_NONE,
3385 names => _FORMAT_NONE, # ??
3386 retrieve => _FORMAT_DEFAULT,
3387 search_date => _FORMAT_DEFAULT,
3388 search_decay => _FORMAT_DEFAULT,
3389 search_id => _FORMAT_DEFAULT,
3390 search_name => _FORMAT_DEFAULT,
3391 search_oid => _FORMAT_DEFAULT,
3392 set => _FORMAT_NONE,
3393 shell => _FORMAT_NONE,
3394 source => _FORMAT_NONE,
3395 spacetrack => _FORMAT_DEFAULT,
3396 spacetrack_query_v2 => _FORMAT_DEFAULT,
3397 update => _FORMAT_DEFAULT,
3398 flush_identity_cache => _FORMAT_NONE,
3399 );
3400  
3401 my %handler = (
3402 0 ▶ config => sub {
Subroutine __ANON__: not called CC=10 SCAR=44.7
3403 0 my ( $self, $obj, undef, $opt, @args ) = @_; # $method unused
3404 0 ▶ @args or @args = $obj->attribute_names();
Branch: 1 branch
BranchTrueFalseTotal
@args or @args = $obj->attribute_names 0 0 0
3405 0 my ( $rslt, @values, $virgin );
3406 $opt->{changes}
3407 0 ▶ and $virgin = $self->_get_spacetrack_default();
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"changes"} and $virgin = $self->_get_spacetrack_default 0 0 0
3408 0 foreach my $name ( @args ) {
3409 0 $rslt = $obj->get( $name );
3410 0 ▶ $rslt->is_success()
Branch: 1 branch
BranchTrueFalseTotal
$rslt->is_success or return $rslt 0 0 0
3411 or return $rslt;
3412 0 my $value = $rslt->content();
3413 20 ▶ no warnings qw{ uninitialized };
Subroutine BEGIN: called CC=1 SCAR=0.0
3414 $opt->{changes}
3415 0 ▶ and $value eq $virgin->getv( $name )
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"changes"} and $value eq $virgin->getv($name) and next 0 0 0
Condition0%0/3
$opt->{"changes"} and $value eq $virgin->getv($name)
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->{"changes"} and $value eq $virgin->getv($name)
$opt->{"changes"} $value eq $virgin->getv($name)
Truth table0%0/3
A and B
A= $opt->{"changes"}B= $value eq $virgin->getv($name)
ABresult
0X0
100
111
3416 and next;
3417 0 push @values, [ $name, $value ];
3418 }
3419 0 ▶ if ( $opt->{raw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'raw'}) { } 0 0 0
3420 0 $rslt->content( \@values );
3421 } else {
3422 0 ▶ $opt->{raw} and return \@values;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"raw"} and return \@values 0 0 0
3423 0 my $output = '';
3424 0 foreach ( @values ) {
3425 0 $output .= quoter( qw{ spacetrack set }, @{ $_ } ) . "\n";
3426 }
3427 0 $rslt->content( $output );
3428 }
3429 0 return $rslt;
3430 },
3431 0 ▶ get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3432 0 my ( undef, $obj, undef, $opt, @args ) = @_; # Invocant, $method unused
3433 0 my $rslt = $obj->get( @args );
3434 $rslt->is_success
3435 and not $opt->{raw}
3436 0 ▶ and $rslt->content( scalar quoter(
Branch: 1 branch
BranchTrueFalseTotal
$rslt->is_success and not $opt->{"raw"} and $rslt->content(scalar quoter(("spacetrack", "set"), $args[0], $rslt->content)) 0 0 0
Condition0%0/3
$rslt->is_success and not $opt->{"raw"}
!ll&&!rl&&r
000
MC/DC0%0/2
$rslt->is_success and not $opt->{"raw"}
$rslt->is_success not $opt->{"raw"}
Truth table0%0/3
A and not(B)
A= $rslt->is_successB= not $opt->{"raw"}
ABresult
0X0
100
111
3437 qw{ spacetrack set }, $args[0], $rslt->content() ) );
3438 0 return $rslt;
3439 },
3440 0 ▶ mccants => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3441 0 my ( undef, $obj, undef, $opt, @args ) = @_; # Invocant, $method unused
3442 0 delete $opt->{format}; # You get what he gives you
3443 0 return $obj->mccants( @args );
3444 },
3445 0 ▶ set => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3446 0 my ( undef, $obj, $method, undef, @args ) = @_; # Invocant, $opt unused
3447 0 return $obj->$method( @args );
3448 },
3449 20 );
3450 20 $handler{getv} = $handler{get};
3451 20 $handler{show} = $handler{config};
3452 20 $handler{spacetrack_query_v2} = $handler{set};
3453  
3454 20 my %suppress_output = map { $_ => 1 } '', 'set';
3455  
3456 # Attributes must all be on one line to process correctly under
3457 # 5.8.8.
3458 0 ▶ sub spacetrack : Verb( all! changes! descending! effective! end_epoch=s exclude=s format=s last5! raw! rcs! status=s sort=s start_epoch=s tle! verbose! ) {
Subroutine spacetrack: not called CC=19 SCAR=59.4
Pod documented
3459 0 my ( $self, $opt, $method, @args ) = __arguments( @_ );
3460  
3461 exists $opt->{raw}
3462 0 ▶ or $opt->{raw} = ( ! _is_interactive() );
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"raw"} or $opt->{"raw"} = !_is_interactive() 0 0 0
3463  
3464 0 my $verbose = delete $opt->{verbose};
3465  
3466 0 my $object = $self->_helper_get_object( 'spacetrack' );
3467 $method !~ m/ \A _ /smx and $object->can( $method )
3468 0 ▶ or $handler{$method}
Branch: 1 branch
BranchTrueFalseTotal
not $method =~ / \A _ /msx and $object->can($method) or $handler{$method} or $self->wail("No such spacetrack method as '${method}'") 0 0 0
Condition0%0/6
not $method =~ / \A _ /msx and $object->can($method) or $handler{$method}
l!l&&r!l&&!r
000
not $method =~ / \A _ /msx and $object->can($method)
!ll&&!rl&&r
000
MC/DC0%0/3
not $method =~ / \A _ /msx and $object->can($method) or $handler{$method}
not $method =~ / \A _ /msx $object->can($method) $handler{$method}
Truth table0%0/5
not(A) and B or C
A= not $method =~ / \A _ /msxB= $object->can($method)C= $handler{$method}
ABCresult
11X1
0X11
1011
0X00
1000
3469 or $self->wail("No such spacetrack method as '$method'");
3470  
3471 $opt->{start_epoch}
3472 and $opt->{start_epoch} = $self->__parse_time(
3473 0 ▶ $opt->{start_epoch} );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"start_epoch"} and $opt->{"start_epoch"} = $self->__parse_time($opt->{"start_epoch"}) 0 0 0
3474 $opt->{end_epoch}
3475 and $opt->{end_epoch} = $self->__parse_time(
3476 0 ▶ $opt->{end_epoch} );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"end_epoch"} and $opt->{"end_epoch"} = $self->__parse_time($opt->{"end_epoch"}) 0 0 0
3477  
3478 0 ▶ if ( defined( my $df = $default_format{$method} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $df = $default_format{$method})) { } 0 0 0
3479 defined $opt->{format}
3480 0 ▶ or $opt->{format} = $df;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt->{"format"} or $opt->{"format"} = $df 0 0 0
3481 } else {
3482 # FIXME I would prefer to error out here, but not sure I
3483 # can.
3484 0 delete $opt->{format};
3485 }
3486  
3487 0 my ( $rslt, @rest );
3488 0 ▶ if ( $handler{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler{$method}) { } 0 0 0
3489 0 ( $rslt, @rest ) = $handler{$method}->(
3490 $self, $object, $method, $opt, @args );
3491 } else {
3492 0 delete $opt->{raw};
3493 0 ( $rslt, @rest ) = $object->$method( $opt, @args );
3494 }
3495  
3496 0 ▶ $rslt->is_success()
Branch: 1 branch
BranchTrueFalseTotal
$rslt->is_success or $self->wail($rslt->status_line) 0 0 0
3497 or $self->wail( $rslt->status_line() );
3498  
3499 0 my $output;
3500 0 ▶ my $content_type = $object->content_type || '';
Condition0%0/2
$object->content_type || ''
l!l
00
MC/DC0%0/1
$object->content_type || ''
$object->content_type
Truth table0%0/2
A
A= $object->content_type
Aresult
11
00
3501  
3502 0 ▶ if ($content_type eq 'orbit') {
Branch: 3 branches
BranchTrueFalseTotal
if ($content_type eq 'orbit') { } 0 0 0
elsif ($content_type eq 'iridium-status') { } 0 0 0
elsif (not $suppress_output{$content_type} or $verbose) { } 0 0 0
3503  
3504 0 push @{$self->{bodies}},
3505 Astro::Coord::ECI::TLE->parse ($rslt->content);
3506 0 ▶ $verbose
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $output .= $rslt->content 0 0 0
3507 and $output .= $rslt->content;
3508  
3509 } elsif ($content_type eq 'iridium-status') {
3510  
3511 0 $self->_iridium_status( @rest );
3512 0 ▶ $verbose
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $output .= $rslt->content 0 0 0
3513 and $output .= $rslt->content;
3514  
3515 ▶ } elsif ( ! $suppress_output{$content_type} || $verbose ) {
Condition0%0/3
not $suppress_output{$content_type} or $verbose
l!l&&r!l&&!r
000
MC/DC0%0/2
not $suppress_output{$content_type} or $verbose
not $suppress_output{$content_type} $verbose
Truth table0%0/3
not(A) or B
A= not $suppress_output{$content_type}B= $verbose
ABresult
1X1
011
000
3516  
3517 0 $output .= $rslt->content;
3518  
3519 }
3520  
3521 0 ▶ defined $output
Branch: 1 branch
BranchTrueFalseTotal
defined $output and $output =~ s/ (?<! \n ) \z /\n/msx 0 0 0
3522 and $output =~ s/ (?<! \n ) \z /\n/smx;
3523 0 return $output;
3524 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
3525  
3526 }
3527  
3528 20 ▶sub st : Verb() {
Subroutine st: not called CC=4 SCAR=28.1
Pod documented
3529 0 my ( $self, undef, $func, @args ) = __arguments( @_ ); # $opt unused
3530  
3531 0 $self->_deprecation_notice( method => 'st' );
3532 0 ▶ if ( 'localize' eq $func ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('localize' eq $func) { } 0 0 0
3533 0 my $st = $self->_helper_get_object( 'spacetrack' );
3534 0 foreach my $key (@args) {
3535 exists $self->{frame}[-1]{spacetrack}{$key}
3536 0 ▶ or $self->{frame}[-1]{spacetrack}{$key} =
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"frame"}[-1]{"spacetrack"}{$key} or $self->{"frame"}[-1]{"spacetrack"}{$key} = $st->get($key)->content 0 0 0
3537 $st->get ($key)->content
3538 }
3539 } else {
3540 0 goto &spacetrack;
3541 }
3542 0 return;
3543 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3544  
3545 36 ▶sub station {
Subroutine station: called CC=6 SCAR=21.2
Pod documented
3546 36 my ( $self ) = @_;
3547  
3548 defined $self->{height}
3549 and defined $self->{latitude}
3550 and defined $self->{longitude}
3551 36 ▶ or $self->wail( 'You must set height, latitude, and longitude' );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"height"} and defined $self->{"latitude"} and defined $self->{"longitude"} or $self->wail("You must set height, latitude, and longitude") 36 0 36
Condition33%2/6
defined $self->{"height"} and defined $self->{"latitude"} and defined $self->{"longitude"}
!ll&&!rl&&r
0036
defined $self->{"height"} and defined $self->{"latitude"}
!ll&&!rl&&r
0036
MC/DC0%0/3
defined $self->{"height"} and defined $self->{"latitude"} and defined $self->{"longitude"}
defined $self->{"height"} defined $self->{"latitude"} defined $self->{"longitude"}
Truth table25%1/4
A and B and C
A= defined $self->{"height"}B= defined $self->{"latitude"}C= defined $self->{"longitude"}
ABCresult
0XX0
10X0
1100
1111
3552  
3553 return Astro::Coord::ECI->new (
3554 almanac_horizon => $self->{_almanac_horizon},
3555 horizon => deg2rad( $self->get( 'horizon' ) ),
3556 id => 'station',
3557 name => $self->{location} || '',
3558 refraction => $self->{refraction} || 0,
3559 )->geodetic (
3560 deg2rad( $self->{latitude} ),
3561 deg2rad( $self->{longitude} ),
3562 36 ▶ $self->{height} / 1000
Condition75%3/4
$self->{'location'} || ''
l!l
351
$self->{'refraction'} || 0
l!l
360
MC/DC100%1/1
$self->{'location'} || ''
$self->{'location'}
MC/DC0%0/1
$self->{'refraction'} || 0
$self->{'refraction'}
Truth table100%2/2
A
A= $self->{'location'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'refraction'}
Aresult
11
00
3563 );
3564 }
3565  
3566 # TODO I must have thought -reload would be good for something, but it
3567 # appears I never implemented it.
3568  
3569 3 ▶sub status : Verb( name! reload! ) {
Subroutine status: called CC=14 SCAR=30.2
Pod documented
3570 3 my ( $self, $opt, @args ) = __arguments( @_ );
3571  
3572 3 ▶ @args or @args = qw{show};
Branch: 1 branch
BranchTrueFalseTotal
@args or @args = "show" 2 1 3
3573  
3574 3 ▶ my $verb = lc (shift (@args) || 'show');
Condition50%1/2
shift @args || 'show'
l!l
30
MC/DC0%0/1
shift @args || 'show'
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
3575  
3576 3 ▶ if ( $verb eq 'iridium' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "iridium") 0 3 3
3577 0 $self->_deprecation_notice( status => 'iridium', 'show' );
3578 0 $verb = 'show';
3579 }
3580  
3581 3 my $output;
3582  
3583 3 ▶ if ($verb eq 'add' || $verb eq 'drop') {
Branch: 3 branches
BranchTrueFalseTotal
if ($verb eq 'add' or $verb eq 'drop') { } 1 2 3
elsif ($verb eq 'clear') { } 1 1 2
elsif ($verb eq 'show' or $verb eq 'list') { } 1 0 1
Condition66%2/3
$verb eq "add" or $verb eq "drop"
l!l&&r!l&&!r
012
MC/DC50%1/2
$verb eq "add" or $verb eq "drop"
$verb eq "add" $verb eq "drop"
Truth table66%2/3
A or B
A= $verb eq "add"B= $verb eq "drop"
ABresult
1X1
011
000
3584  
3585 1 Astro::Coord::ECI::TLE->status ($verb, @args);
3586 1 foreach my $tle (@{$self->{bodies}}) {
3587 1 ▶ $tle->get ('id') == $args[0] and $tle->rebless ();
Branch: 1 branch
BranchTrueFalseTotal
$tle->get("id") == $args[0] and $tle->rebless 1 0 1
3588 }
3589  
3590 } elsif ($verb eq 'clear') {
3591  
3592 1 Astro::Coord::ECI::TLE->status ($verb, @args);
3593 1 foreach my $tle (@{$self->{bodies}}) {
3594 2 $tle->rebless ();
3595 }
3596  
3597 ▶ } elsif ($verb eq 'show' || $verb eq 'list') {
Condition33%1/3
$verb eq "show" or $verb eq "list"
l!l&&r!l&&!r
100
MC/DC0%0/2
$verb eq "show" or $verb eq "list"
$verb eq "show" $verb eq "list"
Truth table33%1/3
A or B
A= $verb eq "show"B= $verb eq "list"
ABresult
1X1
011
000
3598  
3599 1 my @data = Astro::Coord::ECI::TLE->status( 'show', @args );
3600 0 ▶ @data = sort {$a->[3] cmp $b->[3]} @data if $opt->{name};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"name"} 0 1 1
3601 1 $output .= ''; # Don't want it to be undef.
3602  
3603 my $encoder = ( HAVE_TLE_IRIDIUM &&
3604 Astro::Coord::ECI::TLE::Iridium->can(
3605 0 ▶ '__encode_operational_status' ) ) || sub { return $_[2] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
3606  
3607 1 foreach my $tle (@data) {
3608 0 my $status = $encoder->( undef, status => $tle->[2] );
3609 0 $output .= quoter( 'status', 'add',
3610 $tle->[0], $tle->[1], $status,
3611 $tle->[3], $tle->[4] ) . "\n";
3612 }
3613  
3614 } else {
3615 0 $output .= ''; # Don't want it to be undef.
3616 0 $output .= Astro::Coord::ECI::TLE->status ($verb, @args);
3617 }
3618  
3619 3 return $output;
3620  
3621 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3622  
3623 4 ▶sub system : method Verb() { ## no critic (ProhibitBuiltInHomonyms)
Subroutine system: called CC=4 SCAR=14.8
Pod documented
3624 4 my ( $self, undef, $verb, @args ) = __arguments( @_ ); # $opt unused
3625  
3626 @args = map {
3627 4 bsd_glob( $_, GLOB_NOCHECK | GLOB_BRACE | GLOB_QUOTE )
3628 } @args;
3629 4 my $stdout = $self->{frame}[-1]{localout};
3630 4 my @exported = keys %{ $self->{exported} };
3631 4 local @ENV{@exported} = map { $mutator{$_} ? $self->get( $_ ) :
3632 5 ▶ $self->{exported}{$_} } @exported;
Branch: 1 branch
BranchTrueFalseTotal
$mutator{$_} ? : 4 1 5
3633 4 ▶ if ( defined $stdout && -t $stdout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stdout and -t $stdout) { } 0 4 4
Condition33%1/3
defined $stdout and -t $stdout
!ll&&!rl&&r
400
MC/DC0%0/2
defined $stdout and -t $stdout
defined $stdout -t $stdout
Truth table33%1/3
A and B
A= defined $stdoutB= -t $stdout
ABresult
0X0
100
111
3634 0 CORE::system {$verb} $verb, @args;
3635 0 return;
3636 } else {
3637 4 $self->load_package( { fatal => 'wail' }, 'IPC::System::Simple' );
3638 4 return IPC::System::Simple::capturex( $verb, @args );
3639 }
3640 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3641  
3642 1 ▶sub time : method Verb() Tweak( -unsatisfied ) { ## no critic (ProhibitBuiltInHomonyms,RequireArgUnpacking)
Subroutine time: called CC=4 SCAR=14.6
Pod documented
3643 0 ▶ my ($self, @args) = map { ARRAY_REF eq ref $_ ? @{ $_ } : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $_ ? : 0 2 2
3644 1 ▶ $have_time_hires->() or $self->wail( 'Time::HiRes not available' );
Branch: 1 branch
BranchTrueFalseTotal
&$have_time_hires() or $self->wail("Time::HiRes not available") 1 0 1
3645 1 $self->_dispatch_check( time => $args[0] );
3646 1 my $start = Time::HiRes::time();
3647 # If we're inside an unsatisfied if() we do not do the timing,
3648 # because dispatch() is probably a no-op.
3649 $self->_in_unsatisfied_if()
3650 or $self->_add_post_dispatch(
3651 1 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3652 1 return sprintf "%.3f seconds\n", Time::HiRes::time() - $start;
3653 },
3654 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->_in_unsatisfied_if or $self->_add_post_dispatch(sub { return sprintf("%.3f seconds\n", &Time::HiRes::time() - $start); } ) 0 1 1
3655 1 return $self->dispatch( @args );
3656 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3657  
3658 0 ▶sub time_parser : Verb() {
Subroutine time_parser: not called CC=2 SCAR=17.9
Pod documented
3659 0 ▶ splice @_, ( HASH_REF eq ref $_[1] ? 2 : 1 ), 0, 'time_parser';
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $_[1] ? : 0 0 0
3660 0 goto &_helper_handler;
3661 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3662  
3663 4 ▶sub tle : Verb( :compute __tle_options ) {
Subroutine tle: called CC=4 SCAR=14.6
Pod documented
3664 4 my ( $self, $opt, @args ) = __arguments( @_ );
3665 @args
3666 and not $opt->{choose}
3667 4 ▶ and $opt->{choose} = \@args;
Branch: 1 branch
BranchTrueFalseTotal
@args and not $opt->{"choose"} and $opt->{"choose"} = \@args 0 4 4
Condition33%1/3
@args and not $opt->{"choose"}
!ll&&!rl&&r
400
MC/DC0%0/2
@args and not $opt->{"choose"}
@args not $opt->{"choose"}
Truth table33%1/3
A and not(B)
A= @argsB= not $opt->{"choose"}
ABresult
0X0
100
111
3668  
3669 4 my $bodies = $self->__choose( $opt->{choose}, $self->{bodies} );
3670 5 @{ $bodies } = map { $_->[0] }
3671 1 ▶ sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] }
Condition33%1/3
$Astro::App::Satpass2::a->[1] <=> $Astro::App::Satpass2::b->[1] || $Astro::App::Satpass2::a->[2] <=> $Astro::App::Satpass2::b->[2]
l!l&&r!l&&!r
100
MC/DC0%0/2
$Astro::App::Satpass2::a->[1] <=> $Astro::App::Satpass2::b->[1] || $Astro::App::Satpass2::a->[2] <=> $Astro::App::Satpass2::b->[2]
$Astro::App::Satpass2::a->[1] <=> $Astro::App::Satpass2::b->[1] $Astro::App::Satpass2::a->[2] <=> $Astro::App::Satpass2::b->[2]
Truth table33%1/3
A || B
A= $Astro::App::Satpass2::a->[1] <=> $Astro::App::Satpass2::b->[1]B= $Astro::App::Satpass2::a->[2] <=> $Astro::App::Satpass2::b->[2]
ABresult
1X1
011
000
3672 5 map { [ $_, $_->get( 'id' ), $_->get( 'epoch' ) ] }
3673 4 @{ $bodies };
3674 4 my $tplt_name = delete $opt->{_template};
3675 4 return $self->__format_data( $tplt_name => $bodies, $opt );
3676 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3677  
3678 4 ▶sub __tle_options {
Subroutine __tle_options: called CC=1 SCAR=0.0
3679 4 my ( $self, $opt ) = @_;
3680 return [
3681 4 qw{ choose=s@ },
3682 $self->_templates_to_options( tle => $opt ),
3683 ];
3684 }
3685  
3686 1 ▶sub unexport : Verb() {
Subroutine unexport: called CC=2 SCAR=6.9
Pod documented
3687 1 my ( $self, undef, @args ) = __arguments( @_ ); # $opt unused
3688  
3689 1 foreach my $name ( @args ) {
3690 1 delete $self->{exported}{$name};
3691 }
3692 1 return;
3693 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3694  
3695 1 ▶sub validate : Verb( quiet! ) {
Subroutine validate: called CC=6 SCAR=18.2
Pod documented
3696 1 my ( $self, $opt, @args ) = __arguments( @_ );
3697  
3698 1 my $pass_start = $self->__parse_time (
3699 shift @args, $self->_get_day_noon());
3700 1 ▶ my $pass_end = $self->__parse_time (shift @args || '+7');
Condition50%1/2
shift @args || '+7'
l!l
01
MC/DC0%0/1
shift @args || '+7'
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
3701 1 ▶ $pass_start >= $pass_end
Branch: 1 branch
BranchTrueFalseTotal
$pass_start >= $pass_end and $self->wail("End time must be after start time") 0 1 1
3702 and $self->wail( 'End time must be after start time' );
3703  
3704 1 ▶ @{ $self->{bodies} }
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"bodies"};} or $self->wail("No bodies selected") 1 0 1
3705 or $self->wail( 'No bodies selected' );
3706  
3707 # Validate each body.
3708  
3709 1 my @valid;
3710 1 foreach my $tle ( $self->_aggregate( $self->{bodies} ) ) {
3711 2 ▶ $tle->validate( $opt, $pass_start, $pass_end )
Branch: 1 branch
BranchTrueFalseTotal
$tle->validate($opt, $pass_start, $pass_end) and push @valid, $tle->members 1 1 2
3712 and push @valid, $tle->members();
3713 }
3714  
3715 1 $self->{bodies} = \@valid;
3716  
3717 1 return;
3718 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3719  
3720 0 ▶sub version : Verb() {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
3721 0 return <<"EOD";
3722  
3723 0 @{[__PACKAGE__]} $VERSION - Satellite pass predictor
3724 0 based on Astro::Coord::ECI @{[Astro::Coord::ECI->VERSION]}
3725 Copyright (C) 2009-2026 by Thomas R. Wyant, III
3726  
3727 EOD
3728 20 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3729  
3730 ########################################################################
3731  
3732 # $self->_add_post_dispatch( $code_ref );
3733  
3734 # Add a reference to code to be executed after the current interactive
3735 # method is dispatched. All such code is executed, in the reverse of
3736 # the order it was added. The only argument will be the invocant.
3737 # Because it is added to the current execution frame, if the
3738 # interactive method being dispatched is begin(), the code will be
3739 # executed after the corresponding end(). Code to make the execution
3740 # happen is, of course, in dispatch().
3741 23 ▶sub _add_post_dispatch {
Subroutine _add_post_dispatch: called CC=2 SCAR=7.0
3742 23 my ( $self, $code ) = @_;
3743 23 ▶ push @{ $self->{frame}[-1]{post_dispatch} ||= [] }, $code;
Condition50%1/2
$self->{"frame"}[-1]{"post_dispatch"} ||= []
l!l
023
MC/DC0%0/1
$self->{"frame"}[-1]{"post_dispatch"} ||= []
$self->{"frame"}[-1]{"post_dispatch"}
Truth table50%1/2
A
A= $self->{"frame"}[-1]{"post_dispatch"}
Aresult
11
00
3744 23 return;
3745 }
3746  
3747 # $self->_aggregate( $list_ref );
3748  
3749 5 ▶sub __add_to_observing_list {
Subroutine __add_to_observing_list: called CC=4 SCAR=17.2
3750 5 my ( $self, @args ) = @_;
3751 5 foreach my $body ( @args ) {
3752 10 ▶ embodies( $body, 'Astro::Coord::ECI::TLE' )
Branch: 1 branch
BranchTrueFalseTotal
embodies($body, "Astro::Coord::ECI::TLE") and next 10 0 10
3753 and next;
3754 0 my $id = $body->get( 'id' );
3755 0 ▶ defined $id
Branch: 1 branch
BranchTrueFalseTotal
defined $id or $id = $body->get("name") 0 0 0
3756 or $id = $body->get( 'name' );
3757 0 $self->wail( "Body $id is not a TLE" );
3758 }
3759 5 push @{ $self->{bodies} }, @args;
3760 5 return $self;
3761 }
3762  
3763 # This is just a wrapper for
3764 # Astro::Coord::ECI::TLE::Set->aggregate.
3765  
3766 29 ▶sub _aggregate {
Subroutine _aggregate: called CC=1 SCAR=0.0
3767 29 my ( $self, $bodies ) = @_;
3768 29 local $Astro::Coord::ECI::TLE::Set::Singleton = $self->{singleton};
3769 29 return Astro::Coord::ECI::TLE::Set->aggregate ( @{ $bodies } );
3770 }
3771  
3772 # _apply_boolean_default( \%opt, $invert, @keys );
3773 #
3774 # This subroutine defaults a set of boolean options. The keys in
3775 # the set are specified in @keys, and the defined values are
3776 # inverted before the defaults are applied if $invert is true.
3777 # Nothing is returned.
3778  
3779 44 ▶sub _apply_boolean_default {
Subroutine _apply_boolean_default: called CC=9 SCAR=22.3
3780 44 my ( $self, $opt, $invert, @keys ) = @_;
3781 44 my $state = my $found = 0;
3782 44 foreach my $key ( @keys ) {
3783 136 ▶ if ( exists $opt->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{$key}) 8 128 136
3784 8 $found++;
3785 $invert
3786 8 ▶ and $opt->{$key} = ( ! $opt->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
$invert and $opt->{$key} = !$opt->{$key} 0 8 8
3787 8 ▶ $state |= ( $opt->{$key} ? 2 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{$key} ? : 6 2 8
3788 }
3789 }
3790 1 == $state # Only negated options found
3791 and @keys == $found # All options in group were specified
3792 and $self->wail( 'May not negate all of ' . join ', ', map {
3793 0 ▶ "-$_" } @keys );
Branch: 1 branch
BranchTrueFalseTotal
1 == $state and @keys == $found and $self->wail('May not negate all of ' . join(", ", map({"-$_";} @keys))) 0 44 44
Condition66%2/3
1 == $state and @keys == $found
!ll&&!rl&&r
4220
MC/DC0%0/2
1 == $state and @keys == $found
1 == $state @keys == $found
Truth table66%2/3
A and B
A= 1 == $stateB= @keys == $found
ABresult
0X0
100
111
3794 44 my $default = $state < 2;
3795 44 foreach my $key ( @keys ) {
3796 exists $opt->{$key}
3797 136 ▶ or $opt->{$key} = $default;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{$key} or $opt->{$key} = $default 8 128 136
3798 }
3799 44 return;
3800 }
3801  
3802 # $self->_attribute_exists( $name, %arg );
3803 #
3804 # This method returns true if an accessor for the given attribute
3805 # exists, and croaks otherwise.
3806 # Attributes in the %level1_attr hash fail unless in level1 mode
3807 # Named arguments:
3808 # query: if true, returns false if attribute does not exist
3809  
3810 {
3811 20 my %level1_attr = map { $_ => 1 } qw{ sun };
3812  
3813 1288 ▶ sub _attribute_exists {
Subroutine _attribute_exists: called CC=5 SCAR=24.5
3814 1288 my ( $self, $name, %arg ) = @_;
3815 exists $accessor{$name}
3816 and ( ! $level1_attr{$name} || $self->{frame}[-1]{level1} )
3817 1288 ▶ and return $accessor{$name};
Branch: 1 branch
BranchTrueFalseTotal
exists $accessor{$name} and !$level1_attr{$name} || $self->{"frame"}[-1]{"level1"} and return $accessor{$name} 1288 0 1288
Condition33%2/6
exists $accessor{$name} and !$level1_attr{$name} || $self->{"frame"}[-1]{"level1"}
!ll&&!rl&&r
001288
not $level1_attr{$name} or $self->{"frame"}[-1]{"level1"}
l!l&&r!l&&!r
128800
MC/DC0%0/3
exists $accessor{$name} and !$level1_attr{$name} || $self->{"frame"}[-1]{"level1"}
exists $accessor{$name} not $level1_attr{$name} $self->{"frame"}[-1]{"level1"}
Truth table25%1/4
A and not(B) or C
A= exists $accessor{$name}B= not $level1_attr{$name}C= $self->{"frame"}[-1]{"level1"}
ABCresult
0XX0
1000
11X1
1011
3818 $arg{query}
3819 0 ▶ or $self->wail("No such attribute as '$name'");
Branch: 1 branch
BranchTrueFalseTotal
$arg{"query"} or $self->wail("No such attribute as '${name}'") 0 0 0
3820 0 return;
3821 }
3822 }
3823  
3824 {
3825  
3826 20 my %spacetrack_attributes;
3827 $have_astro_spacetrack->()
3828 0 ▶ and %spacetrack_attributes = map { $_ => 1 }
Branch: 1 branch
BranchTrueFalseTotal
&$have_astro_spacetrack() and %spacetrack_attributes = map({$_, 1;} "Astro::SpaceTrack"->attribute_names) 0 20 20
3829 Astro::SpaceTrack->attribute_names();
3830  
3831 my %special = (
3832 2 ▶ formatter => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
3833 2 my ( $obj, $attr ) = @_;
3834 2 ▶ $obj->can( $attr )
Branch: 1 branch
BranchTrueFalseTotal
$obj->can($attr) or return bless( do{\(my $o = undef)}, 'Null' ) 2 0 2
3835 or return NULL;
3836 2 return $obj->$attr();
3837 },
3838 0 ▶ spacetrack => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3839 0 my ( $obj, $attr ) = @_;
3840 0 ▶ $spacetrack_attributes{$attr}
Branch: 1 branch
BranchTrueFalseTotal
$spacetrack_attributes{$attr} or return bless( do{\(my $o = undef)}, 'Null' ) 0 0 0
3841 or return NULL;
3842 0 return $obj->getv( $attr );
3843 },
3844 0 ▶ time_parser => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3845 0 my ( $obj, $attr ) = @_;
3846 0 ▶ $obj->can( $attr )
Branch: 1 branch
BranchTrueFalseTotal
$obj->can($attr) or return bless( do{\(my $o = undef)}, 'Null' ) 0 0 0
3847 or return NULL;
3848 0 return $obj->$attr();
3849 },
3850 20 );
3851  
3852 # my $value = $self->_attribute_value( $name );
3853 #
3854 # Return an attribute value. If the attribute is 'formatter',
3855 # 'spacetrack' or 'time_parser' you can specify a dot and the name
3856 # of an attribute of the relevant object, e.g. spacetrack.username.
3857 # If the attribute does not exist you get back manifest constant
3858 # NULL, which is a reference to undef blessed into class 'Null'.
3859 43 ▶ sub _attribute_value {
Subroutine _attribute_value: called CC=5 SCAR=16.4
3860 43 my ( $self, $name ) = @_;
3861 43 my ( $attr, $sub ) = split qr{ [.] }smx, $name, 2;
3862 43 ▶ $accessor{$attr}
Branch: 1 branch
BranchTrueFalseTotal
$accessor{$attr} or return bless( do{\(my $o = undef)}, 'Null' ) 9 34 43
3863 or return NULL;
3864 9 my $rslt = $self->get( $attr );
3865 9 ▶ if ( defined $sub ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sub) 2 7 9
3866 $rslt
3867 2 ▶ and my $code = $special{$attr}
Branch: 1 branch
BranchTrueFalseTotal
$rslt and my $code = $special{$attr} or return bless( do{\(my $o = undef)}, 'Null' ) 2 0 2
Condition33%1/3
$rslt and my $code = $special{$attr}
!ll&&!rl&&r
002
MC/DC0%0/2
$rslt and my $code = $special{$attr}
$rslt my $code = $special{$attr}
Truth table33%1/3
A and B
A= $rsltB= my $code = $special{$attr}
ABresult
0X0
100
111
3868 or return NULL;
3869 2 $rslt = $code->( $rslt, $sub );
3870 }
3871 9 return $rslt;
3872 }
3873 }
3874  
3875 # Documented in POD
3876  
3877 {
3878 20 my %chooser = (
3879 9 ▶ '' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
3880 9 my ( $sel ) = @_;
3881 9 my @rslt;
3882 9 foreach my $s ( split qr{ \s* , \s* }smx, $sel ) {
3883 9 ▶ if ( $s =~ m/ \D /smx || $s < 1000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ / \D /msx or $s < 1000) { } 5 4 9
Condition66%2/3
$s =~ / \D /msx or $s < 1000
l!l&&r!l&&!r
504
MC/DC50%1/2
$s =~ / \D /msx or $s < 1000
$s =~ / \D /msx $s < 1000
Truth table66%2/3
A or B
A= $s =~ / \D /msxB= $s < 1000
ABresult
1X1
011
000
3884 5 my $re = qr{\Q$s\E}i;
3885 8 ▶ push @rslt, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
3886 8 my ( $tle, $context ) = @_;
3887 8 ▶ $context->{name} ||= $tle->get( 'name' );
Condition100%3/3
$context->{"name"} ||= $tle->get("name")
l!l&&r!l&&!r
242
MC/DC100%2/2
$context->{"name"} ||= $tle->get("name")
$context->{"name"} $tle->get("name")
Truth table100%3/3
A ||= B
A= $context->{"name"}B= $tle->get("name")
ABresult
1X1
011
000
3888 defined $context->{name}
3889 8 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $context->{"name"} or return 6 2 8
3890 6 return $context->{name} =~ $re;
3891 5 };
3892 } else {
3893 8 ▶ push @rslt, sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
3894 8 my ( $tle, $context ) = @_;
3895 8 ▶ $context->{id} ||= $tle->get( 'id' );
Condition33%1/3
$context->{"id"} ||= $tle->get("id")
l!l&&r!l&&!r
080
MC/DC0%0/2
$context->{"id"} ||= $tle->get("id")
$context->{"id"} $tle->get("id")
Truth table33%1/3
A ||= B
A= $context->{"id"}B= $tle->get("id")
ABresult
1X1
011
000
3896 8 return $context->{id} == $s;
3897 4 };
3898 }
3899 }
3900 9 return @rslt;
3901 },
3902 0 ▶ CODE_REF() => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3903 0 my ( $sel ) = @_;
3904 0 return $sel;
3905 },
3906 0 ▶ REGEXP_REF() => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3907 0 my ( $sel ) = @_;
3908 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3909 0 my ( $tle, $context ) = @_;
3910 0 ▶ $context->{name} ||= $tle->get( 'name' );
Condition0%0/3
$context->{"name"} ||= $tle->get("name")
l!l&&r!l&&!r
000
MC/DC0%0/2
$context->{"name"} ||= $tle->get("name")
$context->{"name"} $tle->get("name")
Truth table0%0/3
A ||= B
A= $context->{"name"}B= $tle->get("name")
ABresult
1X1
011
000
3911 0 return $context->{name} =~ $sel;
3912 0 };
3913 },
3914 20 );
3915  
3916 47 ▶ sub __choose {
Subroutine __choose: called CC=17 SCAR=28.4
3917 47 my ( $self, @args ) = @_;
3918 47 ▶ my $opt = HASH_REF eq ref $args[0] ? shift @args : {};
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $args[0] ? : 9 38 47
3919 47 my $choice = shift @args;
3920 47 ▶ defined $choice
Branch: 1 branch
BranchTrueFalseTotal
defined $choice or $choice = [] 7 40 47
3921 or $choice = [];
3922 47 ▶ ARRAY_REF eq ref $choice
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $choice or $self->weep("Choice must be an ARRAY ref") 47 0 47
3923 or $self->weep( 'Choice must be an ARRAY ref' );
3924 47 my @rslt;
3925 my @selector;
3926 47 foreach my $sel ( @{ $choice } ) {
3927 9 my $ref = ref $sel;
3928 9 ▶ my $code = $chooser{$ref}
Branch: 1 branch
BranchTrueFalseTotal
my $code = $chooser{$ref} or $self->weep("$ref not supported as chooser") 9 0 9
3929 or $self->weep( "$ref not supported as chooser" );
3930 9 push @selector, $code->( $sel );
3931 }
3932  
3933 $opt->{bodies}
3934 and push @args,
3935 47 ▶ $self->_aggregate( $self->{bodies} );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"bodies"} and push @args, $self->_aggregate($self->{"bodies"}) 8 39 47
3936 $opt->{sky}
3937 47 ▶ and push @args, $self->{sky};
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"sky"} and push @args, $self->{"sky"} 6 41 47
3938  
3939 47 ▶ @args = map { ARRAY_REF eq ref $_ ? @{ $_ } : $_ } @args;
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $_ ? : 45 8 53
3940  
3941 not @selector
3942 47 ▶ and return wantarray ? @args : \@args;
Branch: 2 branches
BranchTrueFalseTotal
@selector or return wantarray ? @args : \@args 7 40 47
wantarray ? : 36 4 40
3943  
3944 7 foreach my $tle ( @args ) {
3945 14 ▶ ARRAY_REF eq ref $tle
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $tle and $self->weep("Schwartzian-transform objects not supported") 0 14 14
3946 and $self->weep( 'Schwartzian-transform objects not supported' );
3947  
3948 14 my $match = $opt->{invert};
3949 14 my $context = {};
3950 14 foreach my $sel ( @selector ) {
3951 16 ▶ $sel->( $tle, $context )
Branch: 1 branch
BranchTrueFalseTotal
&$sel($tle, $context) or next 8 8 16
3952 or next;
3953 8 $match = !$match;
3954 8 last;
3955 }
3956  
3957 14 ▶ $match and push @rslt, $tle;
Branch: 1 branch
BranchTrueFalseTotal
$match and push @rslt, $tle 8 6 14
3958 }
3959  
3960 7 ▶ return wantarray ? @rslt : \@rslt;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 3 7
3961 }
3962  
3963 }
3964  
3965 # $self->_deprecation_notice( $type, $name );
3966 #
3967 # This method centralizes deprecation. Type is 'attribute' or
3968 # 'method'. Deprecation is driven of the %deprecate hash. Values
3969 # are:
3970 # false - no warning
3971 # 1 - warn on first use
3972 # 2 - warn on each use
3973 # 3 - die on each use.
3974 #
3975 # $self->_deprecation_in_progress( $type, $name )
3976 #
3977 # This method returns true if the deprecation is in progress. In
3978 # fact it returns the deprecation level.
3979  
3980 {
3981  
3982 20 my %deprecate = (
3983 attribute => {
3984 country => 0,
3985 date_format => 0,
3986 desired_equinox_dynamical => 0,
3987 explicit_macro_delete => 0,
3988 gmt => 0,
3989 local_coord => 0,
3990 perltime => 0,
3991 time_format => 0,
3992 tz => 0,
3993 },
3994 method => {
3995 st => 0,
3996 },
3997 status => {
3998 iridium => 3,
3999 },
4000 );
4001  
4002 1285 ▶ sub _deprecation_notice {
Subroutine _deprecation_notice: called CC=8 SCAR=36.6
4003 1285 my ( $self, $type, $name, $repl ) = @_;
4004 1285 ▶ $deprecate{$type} or return;
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type} or return 1285 0 1285
4005 1285 ▶ $deprecate{$type}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type}{$name} or return 0 1285 1285
4006 my $msg = sprintf 'The %s %s is %s', $name, $type,
4007 0 ▶ $deprecate{$type}{$name} > 2 ? 'removed' : 'deprecated';
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type}{$name} > 2 ? : 0 0 0
4008 0 ▶ defined $repl
Branch: 1 branch
BranchTrueFalseTotal
defined $repl and $msg .= "; use $repl instead" 0 0 0
4009 and $msg .= "; use $repl instead";
4010 0 ▶ $deprecate{$type}{$name} >= 3
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type}{$name} >= 3 and $self->wail($msg) 0 0 0
4011 and $self->wail( $msg );
4012 0 ▶ warnings::enabled( 'deprecated' )
Branch: 1 branch
BranchTrueFalseTotal
warnings::enabled("deprecated") and $self->whinge($msg) 0 0 0
4013 and $self->whinge( $msg );
4014 $deprecate{$type}{$name} == 1
4015 0 ▶ and $deprecate{$type}{$name} = 0;
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type}{$name} == 1 and $deprecate{$type}{$name} = 0 0 0 0
4016 0 return;
4017 }
4018  
4019 0 ▶ sub _deprecation_in_progress {
Subroutine _deprecation_in_progress: not called CC=2 SCAR=17.9
4020 0 my ( undef, $type, $name ) = @_; # Invocant unused
4021 0 ▶ $deprecate{$type} or return;
Branch: 1 branch
BranchTrueFalseTotal
$deprecate{$type} or return 0 0 0
4022 0 return $deprecate{$type}{$name};
4023 }
4024  
4025 }
4026  
4027 # my ( $obj ) = $self->_drop_from_sky( $name );
4028 # The return is an array containing the dropped body, or nothing if the
4029 # body was not found.
4030 20 ▶sub _drop_from_sky {
Subroutine _drop_from_sky: called CC=2 SCAR=7.0
4031 1 my ( $self, $name ) = @_;
4032 1 ▶ defined( my $inx = $self->_find_in_sky( $name ) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $inx = $self->_find_in_sky($name)) or return 1 0 1
4033 or return;
4034 1 return splice @{ $self->{sky} }, $inx, 1;
4035 }
4036  
4037 # $fh = $self->_file_opener( $name, $mode );
4038 #
4039 # This method opens the given file, returning the handle. If the
4040 # mode is output, the current value of output_layers is appended.
4041 # An exception is thrown if the file can not be opened.
4042  
4043 1 ▶sub _file_opener {
Subroutine _file_opener: called CC=8 SCAR=25.2
4044 1 my ( $self, $name, $mode ) = @_;
4045  
4046 # NOTE special case for &1 (stdout) and &2 (stderr).
4047 my $fh = ( $name =~ m/ \A & ( [12] ) \z /smx ) ?
4048 [
4049 undef,
4050 1 ▶ $self->{frame}[-1]{localout} || \*STDOUT,
Branch: 2 branches
BranchTrueFalseTotal
my $fh = $name =~ / \A & ( [12] ) \z /msx ? [undef, $self->{"frame"}[-1]{"localout"} || \*STDOUT, \*STDERR]->[$1] : "IO::File"->new($name, $mode) or $self->wail("Unable to open ${name}: $!") 1 0 1
$name =~ / \A & ( [12] ) \z /msx ? : 0 1 1
Condition0%0/2
$self->{'frame'}[-1]{'localout'} || \*STDOUT
l!l
00
MC/DC0%0/1
$self->{'frame'}[-1]{'localout'} || \*STDOUT
$self->{'frame'}[-1]{'localout'}
Truth table0%0/2
A
A= $self->{'frame'}[-1]{'localout'}
Aresult
11
00
4051 \*STDERR,
4052 ]->[ $1 ] :
4053 IO::File->new( $name, $mode )
4054 or $self->wail( "Unable to open $name: $!" );
4055  
4056 1 ▶ if ( $mode =~ m/ \A (?: [+>] | [|] - ) /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ / \A (?: [+>] | [|] - ) /msx) 1 0 1
4057  
4058 1 my $layers = $self->get( 'output_layers' );
4059 1 ▶ if ( defined $layers && '' ne $layers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layers and "" ne $layers) 1 0 1
Condition33%1/3
defined $layers and "" ne $layers
!ll&&!rl&&r
001
MC/DC0%0/2
defined $layers and "" ne $layers
defined $layers "" ne $layers
Truth table33%1/3
A and B
A= defined $layersB= "" ne $layers
ABresult
0X0
100
111
4060 1 ▶ binmode $fh, $layers
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh, $layers or $self->wail("Unable to set '${layers}' on ${name}: $!") 1 0 1
4061 or $self->wail(
4062 "Unable to set '$layers' on $name: $!" );
4063 }
4064 }
4065  
4066 1 return $fh;
4067 }
4068  
4069 # $code = $self->_file_reader( $file, \%opt );
4070 #
4071 # This method returns a code snippet that returns the contents of
4072 # the file one line at a time. The $file can be any of:
4073 #
4074 # * An open handle
4075 # * A URL (if LWP::UserAgent can be loaded)
4076 # * A file name
4077 # * A scalar reference
4078 # * An array reference
4079 # * A code reference, which is returned unmodified
4080 #
4081 # The code snippet will return undef at end-of-file.
4082 #
4083 # The following keys in %opt are recognized:
4084 # {encoding} specifies the encoding of the file. How this is used
4085 # on the $file argument as follows:
4086 # * An open handle -- unused
4087 # * A URL ----------- unused (encoding taken from HTTP::Response)
4088 # * A file name ----- used (default is utf-8)
4089 # * A scalar ref ---- used (default is un-encoded)
4090 # * An array ref ---- unused
4091 # * A code ref ------ unused
4092 # {glob} causes the contents of the file to be returned, rather
4093 # than a reader.
4094 # {optional} causes the code to simply return on an error, rather
4095 # than failing.
4096  
4097 30 ▶sub _file_reader {
Subroutine _file_reader: called CC=4 SCAR=13.9
4098 30 my ( $self, $file, $opt ) = @_;
4099  
4100 30 ▶ if ( openhandle( $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($file)) 2 28 30
4101 $opt->{glob}
4102 2 ▶ or return sub { return scalar <$file> };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"glob"} or return sub { return scalar readline $file; } 1 1 2
4103 1 local $/ = undef;
4104 1 return scalar <$file>;
4105 }
4106  
4107 28 my $ref = ref $file;
4108 28 ▶ my $code = $self->can( "_file_reader_$ref" )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can("_file_reader_$ref") or $self->wail(sprintf("Opening a $ref ref is unsupported")) 28 0 28
4109 or $self->wail( sprintf "Opening a $ref ref is unsupported" );
4110  
4111 28 goto &$code;
4112 }
4113  
4114 # Most of the following are called using '$self->can(
4115 # "_file_reader_$ref" )', and there is no way a static analysis tool can
4116 # find such calls. So we just have to exempt them from Perl::Critic
4117  
4118 17 ▶sub _file_reader_ { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _file_reader_: called CC=13 SCAR=28.8
4119 17 my ( $self, $file, $opt ) = @_;
4120 17 ▶ $opt ||= {};
Condition100%2/2
$opt ||= {}
l!l
143
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
4121  
4122 17 ▶ defined $file
Branch: 1 branch
BranchTrueFalseTotal
defined $file and chomp $file 17 0 17
4123 and chomp $file;
4124  
4125 17 ▶ if ( ! defined $file || ! ref $file && '' eq $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $file or not ref $file and "" eq $file) 0 17 17
Condition33%2/6
not defined $file or not ref $file and "" eq $file
l!l&&r!l&&!r
0017
not ref $file and "" eq $file
!ll&&!rl&&r
0170
MC/DC0%0/3
not defined $file or not ref $file and "" eq $file
not defined $file not ref $file "" eq $file
Truth table25%1/4
not(A) or not(B) and C
A= not defined $fileB= not ref $fileC= "" eq $file
ABCresult
1XX1
0111
00X0
0100
4126 0 ▶ $opt->{optional} and return;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"optional"} and return 0 0 0
4127 0 $self->wail( 'Defined file required' );
4128 }
4129  
4130 17 ▶ if ( $self->_file_reader__validate_url( $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_file_reader__validate_url($file)) { } 2 15 17
4131 2 my $ua = LWP::UserAgent->new();
4132 2 my $resp = $ua->get( $file );
4133 $resp->is_success()
4134 2 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$resp->is_success or do { $opt->{"optional"} and return; $self->wail("Failed to retrieve ${file}: ", $resp->status_line) } 2 0 2
4135 0 ▶ $opt->{optional} and return;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"optional"} and return 0 0 0
4136 0 $self->wail( "Failed to retrieve $file: ",
4137 $resp->status_line() );
4138 };
4139 2 $opt = { %{ $opt }, encoding => $resp->content_charset() };
4140 2 return $self->_file_reader(
4141 \( scalar $resp->content() ),
4142 $opt,
4143 );
4144 } else {
4145 15 my $encoding = $self->_file_reader__encoding( $opt );
4146 open my $fh, "<$encoding", $self->expand_tilde( $file ) ## no critic (RequireBriefOpen)
4147 15 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$encoding", $self->expand_tilde($file) or do { $opt->{"optional"} and return; $self->wail("Failed to open ${file}: $!") } 11 4 15
4148 4 ▶ $opt->{optional} and return;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"optional"} and return 1 3 4
4149 3 $self->wail( "Failed to open $file: $!" );
4150 };
4151 $opt->{glob}
4152 11 ▶ or return sub { return scalar <$fh> };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"glob"} or return sub { return scalar readline $fh; } 7 4 11
4153 7 local $/ = undef;
4154 7 return scalar <$fh>;
4155 }
4156 }
4157  
4158 19 ▶sub _file_reader__encoding {
Subroutine _file_reader__encoding: called CC=3 SCAR=11.0
4159 19 my ( undef, $opt ) = @_;
4160 19 ▶ $opt ||= {};
Condition100%2/2
$opt ||= {}
l!l
181
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
4161 19 ▶ my $encoding = $opt->{encoding} || 'utf-8';
Condition100%2/2
$opt->{'encoding'} || 'utf-8'
l!l
217
MC/DC100%1/1
$opt->{'encoding'} || 'utf-8'
$opt->{'encoding'}
Truth table100%2/2
A
A= $opt->{'encoding'}
Aresult
11
00
4162 19 $encoding = ":encoding($encoding)";
4163 19 OS_IS_WINDOWS
4164 and substr $encoding, 0, 0, ':crlf';
4165 19 return $encoding;
4166 }
4167  
4168 17 ▶sub _file_reader__validate_url {
Subroutine _file_reader__validate_url: called CC=8 SCAR=21.6
4169 17 my ( undef, $url ) = @_; # Invocant unused
4170  
4171 17 ▶ load_package( 'LWP::UserAgent' )
Branch: 1 branch
BranchTrueFalseTotal
load_package("LWP::UserAgent") or return 17 0 17
4172 or return;
4173  
4174 17 ▶ load_package( 'URI' )
Branch: 1 branch
BranchTrueFalseTotal
load_package("URI") or return 17 0 17
4175 or return;
4176  
4177 17 ▶ load_package( 'LWP::Protocol' )
Branch: 1 branch
BranchTrueFalseTotal
load_package("LWP::Protocol") or return 17 0 17
4178 or return;
4179  
4180 17 ▶ my $obj = URI->new( $url )
Branch: 1 branch
BranchTrueFalseTotal
my $obj = "URI"->new($url) or return 17 0 17
4181 or return;
4182 17 ▶ $obj->can( 'authority' )
Branch: 1 branch
BranchTrueFalseTotal
$obj->can("authority") or return 1 17 0 17
4183 or return 1;
4184  
4185 17 ▶ defined( my $scheme = $obj->scheme() )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $scheme = $obj->scheme) or return 3 14 17
4186 or return;
4187 3 ▶ LWP::Protocol::implementor( $scheme )
Branch: 1 branch
BranchTrueFalseTotal
LWP::Protocol::implementor($scheme) or return 2 1 3
4188 or return;
4189  
4190 2 return 1;
4191 }
4192  
4193 5 ▶sub _file_reader_ARRAY { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _file_reader_ARRAY: called CC=4 SCAR=13.9
4194 5 my ( undef, $file, $opt ) = @_; # Invocant unused
4195  
4196 5 my $inx = 0;
4197 $opt->{glob}
4198 5 ▶ or return sub { return $file->[$inx++] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"glob"} or return sub { return $$file[$inx++]; } 1 4 5
4199 1 my $buffer;
4200 1 foreach ( @{ $file } ) {
4201 5 $buffer .= $_;
4202 5 ▶ $buffer =~ m/ \n \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \n \z /msx or $buffer .= "\n" 5 0 5
4203 or $buffer .= "\n";
4204 }
4205 1 return $buffer;
4206 }
4207  
4208 2 ▶sub _file_reader_CODE { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _file_reader_CODE: called CC=4 SCAR=13.9
4209 2 my ( undef, $file, $opt ) = @_; # Invocant unused
4210 $opt->{glob}
4211 2 ▶ or return $file;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"glob"} or return $file 1 1 2
4212 1 my $buffer;
4213 1 local $_;
4214 1 ▶ while ( defined( $_ = $file->() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = &$file())) 5 1 6
4215 5 $buffer .= $_;
4216 5 ▶ $buffer =~ m/ \n \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \n \z /msx or $buffer .= "\n" 5 0 5
4217 or $buffer .= "\n";
4218 }
4219 1 return $buffer;
4220 }
4221  
4222 4 ▶sub _file_reader_SCALAR { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _file_reader_SCALAR: called CC=4 SCAR=15.2
4223 4 my ( $self, $file, $opt ) = @_;
4224  
4225 4 my $encoding = $self->_file_reader__encoding( $opt );
4226 open my $fh, "<$encoding", $file ## no critic (RequireBriefOpen)
4227 4 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$encoding", $file or do { $opt->{"optional"} and return; $self->wail("Failed to open SCALAR reference: $!") } 4 0 4
4228 0 ▶ $opt->{optional} and return;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"optional"} and return 0 0 0
4229 0 $self->wail( "Failed to open SCALAR reference: $!" );
4230 };
4231 $opt->{glob}
4232 4 ▶ or return sub { return scalar <$fh> };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"glob"} or return sub { return scalar readline $fh; } 2 2 4
4233 2 local $/ = undef;
4234 2 return scalar <$fh>;
4235 }
4236  
4237 # $inx = $self->_find_in_sky( $name )
4238 # The return is the index of the named body in @{ $self->{sky} }, or
4239 # undef if it is not present. 'Sun' and 'Moon' are special cases;
4240 # everything else is presumed to be found by name.
4241 6 ▶sub _find_in_sky {
Subroutine _find_in_sky: called CC=3 SCAR=11.0
4242 6 my ( $self, $name ) = @_;
4243  
4244 6 my $re = qr/ \A \Q$name\E \z /smxi;
4245 6 foreach my $inx ( 0 .. $#{ $self->{sky} } ) {
4246 8 ▶ $self->{sky}[$inx]->get( 'name' ) =~ $re
Branch: 1 branch
BranchTrueFalseTotal
$self->{"sky"}[$inx]->get("name") =~ /$re/ and return $inx 1 7 8
4247 and return $inx;
4248 }
4249 5 return;
4250 }
4251  
4252 # Documented in POD
4253  
4254 41 ▶sub __format_data {
Subroutine __format_data: called CC=1 SCAR=0.0
4255 41 my ( $self, $action, $data, $opt ) = @_;
4256 41 return $self->_get_formatter_object( $opt )->format(
4257 sp => $self,
4258 template => $action,
4259 data => $data,
4260 opt => $opt,
4261 );
4262 }
4263  
4264 # $frames = $satpass2->_frame_push($type, \@args);
4265 #
4266 # This method pushes a context frame on the stack. The $type
4267 # describes the frame, and goes in the frame's {type} entry, but
4268 # is currently unused. The \@args entry goes in the {args} key,
4269 # and is the basis of argument expansion. The return is the number
4270 # of frames that were on the stack _BEFORE_ the now-current frame
4271 # was added to the stack. This gets passed to _frame_pop() to
4272 # restore the context stack to its status before the current frame
4273 # was added.
4274  
4275 59 ▶sub _frame_push {
Subroutine _frame_push: called CC=8 SCAR=20.8
4276 59 my ( $self, $type, $args, $opt ) = @_;
4277 59 ▶ $args ||= [];
Condition50%1/2
$args ||= []
l!l
590
MC/DC0%0/1
$args ||= []
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
4278 59 ▶ $opt ||= {};
Condition100%2/2
$opt ||= {}
l!l
2237
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
4279 59 ▶ my $frames = scalar @{$self->{frame} ||= []};
Condition100%2/2
$self->{"frame"} ||= []
l!l
527
MC/DC100%1/1
$self->{"frame"} ||= []
$self->{"frame"}
Truth table100%2/2
A
A= $self->{"frame"}
Aresult
11
00
4280 59 ▶ my $prior = $frames ? $self->{frame}[-1] : {
Branch: 1 branch
BranchTrueFalseTotal
$frames ? : 52 7 59
4281 condition => 1,
4282 stdout => select(),
4283 };
4284 my $condition = exists $opt->{condition} ?
4285 $opt->{condition} :
4286 59 ▶ $prior->{condition};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'condition'} ? : 22 37 59
4287 #### defined $stdout or $stdout = select();
4288 59 my ( undef, $filename, $line ) = caller;
4289 59 ▶ push @{$self->{frame}}, {
Condition83%5/6
$prior->{'localout'} || $prior->{'stdout'}
l!l&&r!l&&!r
01049
$prior->{'unsatisfied_if'} || !$condition
l!l&&r!l&&!r
31046
MC/DC50%1/2
$prior->{'localout'} || $prior->{'stdout'}
$prior->{'localout'} $prior->{'stdout'}
MC/DC100%2/2
$prior->{'unsatisfied_if'} || !$condition
$prior->{'unsatisfied_if'} !$condition
Truth table66%2/3
A || B
A= $prior->{'localout'}B= $prior->{'stdout'}
ABresult
1X1
011
000
Truth table100%3/3
A || not(B)
A= $prior->{'unsatisfied_if'}B= !$condition
ABresult
1X1
011
000
4290 type => $type,
4291 args => $args,
4292 condition => $condition,
4293 define => {}, # Macro defaults done with :=
4294 local => {},
4295 localout => undef, # Output for statement.
4296 macro => {},
4297 pushed_by => "$filename line $line",
4298 spacetrack => {},
4299 stdout => $prior->{localout} || $prior->{stdout},
4300 59 unsatisfied_if => $prior->{unsatisfied_if} || ! $condition,
4301 };
4302 59 return $frames;
4303 }
4304  
4305 # $satpass2->_frame_pop($frames);
4306 # $satpass2->_frame_pop($type => $frames);
4307 # $satpass2->_frame_pop();
4308 #
4309 # This method pops context frames off the stack until there are
4310 # $frames frames left. The optional $type argument is currently
4311 # unused, but was intended for type checking should that become
4312 # necessary. The zero-argument call pops one frame off the stack.
4313 # An exception is thrown if there are no frames left to pop. After
4314 # all required frames are popped, an exception is thrown if the
4315 # pop was done with a continued input line pending.
4316  
4317 {
4318  
4319 20 my %force_set; # If true, the named attribute is set with the
4320 # set() method even if a hash key of the same
4321 # name exists. This is set with
4322 # _frame_pop_force_set(), typically where the
4323 # mutator is defined.
4324  
4325 53 ▶ sub _frame_pop {
Subroutine _frame_pop: called CC=16 SCAR=28.7
4326 53 my ($self, @args) = @_;
4327 ## my $type = @args > 1 ? shift @args : undef;
4328 53 ▶ @args > 1 and shift @args; # Currently unused
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 and shift @args 22 31 53
4329 my $frames = ( @args && defined $args[0] ) ?
4330 shift @args :
4331 53 ▶ @{$self->{frame}} - 1;
Branch: 1 branch
BranchTrueFalseTotal
@args && defined $args[0] ? : 26 27 53
Condition100%3/3
@args and defined $args[0]
!ll&&!rl&&r
52226
MC/DC100%2/2
@args and defined $args[0]
@args defined $args[0]
Truth table100%3/3
A and B
A= @argsB= defined $args[0]
ABresult
0X0
100
111
4332 53 ▶ while (@{$self->{frame}} > $frames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"frame"};} > $frames) 52 53 105
4333 52 ▶ my $frame = pop @{$self->{frame}}
Branch: 1 branch
BranchTrueFalseTotal
my $frame = pop @{$$self{"frame"};} or $self->weep("No frame to pop") 52 0 52
4334 or $self->weep( 'No frame to pop' );
4335 52 ▶ my $local = $frame->{local} || {};
Condition50%1/2
$frame->{'local'} || {}
l!l
520
MC/DC0%0/1
$frame->{'local'} || {}
$frame->{'local'}
Truth table50%1/2
A
A= $frame->{'local'}
Aresult
11
00
4336 52 foreach my $name ( keys %{ $local } ) {
4337 2 my $value = $local->{$name};
4338 2 ▶ if ( exists $self->{$name} && !$force_set{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$name} and not $force_set{$name}) { } 1 1 2
Condition66%2/3
exists $self->{$name} and not $force_set{$name}
!ll&&!rl&&r
011
MC/DC50%1/2
exists $self->{$name} and not $force_set{$name}
exists $self->{$name} not $force_set{$name}
Truth table66%2/3
A and not(B)
A= exists $self->{$name}B= not $force_set{$name}
ABresult
0X0
100
111
4339 1 $self->{$name} = $value;
4340 } else {
4341 1 $self->set( $name, $value );
4342 }
4343 }
4344 52 foreach my $key (qw{macro}) {
4345 52 ▶ my $info = $frame->{$key} || {};
Condition50%1/2
$frame->{$key} || {}
l!l
520
MC/DC0%0/1
$frame->{$key} || {}
$frame->{$key}
Truth table50%1/2
A
A= $frame->{$key}
Aresult
11
00
4346 52 foreach my $name ( keys %{ $info } ) {
4347 19 $self->{$key}{$name} = $info->{ $name };
4348 }
4349 }
4350 52 ($frame->{spacetrack} && %{$frame->{spacetrack}})
4351 0 ▶ and $self->_get_spacetrack()->set(%{$frame->{spacetrack}});
Branch: 1 branch
BranchTrueFalseTotal
$frame->{"spacetrack"} and %{$frame->{"spacetrack"};} and $self->_get_spacetrack->set(%{$$frame{"spacetrack"};}) 0 52 52
Condition33%1/3
$frame->{"spacetrack"} and %{$frame->{"spacetrack"};}
!ll&&!rl&&r
0520
MC/DC0%0/2
$frame->{"spacetrack"} and %{$frame->{"spacetrack"};}
$frame->{"spacetrack"} %{$frame->{"spacetrack"};}
Truth table33%1/3
A and B
A= $frame->{"spacetrack"}B= %{$frame->{"spacetrack"};}
ABresult
0X0
100
111
4352 }
4353 53 ▶ if (delete $self->{pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"pending"}) 0 53 53
4354 0 $self->wail('Input ended on continued line');
4355 }
4356 53 return;
4357 }
4358  
4359 # Force use of the set() method even if there is an attribute of the
4360 # same name.
4361 20 ▶ sub _frame_pop_force_set {
Subroutine _frame_pop_force_set: called CC=2 SCAR=6.9
4362 20 foreach my $name ( @_ ) {
4363 20 $force_set{$name} = 1;
4364 }
4365 20 return;
4366 }
4367 }
4368  
4369 20 ▶sub _get_browser_command {
Subroutine _get_browser_command: not called CC=5 SCAR=32.4
4370 0 my ( $self, $val ) = @_;
4371 defined $val
4372 0 ▶ or $val = $self->{webcmd};
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $val = $self->{"webcmd"} 0 0 0
4373 0 ▶ defined $val
Branch: 1 branch
BranchTrueFalseTotal
defined $val and "" ne $val or return $val 0 0 0
Condition0%0/3
defined $val and "" ne $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and "" ne $val
defined $val "" ne $val
Truth table0%0/3
A and B
A= defined $valB= "" ne $val
ABresult
0X0
100
111
4374 and '' ne $val
4375 or return $val;
4376 0 ▶ '1' eq $val
Branch: 1 branch
BranchTrueFalseTotal
1 eq $val or return $val 0 0 0
4377 or return $val;
4378 0 require Browser::Open;
4379 0 return Browser::Open::open_browser_cmd();
4380 }
4381  
4382 # $dumper = $self->_get_dumper();
4383 #
4384 # This method returns a reference to code that can be used to dump
4385 # data. The first time it is called it goes through a list of
4386 # possible classes, and uses the first one it can load, dying if
4387 # it can not load any of them. After the first successful call, it
4388 # simply returns the cached dumper.
4389  
4390 {
4391 20 my $dumper;
4392 my %kode = (
4393 0 ▶ 'Data::Dumper' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
4394 0 local $Data::Dumper::Terse = 1;
4395 0 Data::Dumper::Dumper(@_);
4396 },
4397 20 );
4398 0 ▶ sub _get_dumper {
Subroutine _get_dumper: not called CC=4 SCAR=30.0
4399 0 my ($self) = @_;
4400 0 my %dmpr;
4401 my @mod;
4402 0 ▶ return $dumper ||= do {
Condition0%0/3
$dumper ||= do { foreach $_ ("YAML::Dump", "Data::Dumper::Dumper") { () = / (.*) :: (.*) /msx; push @mod, $module; $dmpr{$module} = $routine; } ; my $mod = $self->_load_module(@mod); $kode{$mod} or $mod->can($dmpr{$mod}) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$dumper ||= do { foreach $_ ("YAML::Dump", "Data::Dumper::Dumper") { () = / (.*) :: (.*) /msx; push @mod, $module; $dmpr{$module} = $routine; } ; my $mod = $self->_load_module(@mod); $kode{$mod} or $mod->can($dmpr{$mod}) }
$dumper do { foreach $_ ("YAML::Dump", "Data::Dumper::Dumper") { () = / (.*) :: (.*) /msx; push @mod, $module; $dmpr{$module} = $routine; } ; my $mod = $self->_load_module(@mod); $kode{$mod} or $mod->can($dmpr{$mod}) }
Truth table0%0/3
A ||= B
A= $dumperB= do { foreach $_ ("YAML::Dump", "Data::Dumper::Dumper") { () = / (.*) :: (.*) /msx; push @mod, $module; $dmpr{$module} = $routine; } ; my $mod = $self->_load_module(@mod); $kode{$mod} or $mod->can($dmpr{$mod}) }
ABresult
1X1
011
000
4403 0 foreach (qw{YAML::Dump Data::Dumper::Dumper}) {
4404 0 my ($module, $routine) = m/ (.*) :: (.*) /smx;
4405 0 push @mod, $module;
4406 0 $dmpr{$module} = $routine;
4407 }
4408 0 my $mod = $self->_load_module(@mod);
4409 0 ▶ $kode{$mod} || $mod->can($dmpr{$mod});
Condition0%0/3
$kode{$mod} || $mod->can($dmpr{$mod})
l!l&&r!l&&!r
000
MC/DC0%0/2
$kode{$mod} || $mod->can($dmpr{$mod})
$kode{$mod} $mod->can($dmpr{$mod})
Truth table0%0/3
A || B
A= $kode{$mod}B= $mod->can($dmpr{$mod})
ABresult
1X1
011
000
4410 };
4411 }
4412 }
4413  
4414 # $fmt = $satpass2->_get_dumper_object();
4415 #
4416 # Gets a dumper object. This object must conform to the
4417 # Astro::App::Satpass2::Format interface.
4418  
4419 {
4420  
4421 20 my $dumper;
4422  
4423 0 ▶ sub _get_dumper_object {
Subroutine _get_dumper_object: not called CC=2 SCAR=17.9
4424 0 ▶ return ( $dumper ||= do {
Condition0%0/3
$dumper ||= do { require Astro::App::Satpass2::Format::Dump; "Astro::App::Satpass2::Format::Dump"->new }
l!l&&r!l&&!r
000
MC/DC0%0/2
$dumper ||= do { require Astro::App::Satpass2::Format::Dump; "Astro::App::Satpass2::Format::Dump"->new }
$dumper do { require Astro::App::Satpass2::Format::Dump; "Astro::App::Satpass2::Format::Dump"->new }
Truth table0%0/3
A ||= B
A= $dumperB= do { require Astro::App::Satpass2::Format::Dump; "Astro::App::Satpass2::Format::Dump"->new }
ABresult
1X1
011
000
4425 0 require Astro::App::Satpass2::Format::Dump;
4426 0 Astro::App::Satpass2::Format::Dump->new();
4427 }
4428 );
4429 }
4430  
4431 }
4432  
4433 # $fmt = $satpass2->_get_formatter_object( $opt );
4434 #
4435 # Gets the Astro::App::Satpass2::Format object. If $opt->{dump} is true,
4436 # returns a dumper object; otherwise returns the currently-set
4437 # formatter object.
4438  
4439 20 ▶sub _get_formatter_object {
Subroutine _get_formatter_object: called CC=4 SCAR=15.6
4440 41 my ( $self, $opt ) = @_;
4441 41 ▶ $opt ||= {};
Condition50%1/2
$opt ||= {}
l!l
410
MC/DC0%0/1
$opt ||= {}
$opt
Truth table50%1/2
A
A= $opt
Aresult
11
00
4442 41 ▶ return ( $opt && $opt->{dump} ) ? $self->_get_dumper_object() :
Branch: 1 branch
BranchTrueFalseTotal
$opt && $opt->{'dump'} ? : 0 41 41
Condition33%1/3
$opt and $opt->{"dump"}
!ll&&!rl&&r
0410
MC/DC0%0/2
$opt and $opt->{"dump"}
$opt $opt->{"dump"}
Truth table33%1/3
A and B
A= $optB= $opt->{"dump"}
ABresult
0X0
100
111
4443 $self->get( 'formatter' );
4444 }
4445  
4446 0 ▶sub _get_formatter_attribute {
Subroutine _get_formatter_attribute: not called CC=1 SCAR=6.9
4447 0 my ( $self, $name ) = @_;
4448 0 return $self->get( 'formatter' )->$name();
4449 }
4450  
4451 # $st = $satpass2->_get_geocoder()
4452  
4453 # Gets the geocoder object, instantiating it if
4454 # necesary.
4455  
4456 0 ▶sub _get_geocoder {
Subroutine _get_geocoder: not called CC=3 SCAR=24.8
4457 0 my ( $self ) = @_;
4458 0 ▶ if ( ! exists $self->{geocoder} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"geocoder"}) 0 0 0
4459 0 my ( $class, $obj );
4460 0 ▶ $class = $default_geocoder->()
Branch: 1 branch
BranchTrueFalseTotal
$class = &$default_geocoder() and $obj = $class->new 0 0 0
4461 and $obj = $class->new();
4462 0 $self->{geocoder} = $obj;
4463 }
4464 0 return $self->{geocoder};
4465 }
4466  
4467 # $boolean = $satpass2->_get_interactive();
4468 #
4469 # This method returns true if the script is running interactively,
4470 # and false otherwise. Currently, it returns the results of -t
4471 # STDIN.
4472  
4473 0 ▶sub _get_interactive {
Subroutine _get_interactive: not called CC=1 SCAR=6.9
4474 0 return -t STDIN;
4475 }
4476  
4477 # $code = $satpass2->_get_readline();
4478 #
4479 # Returns code to read input. The code takes an argument which
4480 # will be used as a prompt if one is needed. What is actually
4481 # returned is:
4482 #
4483 # If $satpass2->_get_interactive() is false, the returned code
4484 # just reads standard in. Otherwise,
4485 #
4486 # if Term::ReadLine can be loaded, a Term::ReadLine object is
4487 # instantiated if need be, and the returned code calls
4488 # Term::ReadLine->readline($_[0]) and returns whatever that gives
4489 # you. Otherwise,
4490 #
4491 # Otherwise the returned code writes its argument to STDERR and
4492 # reads STDIN.
4493 #
4494 # Note that the return from this subroutine may or may not be
4495 # chomped.
4496  
4497 20 my $readline_word_break_re = DEFAULT_COMPLETER_WORD_BREAK_CHARACTERS;
4498  
4499 {
4500 20 my $rl;
4501  
4502 0 ▶ sub _get_readline {
Subroutine _get_readline: not called CC=6 SCAR=35.5
4503 0 my ($self) = @_;
4504 # The Perl::Critic recommendation is IO::Interactive, but that
4505 # fiddles with STDOUT. We want STDIN, because we want to behave
4506 # differently if STDIN is a pipe, but not if STDOUT is a pipe.
4507 # We're still missing the *ARGV logic, but that's OK too, since
4508 # we use the contents of @ARGV as commands, not as file names.
4509 0 return do {
4510 0 my $buffer = '';
4511 0 ▶ if ($self->_get_interactive()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_get_interactive) { } 0 0 0
4512 eval {
4513 0 ▶ load_package( 'Term::ReadLine' )
Branch: 1 branch
BranchTrueFalseTotal
load_package("Term::ReadLine") or return 0 0 0
4514 or return;
4515 0 ▶ unless ( $rl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rl) 0 0 0
4516 0 $rl = Term::ReadLine->new( 'satpass2' );
4517 0 ▶ if ( 'Term::ReadLine::Perl' eq $rl->ReadLine() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Term::ReadLine::Perl" eq $rl->ReadLine) 0 0 0
4518  
4519 0 $readline_word_break_re = qr<
4520 [\Q$readline::rl_completer_word_break_characters\E]+
4521 >smx;
4522  
4523 20 ▶ no warnings qw{ once };
Subroutine BEGIN: called CC=1 SCAR=0.0
4524 0 ▶ $readline::rl_completion_function = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
4525 0 my ( $text, $line, $start ) = @_;
4526 0 return $self->__readline_completer(
4527 $text, $line, $start );
4528 0 };
4529 }
4530 }
4531 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
4532 0 ▶ defined $buffer or return $buffer;
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or return $buffer 0 0 0
4533 0 return ( $buffer = $rl->readline($_[0]) );
4534 }
4535 0 ▶ } || sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
4536 0 ▶ defined $buffer or return $buffer;
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or return $buffer 0 0 0
4537 0 print STDERR $_[0];
4538 return (
4539 0 $buffer = <STDIN> ## no critic (ProhibitExplicitStdin)
4540 );
4541 0 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { load_package("Term::ReadLine") or return; unless ($rl) { $rl = "Term::ReadLine"->new("satpass2"); if ("Term::ReadLine::Perl" eq $rl->ReadLine) { $readline_word_break_re = qr/ [\Q$readline::rl_completer_word_break_characters\E]+ /msx; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x45\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} $readline::rl_completion_function = sub { my($text, $line, $start) = @_; return $self->__readline_completer($text, $line, $start); } ; } ; } ; sub { defined $buffer or return $buffer; return $buffer = $rl->readline($_[0]); } } } or sub { defined $buffer or return $buffer; print STDERR $_[0]; return $buffer = readline STDIN; } 0 0 0
4542 } else {
4543 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
4544 0 ▶ defined $buffer or return $buffer;
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or return $buffer 0 0 0
4545 return (
4546 0 $buffer = <STDIN> ## no critic (ProhibitExplicitStdin)
4547 );
4548 0 };
4549 }
4550 };
4551 }
4552 }
4553  
4554 20 ▶sub __readline_completer {
Subroutine __readline_completer: called CC=22 SCAR=43.5
4555 38 my ( $app, $text, $line, $start ) = @_;
4556  
4557  
4558 38 ▶ $start
Branch: 1 branch
BranchTrueFalseTotal
$start or return $app->_readline_complete_command($text) 30 8 38
4559 or return $app->_readline_complete_command( $text );
4560  
4561 30 my ( $cmd ) = split $readline_word_break_re, $line, 2;
4562 30 my $code;
4563 not $cmd =~ s/ \A core [.] //smx
4564 and ref $app
4565 and $app->{macro}{$cmd}
4566 30 ▶ and $code = $app->{macro}{$cmd}->implements( $cmd );
Branch: 1 branch
BranchTrueFalseTotal
not $cmd =~ s/ \A core [.] //msx and ref $app and $app->{"macro"}{$cmd} and $code = $app->{"macro"}{$cmd}->implements($cmd) 3 27 30
Condition83%5/6
not $cmd =~ s/ \A core [.] //msx and ref $app and $app->{"macro"}{$cmd}
!ll&&!rl&&r
5223
not $cmd =~ s/ \A core [.] //msx and ref $app
!ll&&!rl&&r
5025
MC/DC66%2/3
not $cmd =~ s/ \A core [.] //msx and ref $app and $app->{"macro"}{$cmd}
not $cmd =~ s/ \A core [.] //msx ref $app $app->{"macro"}{$cmd}
Truth table75%3/4
not(A) and B and C
A= not $cmd =~ s/ \A core [.] //msxB= ref $appC= $app->{"macro"}{$cmd}
ABCresult
0XX0
10X0
1100
1111
4567 30 ▶ $code ||= $app->can( $cmd );
Condition66%2/3
$code ||= $app->can($cmd)
l!l&&r!l&&!r
3270
MC/DC0%0/2
$code ||= $app->can($cmd)
$code $app->can($cmd)
Truth table66%2/3
A ||= B
A= $codeB= $app->can($cmd)
ABresult
1X1
011
000
4568  
4569 30 ▶ if ( CODE_REF eq ref $code ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('CODE' eq ref $code) { } 27 3 30
elsif (my $macro = $app->{'macro'}{$cmd}) { } 3 0 3
4570 # builtins and code macros go here
4571  
4572 27 my $rslt;
4573  
4574 27 ▶ if ( my $method = $app->__get_attr( $code, Tweak => {}
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $app->__get_attr($code, "Tweak", {})->{"completion"}) 25 2 27
4575 )->{completion} ) {
4576 $rslt = $app->$method( $code, $text, $line, $start )
4577 25 ▶ and return @{ $rslt };
Branch: 1 branch
BranchTrueFalseTotal
$rslt = $app->$method($code, $text, $line, $start) and return @{$rslt;} 25 0 25
4578 }
4579  
4580 $rslt = $app->_readline_complete_options( $code, $text,
4581 $line, $start )
4582 2 and @{ $rslt }
4583 2 ▶ and return @{ $rslt };
Branch: 1 branch
BranchTrueFalseTotal
$rslt = $app->_readline_complete_options($code, $text, $line, $start) and @{$rslt;} and return @{$rslt;} 2 0 2
Condition33%1/3
$rslt = $app->_readline_complete_options($code, $text, $line, $start) and @{$rslt;}
!ll&&!rl&&r
002
MC/DC0%0/2
$rslt = $app->_readline_complete_options($code, $text, $line, $start) and @{$rslt;}
$rslt = $app->_readline_complete_options($code, $text, $line, $start) @{$rslt;}
Truth table33%1/3
A and B
A= $rslt = $app->_readline_complete_options($code, $text, $line, $start)B= @{$rslt;}
ABresult
0X0
100
111
4584  
4585 } elsif ( my $macro = $app->{macro}{$cmd} ) {
4586 # command macros go here
4587  
4588 3 my $rslt;
4589 $rslt = $macro->completion( $text )
4590 3 ▶ and return @{ $rslt };
Branch: 1 branch
BranchTrueFalseTotal
$rslt = $macro->completion($text) and return @{$rslt;} 3 0 3
4591 }
4592  
4593 0 my @files = bsd_glob( "$text*" );
4594 0 ▶ if ( 1 == @files ) {
Branch: 2 branches
BranchTrueFalseTotal
if (1 == @files) { } 0 0 0
elsif ($readline::var_CompleteAddsuffix) { } 0 0 0
4595 0 ▶ $files[0] .= -d $files[0] ? '/' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
-d $files[0] ? : 0 0 0
4596 } elsif ( $readline::var_CompleteAddsuffix ) {
4597 0 foreach ( @files ) {
4598 0 ▶ if ( -l $_ ) {
Branch: 4 branches
BranchTrueFalseTotal
if (-l $_) { } 0 0 0
elsif (-d $_) { } 0 0 0
elsif (-x _) { } 0 0 0
elsif (-S _ or -p _) { } 0 0 0
4599 0 $_ .= '@';
4600 } elsif ( -d $_ ) {
4601 0 $_ .= '/';
4602 } elsif ( -x _) {
4603 0 $_ .= '*';
4604 ▶ } elsif ( -S _ || -p _ ) {
Condition0%0/3
-S _ or -p _
l!l&&r!l&&!r
000
MC/DC0%0/2
-S _ or -p _
-S _ -p _
Truth table0%0/3
A or B
A= -S _B= -p _
ABresult
1X1
011
000
4605 0 $_ .= '=';
4606 }
4607 }
4608 }
4609 0 $readline::rl_completer_terminator_character = '';
4610 0 return @files;
4611 }
4612  
4613 {
4614 20 my @builtins;
4615 8 ▶ sub _readline_complete_command {
Subroutine _readline_complete_command: called CC=11 SCAR=24.1
4616 8 my ( $app, $text ) = @_;
4617 8 ▶ unless ( @builtins ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@builtins) 1 7 8
4618 1 ▶ my $stash = ( ref $app || $app ) . '::';
Condition33%1/3
ref $app || $app
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $app || $app
ref $app $app
Truth table33%1/3
A || B
A= ref $appB= $app
ABresult
1X1
011
000
4619 20 ▶ no strict qw{ refs };
Subroutine BEGIN: called CC=1 SCAR=0.0
4620 1 foreach my $sym ( keys %$stash ) {
4621 416 ▶ $sym =~ m/ \A _ /smx
Branch: 1 branch
BranchTrueFalseTotal
$sym =~ / \A _ /msx and next 161 255 416
4622 and next;
4623 255 ▶ my $code = $app->can( $sym )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $app->can($sym) or next 237 18 255
4624 or next;
4625 237 ▶ $app->__get_attr( $code, 'Verb' )
Branch: 1 branch
BranchTrueFalseTotal
$app->__get_attr($code, "Verb") or next 50 187 237
4626 or next;
4627 50 push @builtins, $sym;
4628 }
4629 1 @builtins = sort @builtins;
4630 }
4631 8 my @rslt;
4632 8 ▶ if ( $text =~ s/ \A core [.] //smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/ \A core [.] //msx) { } 2 6 8
4633 2 my $match = qr< \A \Q$text\E >smx;
4634 2 @rslt = map { "core.$_" } grep { $_ =~ $match } @builtins;
4635 } else {
4636 6 my $match = qr< \A \Q$text\E >smx;
4637 321 ▶ @rslt = grep { $_ =~ $match } @builtins, 'core.',
Branch: 1 branch
BranchTrueFalseTotal
ref $app ? : 6 0 6
4638 6 ref $app ? keys %{ $app->{macro} } : ();
4639 }
4640 8 ▶ 1 == @rslt
Branch: 1 branch
BranchTrueFalseTotal
1 == @rslt and $rslt[0] =~ / \W \z /msx and $readline::rl_completer_terminator_character = "" 0 8 8
Condition66%2/3
1 == @rslt and $rslt[0] =~ / \W \z /msx
!ll&&!rl&&r
710
MC/DC0%0/2
1 == @rslt and $rslt[0] =~ / \W \z /msx
1 == @rslt $rslt[0] =~ / \W \z /msx
Truth table66%2/3
A and B
A= 1 == @rsltB= $rslt[0] =~ / \W \z /msx
ABresult
0X0
100
111
4641 and $rslt[0] =~ m/ \W \z /smx
4642 and $readline::rl_completer_terminator_character = '';
4643 8 return ( sort @rslt );
4644 }
4645 }
4646  
4647 20 ▶sub _readline_complete_options {
Subroutine _readline_complete_options: called CC=5 SCAR=16.2
4648 # my ( $app, $code, $text, $line, $start ) = @_;
4649 13 my ( $app, $code, $text ) = @_;
4650 13 ▶ $text =~ m/ \A ( --? ) ( .* ) /smx
Branch: 1 branch
BranchTrueFalseTotal
$text =~ / \A ( --? ) ( .* ) /msx or return 9 4 13
4651 or return;
4652 9 my ( $prefix, $match ) = ( $1, $2 );
4653 9 my $lgl = $app->__legal_options( $code );
4654 9 my $re = qr< \A \Q$match\E >smx;
4655 9 my @rslt;
4656 9 foreach ( @{ $lgl } ) {
4657 26 ▶ next if ref;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 26 26
4658 # De-alias before modifying
4659 26 ( my $o = $_ ) =~ s/ [!=?] .* //smx;
4660 26 push @rslt, grep { m/$re/ } split qr< \| >smx, $o;
4661 }
4662 @rslt
4663 9 ▶ and return [ map { "$prefix$_" } sort @rslt ];
Branch: 1 branch
BranchTrueFalseTotal
@rslt and return [map({"$prefix$_";} sort(@rslt))] 9 0 9
4664 0 return;
4665 }
4666  
4667 # The following subroutine is called dynamically
4668 25 ▶sub _readline_complete_subcommand { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _readline_complete_subcommand: called CC=10 SCAR=23.4
4669 # my ( $app, $code, $text, $line, $start ) = @_;
4670 25 my ( $app, undef, $text, $line, $start ) = @_;
4671 25 my @part = _readline_line_to_parts( $line );
4672 25 ▶ if ( my $code = $app->can( "_$part[0]_sub" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $app->can("_$part[0]_sub")) 6 19 25
4673 6 return $code->( $app, $text, $line, $start, @part );
4674 }
4675 19 my @rslt;
4676 19 ▶ if ( 2 == @part ) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 == @part) 10 9 19
4677 10 my $re = qr< \A _$part[0]_sub_ ( \Q$part[1]\E \w* ) >smx;
4678 10 ▶ my $stash = ( ref $app || $app ) . '::';
Condition33%1/3
ref $app || $app
l!l&&r!l&&!r
1000
MC/DC0%0/2
ref $app || $app
ref $app $app
Truth table33%1/3
A || B
A= ref $appB= $app
ABresult
1X1
011
000
4679 20 ▶ no strict qw{ refs };
Subroutine BEGIN: called CC=1 SCAR=0.0
4680 10 foreach my $key ( keys %$stash ) {
4681 4194 ▶ $key =~ m/$re/smx
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /$re/msx and push @rslt, "$1" 30 4164 4194
4682 and push @rslt, "$1";
4683 }
4684 10 return [ sort @rslt ];
4685 }
4686  
4687 9 ▶ my $code = $app->can( "_$part[0]_sub_$part[1]" )
Branch: 1 branch
BranchTrueFalseTotal
my $code = $app->can("_$part[0]_sub_$part[1]") or return 9 0 9
4688 or return;
4689  
4690 9 my $r;
4691 9 ▶ $r = $app->_readline_complete_options( $code, $text, $line,
Branch: 1 branch
BranchTrueFalseTotal
$r = $app->_readline_complete_options($code, $text, $line, $start) and return $r 6 3 9
4692 $start )
4693 and return $r;
4694  
4695 my $complete = $app->__get_attr( $code, Tweak => {} )->{completion}
4696 3 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $complete = $app->__get_attr($code, "Tweak", {})->{"completion"} or return 3 0 3
4697  
4698 3 ▶ $r = $app->$complete( $code, $text, $line, $start )
Branch: 1 branch
BranchTrueFalseTotal
$r = $app->$complete($code, $text, $line, $start) and return $r 3 0 3
4699 and return $r;
4700  
4701 0 return;
4702 }
4703  
4704 3 ▶sub _macro_list_complete { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _macro_list_complete: called CC=5 SCAR=16.2
4705 # my ( $app, $code, $text, $line, $start ) = @_;
4706 3 my ( $app, undef, undef, $line, undef ) = @_;
4707 3 ▶ ref $app
Branch: 1 branch
BranchTrueFalseTotal
ref $app or return 3 0 3
4708 or return;
4709 3 my @part = _readline_line_to_parts( $line );
4710 3 ▶ 3 == @part
Branch: 1 branch
BranchTrueFalseTotal
3 == @part or return 3 0 3
4711 or return;
4712 3 my $re = qr< \A \Q$part[2]\E >smx;
4713 3 my @rslt;
4714 3 foreach ( sort keys %{ $app->{macro} } ) {
4715 9 ▶ m/$re/smx
Branch: 1 branch
BranchTrueFalseTotal
/$re/msx and push @rslt, $_ 4 5 9
4716 and push @rslt, $_;
4717 }
4718 3 return \@rslt;
4719 }
4720  
4721 0 ▶sub _sky_body_complete { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _sky_body_complete: not called CC=6 SCAR=37.4
4722 # my ( $app, $code, $text, $line, $start ) = @_;
4723 0 my ( $app, undef, undef, $line, undef ) = @_;
4724 0 ▶ ref $app
Branch: 1 branch
BranchTrueFalseTotal
ref $app or return 0 0 0
4725 or return;
4726 0 my @part = _readline_line_to_parts( $line );
4727 0 ▶ 3 == @part
Branch: 1 branch
BranchTrueFalseTotal
3 == @part or return 0 0 0
4728 or return;
4729 0 my $re = qr< \A \Q$part[2]\E >smxi;
4730 0 my @rslt;
4731 0 foreach my $body ( @{ $app->{sky} } ) {
4732 0 ▶ if ( ( my $name = $body->get( 'name' ) ) =~ $re ) {
Branch: 2 branches
BranchTrueFalseTotal
if ((my $name = $body->get('name')) =~ /$re/) { } 0 0 0
elsif ((my $id = $body->get('id')) =~ /$re/) { } 0 0 0
4733 0 push @rslt, $name;
4734 } elsif ( ( my $id = $body->get( 'id' ) ) =~ $re ) {
4735 0 push @rslt, $id;
4736 }
4737 }
4738 0 return [ sort @rslt ];
4739 }
4740  
4741 28 ▶sub _readline_line_to_parts {
Subroutine _readline_line_to_parts: called CC=2 SCAR=7.0
4742 28 my ( $line ) = @_;
4743 # NOTE that the field count of -1 causes a trailing separator to
4744 # result in a trailing empty field.
4745 28 my @parts = split $readline_word_break_re, $line, -1;
4746 # NOTE that we strip the leading 'core.' if any, so the return from
4747 # this method does not distinguish between a core command and the
4748 # same-named macro if any.
4749 @parts
4750 28 ▶ and $parts[0] =~ s/ \A core [.] //smx;
Branch: 1 branch
BranchTrueFalseTotal
@parts and $parts[0] =~ s/ \A core [.] //msx 28 0 28
4751 28 return @parts;
4752 }
4753  
4754 0 ▶sub _get_time_parser_attribute {
Subroutine _get_time_parser_attribute: not called CC=1 SCAR=6.9
4755 0 my ( $self, $name ) = @_;
4756 0 return $self->{time_parser}->$name();
4757 }
4758  
4759 # $st = $satpass2->_get_spacetrack()
4760  
4761 # Gets the Astro::SpaceTrack object, instantiating it if
4762 # necesary.
4763  
4764 7 ▶sub _get_spacetrack {
Subroutine _get_spacetrack: called CC=2 SCAR=7.1
4765 7 my ( $self ) = @_;
4766 exists $self->{spacetrack}
4767 7 ▶ or $self->{spacetrack} = $self->_get_spacetrack_default();
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"spacetrack"} or $self->{"spacetrack"} = $self->_get_spacetrack_default 0 7 7
4768 7 return $self->{spacetrack};
4769 }
4770  
4771 # $st = $satpass2->_get_spacetrack_default();
4772 #
4773 # Returns a new Astro::SpaceTrack object, initialized with this
4774 # object's webcmd, and with its filter attribute set to 1.
4775  
4776 7 ▶sub _get_spacetrack_default {
Subroutine _get_spacetrack_default: called CC=2 SCAR=8.1
4777 7 my ( $self ) = @_;
4778 7 ▶ $have_astro_spacetrack->()
Branch: 1 branch
BranchTrueFalseTotal
&$have_astro_spacetrack() or return 0 7 7
4779 or return;
4780 return Astro::SpaceTrack->new (
4781 webcmd => $self->{webcmd},
4782 0 filter => 1,
4783 );
4784 }
4785  
4786 10 ▶sub _get_day_midnight {
Subroutine _get_day_midnight: called CC=4 SCAR=14.0
4787 10 my ( $self, $day ) = @_;
4788 10 ▶ defined $day
Branch: 1 branch
BranchTrueFalseTotal
defined $day or $day = CORE::time 6 4 10
4789 or $day = time;
4790 10 my $gmt = $self->get( 'formatter' )->gmt();
4791 10 ▶ my @time = $gmt ? gmtime( $day ) : localtime( $day );
Branch: 1 branch
BranchTrueFalseTotal
$gmt ? : 10 0 10
4792 10 $time[0] = $time[1] = $time[2] = 0;
4793 10 $time[5] += 1900;
4794 10 ▶ return $gmt ? greg_time_gm(@time) : greg_time_local(@time);
Branch: 1 branch
BranchTrueFalseTotal
$gmt ? : 10 0 10
4795 }
4796  
4797 42 ▶sub _get_day_noon {
Subroutine _get_day_noon: called CC=4 SCAR=14.0
4798 42 my ( $self, $day ) = @_;
4799 42 ▶ defined $day
Branch: 1 branch
BranchTrueFalseTotal
defined $day or $day = CORE::time 21 21 42
4800 or $day = time;
4801 42 my $gmt = $self->get( 'formatter' )->gmt();
4802 42 ▶ my @time = $gmt ? gmtime( $day ) : localtime( $day );
Branch: 1 branch
BranchTrueFalseTotal
$gmt ? : 42 0 42
4803 42 $time[0] = $time[1] = 0;
4804 42 $time[2] = 12;
4805 42 $time[5] += 1900;
4806 42 ▶ return $gmt ? greg_time_gm(@time) : greg_time_local(@time);
Branch: 1 branch
BranchTrueFalseTotal
$gmt ? : 42 0 42
4807 }
4808  
4809 0 ▶sub _get_warner_attribute {
Subroutine _get_warner_attribute: not called CC=1 SCAR=6.9
4810 0 my ( $self, $name ) = @_;
4811 0 return $self->{_warner}->$name();
4812 }
4813  
4814 9 ▶sub _helper_get_object {
Subroutine _helper_get_object: called CC=2 SCAR=7.1
4815 9 my ( $self, $attribute ) = @_;
4816 9 ▶ my $object = $self->get( $attribute )
Branch: 1 branch
BranchTrueFalseTotal
my $object = $self->get($attribute) or $self->wail("No $attribute object available") 9 0 9
4817 or $self->wail( "No $attribute object available" );
4818 9 return $object;
4819 }
4820  
4821 {
4822  
4823 my %parse_input = (
4824 formatter => {
4825 0 ▶ desired_equinox_dynamical => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
4826 0 my ( $self, undef, @args ) = @_; # $opt unused
4827 0 ▶ if ( $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0]) 0 0 0
4828 0 $args[0] = $self->__parse_time( $args[0], 0 );
4829 }
4830 0 return @args;
4831 },
4832 1 ▶ format => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4833 1 my ( $self, $opt, $template, @args ) = @_;
4834 1 $opt->{raw} = 1;
4835 return (
4836 1 arg => \@args,
4837 sp => $self,
4838 template => $template,
4839 );
4840 },
4841 },
4842 time_parser => {
4843 0 ▶ base => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
4844 0 my ( $self, undef, @args ) = @_; # $opt unused
4845 0 ▶ if ( @args && defined $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[0]) 0 0 0
Condition0%0/3
@args and defined $args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@args and defined $args[0]
@args defined $args[0]
Truth table0%0/3
A and B
A= @argsB= defined $args[0]
ABresult
0X0
100
111
4846 0 $args[0] = $self->__parse_time( $args[0], time );
4847 }
4848 0 return @args;
4849 }
4850 },
4851 20 );
4852  
4853 9 ▶ sub _helper_handler : Verb( changes! raw! ) {
Subroutine _helper_handler: called CC=12 SCAR=26.0
4854 9 my ( $self, $opt, $name, $method, @args ) = __arguments( @_ );
4855  
4856 exists $opt->{raw}
4857 9 ▶ or $opt->{raw} = ( ! _is_interactive() );
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"raw"} or $opt->{"raw"} = !_is_interactive() 0 9 9
4858  
4859 9 ▶ defined $method
Branch: 1 branch
BranchTrueFalseTotal
defined $method or $self->wail("No method name specified") 9 0 9
4860 or $self->wail( 'No method name specified' );
4861  
4862 9 ▶ 'config' eq $method
Branch: 1 branch
BranchTrueFalseTotal
"config" eq $method and return $self->_helper_config_handler($name, $opt) 0 9 9
4863 and return $self->_helper_config_handler( $name => $opt );
4864  
4865 9 my $object = $self->_helper_get_object( $name );
4866 9 ▶ $method !~ m/ \A _ /smx and $object->can( $method )
Branch: 1 branch
BranchTrueFalseTotal
not $method =~ / \A _ /msx and $object->can($method) or $self->wail("No such $name method as '${method}'") 9 0 9
Condition33%1/3
not $method =~ / \A _ /msx and $object->can($method)
!ll&&!rl&&r
009
MC/DC0%0/2
not $method =~ / \A _ /msx and $object->can($method)
not $method =~ / \A _ /msx $object->can($method)
Truth table33%1/3
not(A) and B
A= not $method =~ / \A _ /msxB= $object->can($method)
ABresult
0X0
100
111
4867 or $self->wail("No such $name method as '$method'");
4868  
4869 @args
4870 and $parse_input{$name}
4871 and $parse_input{$name}{$method}
4872 9 ▶ and @args = $parse_input{$name}{$method}->( $self, $opt, @args );
Branch: 1 branch
BranchTrueFalseTotal
@args and $parse_input{$name} and $parse_input{$name}{$method} and @args = $parse_input{$name}{$method}->($self, $opt, @args) 1 8 9
Condition83%5/6
@args and $parse_input{$name} and $parse_input{$name}{$method}
!ll&&!rl&&r
441
@args and $parse_input{$name}
!ll&&!rl&&r
405
MC/DC66%2/3
@args and $parse_input{$name} and $parse_input{$name}{$method}
@args $parse_input{$name} $parse_input{$name}{$method}
Truth table75%3/4
A and B and C
A= @argsB= $parse_input{$name}C= $parse_input{$name}{$method}
ABCresult
0XX0
10X0
1100
1111
4873 delete $opt->{raw}
4874 9 ▶ and return $object->$method( @args );
Branch: 1 branch
BranchTrueFalseTotal
delete $opt->{"raw"} and return $object->$method(@args) 4 5 9
4875 5 my @rslt = $object->decode( $method, @args );
4876  
4877 5 ▶ instance( $rslt[0], ref $object ) and return;
Branch: 1 branch
BranchTrueFalseTotal
instance($rslt[0], ref $object) and return 3 2 5
4878 2 ▶ ref $rslt[0] and return $rslt[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $rslt[0] and return $rslt[0] 0 2 2
4879 2 return quoter( $name, $method, @rslt ) . "\n";
4880 20 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
4881 }
4882  
4883 20 ▶sub _helper_config_handler {
Subroutine _helper_config_handler: not called CC=3 SCAR=23.1
4884 0 my ( $self, $name, $opt ) = @_;
4885 0 my $object = $self->_helper_get_object( $name );
4886 my $rslt = $object->config(
4887 changes => $opt->{changes},
4888 decode => ! $opt->{raw},
4889 0 );
4890 0 ▶ $opt->{raw} and return $rslt;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"raw"} and return $rslt 0 0 0
4891 0 my $output = '';
4892 0 foreach my $item ( @{ $rslt } ) {
4893 0 $output .= quoter( $name, @{ $item } ) . "\n";
4894 }
4895 0 return $output;
4896 }
4897  
4898 # $satpass2->_iridium_status(\@status)
4899  
4900 # Updates the status of all Iridium satellites from the given
4901 # array, which is compatible with the second item returned by
4902 # Astro::SpaceTrack->iridium_status(). If no argument is passed,
4903 # the status is retrieved using Astro::SpaceTrack->iridium_status()
4904  
4905 0 ▶sub _iridium_status {
Subroutine _iridium_status: not called CC=6 SCAR=37.4
4906 0 my ($self, $status) = @_;
4907 0 ▶ unless ($status) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 0 0 0
4908 0 my $st = $self->_get_spacetrack();
4909 0 (my $rslt, $status) = $st->iridium_status;
4910 0 ▶ $rslt->is_success or $self->wail($rslt->status_line);
Branch: 1 branch
BranchTrueFalseTotal
$rslt->is_success or $self->wail($rslt->status_line) 0 0 0
4911 }
4912  
4913 0 ▶ if ( ARRAY_REF eq ref $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('ARRAY' eq ref $status) { } 0 0 0
4914 0 Astro::Coord::ECI::TLE->status (clear => 'iridium');
4915 0 foreach (@$status) {
4916 0 Astro::Coord::ECI::TLE->status (add => $_->[0], iridium =>
4917 $_->[4], $_->[1], $_->[3]);
4918 }
4919 } else {
4920 0 $self->weep(
4921 'Portable status not passed, and unavailable from Astro::SpaceTrack'
4922 );
4923 }
4924  
4925 0 foreach my $tle (@{$self->{bodies}}) {
4926 0 $tle->rebless ();
4927 }
4928  
4929 0 return;
4930  
4931 }
4932  
4933 # _is_case_tolerant()
4934 # Returns true if the OS supports case-tolerant file names. Yes, I know
4935 # it's the file system that is important, but I don't have access to
4936 # that level of detail.
4937 {
4938 20 my %os = map { $_ => 1 } qw{ darwin };
4939  
4940 0 ▶ sub _is_case_tolerant {
Subroutine _is_case_tolerant: not called CC=2 SCAR=17.9
4941 exists $os{$^O}
4942 0 ▶ and return $os{$^O};
Branch: 1 branch
BranchTrueFalseTotal
exists $os{$^O} and return $os{$^O} 0 0 0
4943 0 return File::Spec->case_tolerant();
4944 }
4945 }
4946  
4947 # _is_interactive()
4948 #
4949 # Returns true if the dispatch() method is above us on the call
4950 # stack, otherwise returns false.
4951  
4952 20 ▶use constant INTERACTIVE_CALLER => __PACKAGE__ . '::dispatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
4953 364 ▶sub _is_interactive {
Subroutine _is_interactive: called CC=3 SCAR=11.0
4954 364 my $level = 0;
4955 364 ▶ while ( my @info = caller( $level ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@info) = caller $level) 1734 326 2060
4956 1734 ▶ INTERACTIVE_CALLER eq $info[3]
Branch: 1 branch
BranchTrueFalseTotal
"Astro::App::Satpass2::dispatch" eq $info[3] and return $level 38 1696 1734
4957 and return $level;
4958 1696 $level++;
4959 }
4960 326 return;
4961 }
4962  
4963 # $self->_load_module ($module_name)
4964  
4965 # Loads the module if it has not yet been loaded. Dies if it
4966 # can not be loaded.
4967  
4968 { # Begin local symbol block
4969  
4970 20 my %version;
4971 20 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4972 20 %version = (
4973 'Astro::SpaceTrack' => ASTRO_SPACETRACK_VERSION,
4974 );
4975 }
4976  
4977 0 ▶ sub _load_module {
Subroutine _load_module: not called CC=11 SCAR=48.8
4978 0 my ($self, @module) = @_;
4979 ARRAY_REF eq ref $module[0]
4980 0 ▶ and @module = @{$module[0]};
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $module[0] and @module = @{$module[0];} 0 0 0
4981 0 ▶ @module or $self->weep( 'No module specified' );
Branch: 1 branch
BranchTrueFalseTotal
@module or $self->weep("No module specified") 0 0 0
4982 0 my @probs;
4983 0 foreach my $module (@module) {
4984 0 ▶ load_package ($module) or do {
Branch: 1 branch
BranchTrueFalseTotal
load_package($module) or do { push @probs, "$module needed"; next } 0 0 0
4985 0 push @probs, "$module needed";
4986 0 next;
4987 };
4988 0 my $modver;
4989 0 ▶ ($version{$module} && ($modver = $module->VERSION)) and do {
Branch: 1 branch
BranchTrueFalseTotal
$version{$module} and $modver = $module->VERSION and do { $modver =~ s/_//g; $modver < $version{$module} and do { push @probs, "$module version $version{$module} needed"; next } } 0 0 0
Condition0%0/3
$version{$module} and $modver = $module->VERSION
!ll&&!rl&&r
000
MC/DC0%0/2
$version{$module} and $modver = $module->VERSION
$version{$module} $modver = $module->VERSION
Truth table0%0/3
A and B
A= $version{$module}B= $modver = $module->VERSION
ABresult
0X0
100
111
4990 0 $modver =~ s/_//g;
4991 0 ▶ $modver < $version{$module} and do {
Branch: 1 branch
BranchTrueFalseTotal
$modver < $version{$module} and do { push @probs, "$module version $version{$module} needed"; next } 0 0 0
4992 0 push @probs,
4993 "$module version $version{$module} needed";
4994 0 next;
4995 };
4996 };
4997 0 return $module;
4998 }
4999 {
5000 0 my $inx = 1;
5001 0 ▶ while (my @clr = caller($inx++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@clr) = caller $inx++) 0 0 0
5002 0 ▶ $clr[3] eq '(eval)' and next;
Branch: 1 branch
BranchTrueFalseTotal
$clr[3] eq "(eval)" and next 0 0 0
5003 0 my @raw = split '::', $clr[3];
5004 0 ▶ substr ($raw[-1], 0, 1) eq '_' and next;
Branch: 1 branch
BranchTrueFalseTotal
substr($raw[-1], 0, 1) eq "_" and next 0 0 0
5005 0 push @probs, "for method $raw[-1]";
5006 0 last;
5007 }
5008 }
5009 0 my $pfx = 'Error -';
5010 0 $self->wail(map {my $x = "$pfx $_\n"; $pfx = ' ' x 7; $x} @probs);
5011 0 return; # Can't get here, but Perl::Critic does not know this.
5012 }
5013  
5014 } # end local symbol block.
5015  
5016 # $output = $self->_macro($name,@args)
5017 #
5018 # Execute the named macro. The @args are of course optional.
5019  
5020 20 ▶sub _macro {
Subroutine _macro: called CC=4 SCAR=13.9
5021 19 my ($self, $name, @args) = @_;
5022 19 ▶ $self->{macro}{$name} or $self->wail("No such macro as '$name'");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"macro"}{$name} or $self->wail("No such macro as '${name}'") 19 0 19
5023 19 my $frames = $self->_frame_push(macro => [@args]);
5024 my $macro = $self->{frame}[-1]{macro}{$name} =
5025 19 delete $self->{macro}{$name};
5026 19 my $output;
5027 my $err;
5028 19 ▶ my $ok = eval {
Branch: 1 branch
BranchTrueFalseTotal
my $ok = eval { do { $output = $macro->execute($name, @args); 1 } } or $err = $@ 18 1 19
5029 19 $output = $macro->execute( $name, @args );
5030 18 1;
5031 } or $err = $@;
5032 19 $self->_frame_pop($frames);
5033 19 ▶ $ok or $self->wail($err);
Branch: 1 branch
BranchTrueFalseTotal
$ok or $self->wail($err) 18 1 19
5034 18 return $output;
5035 }
5036  
5037 # $angle = _parse_angle_parts ( @parts );
5038 #
5039 # Joins parts of angles into an angle.
5040 # The @parts array is array references describing the parts in
5041 # decreasing significance, with [0] being the value, and [1] being
5042 # the number in the next larger part. For the first piece, [1]
5043 # should be the number in an entire circle.
5044  
5045 3 ▶sub _parse_angle_parts {
Subroutine _parse_angle_parts: called CC=5 SCAR=16.2
5046 3 my @parts = @_;
5047 3 my $angle = 0;
5048 3 my $circle = 1;
5049 3 my $places;
5050 3 foreach ( @parts ) {
5051 9 my ( $part, $size ) = @{ $_ };
5052 9 ▶ defined $part or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $part or last 9 0 9
5053 9 $circle *= $size;
5054 9 $angle = $angle * $size + $part;
5055 9 ▶ $places = $part =~ m/ [.] ( [0-9]+ ) /smx ? length $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$part =~ / [.] ( [0-9]+ ) /msx ? : 0 9 9
5056 }
5057 3 $angle *= 360 / $circle;
5058 3 ▶ if ( my $mag = sprintf '%d', $circle / 360 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mag = sprintf("%d", $circle / 360)) 3 0 3
5059 3 $places += length $mag;
5060 }
5061 3 return sprintf( '%.*f', $places, $angle ) + 0;
5062 }
5063  
5064 # Documented in POD
5065  
5066 40 ▶sub __parse_angle {
Subroutine __parse_angle: called CC=9 SCAR=22.3
5067 40 my ( $self, @args ) = @_;
5068 40 ▶ my $opt = HASH_REF eq ref $args[0] ? shift @args : {};
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $args[0] ? : 7 33 40
5069 40 my ( $angle ) = @args;
5070 40 ▶ defined $angle or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $angle or return 33 7 40
5071  
5072 33 ▶ if ( $angle =~ m/ : /smx ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($angle =~ / : /msx) { } 2 31 33
elsif ($angle =~ / \A ( [-+] )? ( [0-9]* ) d ( [0-9]* (?: [.] [0-9]* )? ) (?: m ( [0-9]* (?: [.] [0-9]* )? ) s? )? \z /imsx) { } 1 30 31
5073  
5074 2 my ($h, $m, $s) = split ':', $angle;
5075 2 return _parse_angle_parts(
5076 [ $h => 24 ],
5077 [ $m => 60 ],
5078 [ $s => 60 ],
5079 );
5080  
5081 } elsif ( $angle =~
5082 m{ \A ( [-+] )? ( [0-9]* ) d
5083 ( [0-9]* (?: [.] [0-9]* )? ) (?: m
5084 ( [0-9]* (?: [.] [0-9]* )? ) s? )? \z
5085 }smxi ) {
5086 1 my ( $sgn, $deg, $min, $sec ) = ( $1, $2, $3, $4 );
5087 1 $angle = _parse_angle_parts(
5088 [ $deg => 360 ],
5089 [ $min => 60 ],
5090 [ $sec => 60 ],
5091 );
5092 1 ▶ $sgn and '-' eq $sgn and return -$angle;
Branch: 1 branch
BranchTrueFalseTotal
$sgn and "-" eq $sgn and return -$angle 0 1 1
Condition33%1/3
$sgn and "-" eq $sgn
!ll&&!rl&&r
100
MC/DC0%0/2
$sgn and "-" eq $sgn
$sgn "-" eq $sgn
Truth table33%1/3
A and B
A= $sgnB= "-" eq $sgn
ABresult
0X0
100
111
5093 1 return $angle;
5094 }
5095  
5096 $opt->{accept}
5097 30 ▶ or looks_like_number( $angle )
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"accept"} or &looks_like_number($angle) or $self->wail("Invalid angle '${angle}'") 30 0 30
Condition66%2/3
$opt->{"accept"} or &looks_like_number($angle)
l!l&&r!l&&!r
7230
MC/DC0%0/2
$opt->{"accept"} or &looks_like_number($angle)
$opt->{"accept"} &looks_like_number($angle)
Truth table66%2/3
A or B
A= $opt->{"accept"}B= &looks_like_number($angle)
ABresult
1X1
011
000
5098 or $self->wail( "Invalid angle '$angle'" );
5099  
5100 30 return $angle;
5101 }
5102  
5103 # Documented in POD
5104 {
5105 20 my %units = (
5106 au => AU,
5107 ft => 0.0003048,
5108 km => 1,
5109 ly => LIGHTYEAR,
5110 m => .001,
5111 mi => 1.609344,
5112 pc => PARSEC,
5113 );
5114  
5115 3 ▶ sub __parse_distance {
Subroutine __parse_distance: called CC=7 SCAR=21.2
5116 3 my ($self, $string, $dfdist) = @_;
5117 3 ▶ defined $dfdist or $dfdist = 'km';
Branch: 1 branch
BranchTrueFalseTotal
defined $dfdist or $dfdist = "km" 3 0 3
5118 3 ▶ my $dfunits = $dfdist =~ s/ ( [[:alpha:]]+ ) \z //smx ? $1 : 'km';
Branch: 1 branch
BranchTrueFalseTotal
$dfdist =~ s/ ( [[:alpha:]]+ ) \z //msx ? : 3 0 3
5119 3 ▶ my $units = lc (
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/ \s* ( [[:alpha:]]+ ) \z //msx ? : 0 3 3
5120 $string =~ s/ \s* ( [[:alpha:]]+ ) \z //smx ? $1 : $dfunits );
5121 3 ▶ $units{$units}
Branch: 1 branch
BranchTrueFalseTotal
$units{$units} or $self->wail("Units of '${units}' are unknown") 3 0 3
5122 or $self->wail( "Units of '$units' are unknown" );
5123 3 ▶ $string ne '' or $string = $dfdist;
Branch: 1 branch
BranchTrueFalseTotal
$string ne "" or $string = $dfdist 3 0 3
5124 3 ▶ looks_like_number ($string)
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($string) or $self->wail("'${string}' is not a number") 3 0 3
5125 or $self->wail( "'$string' is not a number" );
5126 3 return $string * $units{$units};
5127 }
5128 }
5129  
5130 # Documented in POD
5131  
5132 20 ▶sub __parse_time {
Subroutine __parse_time: called CC=4 SCAR=15.5
5133 57 my ($self, $time, $default) = @_;
5134 my $pt = $self->{time_parser}
5135 57 ▶ or $self->wail( 'No time parser available' );
Branch: 1 branch
BranchTrueFalseTotal
my $pt = $self->{"time_parser"} or $self->wail("No time parser available") 57 0 57
5136 57 ▶ $self->{time_parser}->can( 'station' )
Branch: 1 branch
BranchTrueFalseTotal
$self->{"time_parser"}->can("station") and $self->_set_time_parser_attribute("station", $self->station) 0 57 57
5137 and $self->_set_time_parser_attribute(
5138 station => $self->station() );
5139 57 ▶ if ( defined( my $time = $pt->parse( $time, $default ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $time = $pt->parse($time, $default))) 57 0 57
5140 57 return $time;
5141 }
5142 0 $self->wail( "Invalid time '$time'" );
5143 0 return;
5144 }
5145  
5146 # Reset the last time set. This is called from __arguments() in
5147 # ::Utils if the invocant is an Astro::App::Satpass2.
5148  
5149 342 ▶sub __parse_time_reset {
Subroutine __parse_time_reset: called CC=2 SCAR=6.9
5150 342 my ( $self ) = @_;
5151 defined ( my $pt = $self->{time_parser} )
5152 342 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $pt = $self->{"time_parser"}) or return 321 21 342
5153 321 $pt->reset();
5154 321 return;
5155 }
5156  
5157 # $string = _rad2hms ($angle)
5158  
5159 # Converts the given angle in radians to hours, minutes, and
5160 # seconds (of right ascension, presumably)
5161  
5162 1 ▶sub _rad2hms {
Subroutine _rad2hms: called CC=1 SCAR=0.0
5163 1 my $sec = shift;
5164 1 $sec *= 12 / PI;
5165 1 my $hr = floor( $sec );
5166 1 $sec = ( $sec - $hr ) * 60;
5167 1 my $min = floor( $sec );
5168 1 $sec = ( $sec - $min ) * 60;
5169 1 my $rslt = sprintf '%2d:%02d:%02d', $hr, $min, floor( $sec + .5 );
5170 1 return $rslt;
5171 }
5172  
5173 # $line = $self->_read_continuation( $in, $error_message );
5174 #
5175 # Acquire a line from $in, which must be a code reference taking
5176 # the prompt as an argument. If $in is not a code reference, or if
5177 # it returns undef, we wail() with the error message. Otherwise
5178 # we return the line read. I expect this to be used only by
5179 # __tokenize().
5180  
5181 15 ▶sub _read_continuation {
Subroutine _read_continuation: called CC=7 SCAR=19.9
5182 15 my ( $self, $in, $error ) = @_;
5183 $in and defined( my $more = $in->(
5184 my $prompt = $self->get( 'continuation_prompt' ) ) )
5185 15 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$in and defined(my $more = &$in(my $prompt = $self->get("continuation_prompt"))) or do { $error or return; ref $error eq "CODE" and return &$error(); $self->wail($error) } 14 1 15
Condition66%2/3
$in and defined(my $more = &$in(my $prompt = $self->get("continuation_prompt")))
!ll&&!rl&&r
0114
MC/DC50%1/2
$in and defined(my $more = &$in(my $prompt = $self->get("continuation_prompt")))
$in defined(my $more = &$in(my $prompt = $self->get("continuation_prompt")))
Truth table66%2/3
A and B
A= $inB= defined(my $more = &$in(my $prompt = $self->get("continuation_prompt")))
ABresult
0X0
100
111
5186 1 ▶ $error or return;
Branch: 1 branch
BranchTrueFalseTotal
$error or return 1 0 1
5187 1 ▶ ref $error eq CODE_REF
Branch: 1 branch
BranchTrueFalseTotal
ref $error eq "CODE" and return &$error() 0 1 1
5188 and return $error->();
5189 1 $self->wail( $error );
5190 };
5191 14 ▶ $self->{echo} and $self->whinge( $prompt, $more );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"echo"} and $self->whinge($prompt, $more) 0 14 14
5192 14 ▶ $more =~ m/ \n \z /smx or $more .= "\n";
Branch: 1 branch
BranchTrueFalseTotal
$more =~ / \n \z /msx or $more .= "\n" 10 4 14
5193 14 return $more;
5194 }
5195  
5196 # my ( $old_obj ) = $self->_replace_in_sky( $name, $new_obj );
5197 # This is restricted to objects constructed via {sky_class}.
5198 # The return is an array containing the replaced body, or nothing if
5199 # the body was not found. The $new_obj is optional; if not provided a
5200 # new object is created.
5201 0 ▶sub _replace_in_sky {
Subroutine _replace_in_sky: not called CC=5 SCAR=34.0
5202 0 my ( $self, $name, $new_obj ) = @_;
5203 $new_obj
5204 0 ▶ or $self->{sky_class}{ fold_case( $name ) }
Branch: 1 branch
BranchTrueFalseTotal
$new_obj or $self->{"sky_class"}{CORE::fc $name} or $self->weep("Can not replace $name; no class defined") 0 0 0
Condition0%0/3
$new_obj or $self->{"sky_class"}{CORE::fc $name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$new_obj or $self->{"sky_class"}{CORE::fc $name}
$new_obj $self->{"sky_class"}{CORE::fc $name}
Truth table0%0/3
A or B
A= $new_objB= $self->{"sky_class"}{CORE::fc $name}
ABresult
1X1
011
000
5205 or $self->weep( "Can not replace $name; no class defined" );
5206 0 ▶ defined( my $inx = $self->_find_in_sky( $name ) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $inx = $self->_find_in_sky($name)) or return 0 0 0
5207 or return;
5208 0 ▶ return splice @{ $self->{sky} }, $inx, $inx + 1,
Condition0%0/3
$new_obj || $self->_sky_object($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$new_obj || $self->_sky_object($name)
$new_obj $self->_sky_object($name)
Truth table0%0/3
A || B
A= $new_objB= $self->_sky_object($name)
ABresult
1X1
011
000
5209 $new_obj || $self->_sky_object( $name );
5210 }
5211  
5212 # $self->_rewrite_level1_command( $buffer, $context );
5213 #
5214 # This method rewrites a level1 command to its current form. The
5215 # arguments are the buffer containing the command, and an
5216 # initially-empty hash reference, which the method will use to
5217 # preserve context across lines of command. NOTE that more than
5218 # one rewritten command may be returned (e.g. 'almanac' into
5219 # ( 'location', 'almanac' ).
5220  
5221 {
5222  
5223 my %level1_map = (
5224 1 ▶ almanac => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5225 1 return ( 'location', $_[0] );
5226 },
5227 1 ▶ flare => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5228 1 local $_ = $_[0];
5229 1 s/ (?<= \s ) - ( am|pm|day ) \b /-no$1/sxmg;
5230 1 return $_;
5231 },
5232 1 ▶ pass => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5233 1 return ( 'location', $_[0] );
5234 },
5235 20 );
5236  
5237 my %level1_requote = (
5238 # In a macro definition:
5239 macro => {
5240 # In single-quoted strings,
5241 5 ▶ q{'} => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5242 # escaped interpolations and double quotes may be
5243 # unescaped,
5244 5 s{ (?: \A | (?<! \\ ) ) ( (?: \\\\ )* ) \\ ( [\@\$\"] )
5245 }{$1$2}sxmg;
5246 # and the string remains single-quoted.
5247 5 $_ = qq{'$_'};
5248 5 return;
5249 },
5250 # In double-quoted strings,
5251 2 ▶ q{"} => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5252 # escaped interpolations and double quotes may be
5253 # unescaped,
5254 2 s{ (?: \A | (?<! \\ ) ) ( (?: \\\\ )* ) \\ ( [\@\$\"] )
5255 }{$1$2}sxmg;
5256 # unescaped single quotes become double quotes,
5257 2 s/ (?: \A | (?<! \\ ) ) ( (?: \\\\ )* ) ' /$1"/sxmg;
5258 # and the string becomes single-quoted.
5259 2 $_ = qq{'$_'};
5260 2 return;
5261 },
5262 },
5263 # Anywhere else
5264 '' => {
5265 # In single-quoted strings,
5266 0 ▶ q{'} => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5267 # unescaped double quotes must be escaped,
5268 0 s/ (?: \A | (?<! \\ ) ) ( (?: \\\\ )* ) " /$1\\"/sxmg;
5269 # escaped single quotes may be unescaped,
5270 0 s/ (?: \A | (?<! \\ ) ) ( (?: \\\\ )* ) \\ ' /$1'/sxmg;
5271 # and the string becomes double-quoted.
5272 0 $_ = qq{"$_"};
5273 0 return;
5274 },
5275 # In double-quoted strings,
5276 2 ▶ q{"} => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5277 # no changes need to be made.
5278 2 $_ = qq{"$_"};
5279 2 return;
5280 },
5281 },
5282 20 );
5283  
5284 19 ▶ sub _rewrite_level1_command {
Subroutine _rewrite_level1_command: called CC=14 SCAR=26.6
5285 19 my ( undef, $buffer, $context ) = @_; # Invocant unused
5286  
5287 19 my $command = delete $context->{command};
5288  
5289 19 ▶ defined $buffer
Branch: 1 branch
BranchTrueFalseTotal
defined $buffer or return $buffer 12 7 19
5290 or return $buffer;
5291 12 ▶ $buffer =~ m/ \A \s* \z /sxm
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \A \s* \z /msx and return $buffer 0 12 12
5292 and return $buffer;
5293 12 ▶ $buffer =~ s/ \A \s* [#] 2 [#] \s* //sxm
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ s/ \A \s* [#] 2 [#] \s* //msx and return $buffer 0 12 12
5294 and return $buffer;
5295 12 ▶ $buffer =~ m/ \A \s* [#] /sxm
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \A \s* [#] /msx and return $buffer 0 12 12
5296 and return $buffer;
5297  
5298 12 ▶ if ( ! defined $command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $command) 12 0 12
5299 12 ▶ $buffer =~ m/ \A \s* ( \w+ ) /sxm
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \A \s* ( \w+ ) /msx or return $buffer 11 1 12
5300 or return $buffer;
5301 11 $command = $1;
5302 }
5303 11 my $append = '';
5304 11 ▶ $buffer =~ s/ ( \s* \\? \n ) //sxm
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ s/ ( \s* \\? \n ) //msx and $append = $1 8 3 11
5305 and $append = $1;
5306 $append =~ m/ \\ /sxm
5307 11 ▶ and $context->{command} = $command;
Branch: 1 branch
BranchTrueFalseTotal
$append =~ / \\ /msx and $context->{"command"} = $command 0 11 11
5308  
5309 11 ▶ my $handler = $level1_requote{$command} || $level1_requote{''};
Condition66%2/3
$level1_requote{$command} || $level1_requote{''}
l!l&&r!l&&!r
830
MC/DC0%0/2
$level1_requote{$command} || $level1_requote{''}
$level1_requote{$command} $level1_requote{''}
Truth table66%2/3
A || B
A= $level1_requote{$command}B= $level1_requote{''}
ABresult
1X1
011
000
5310 11 my ( $this_quote, $start_pos );
5311 11 ▶ while ( $buffer =~ m/ (?: \A | (?<! \\ ) ) (?: \\\\ )* ( ['"] ) /sxmg
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ / (?: \A | (?<! \\ ) ) (?: \\\\ )* ( ['"] ) /gmsx) 22 11 33
5312 ) {
5313 22 ▶ if ( ! defined $start_pos ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $start_pos) { } 9 13 22
elsif ($1 eq $this_quote) { } 9 4 13
5314 9 $start_pos = $+[0] - 1;
5315 9 $this_quote = $1;
5316 } elsif ( $1 eq $this_quote ) {
5317 9 my $length = $+[0] - $start_pos;
5318 9 local $_ = substr $buffer, $start_pos + 1, $length - 2;
5319 9 $handler->{$this_quote}->();
5320 9 substr $buffer, $start_pos, $length, $_;
5321 9 pos( $buffer ) = $start_pos + length $_;
5322 9 $start_pos = undef;
5323 }
5324 }
5325  
5326 11 ▶ my $code = $level1_map{$command}
Branch: 1 branch
BranchTrueFalseTotal
my $code = $level1_map{$command} or return $buffer . $append 3 8 11
5327 or return $buffer . $append;
5328  
5329 3 my @rslt = $code->( $buffer );
5330 3 $rslt[-1] .= $append;
5331 3 return @rslt;
5332  
5333 }
5334 }
5335  
5336 # $self->_rewrite_level1_macros();
5337 #
5338 # This method rewrites all macros defined by a satpass
5339 # initialization file (as opposed to a satpass2 initialization
5340 # file) to be satpass2-compatible. It also clears the level1 flag
5341 # so that the satpass-compatible functionality is not invoked.
5342 #
5343 # Specifically it:
5344 # * Inserts a 'location' command before 'almanac' and 'pass';
5345 # * Changes the senses of the -am, -day, and -pm options in
5346 # 'flare';
5347 # * Removes delegated attributes from 'localize', replacing them
5348 # with a localization of the helper object.
5349 #
5350 # This method goes away when the satpass functionality does.
5351  
5352 {
5353 20 my %helper_map = (
5354 date_format => {
5355 helper => 'formatter', # Helper obj attr. Req'd.
5356 },
5357 desired_equinox_dynamical => {
5358 helper => 'formatter',
5359 },
5360 gmt => {
5361 helper => 'formatter',
5362 },
5363 local_coord => {
5364 helper => 'formatter',
5365 },
5366 time_format => {
5367 helper => 'formatter',
5368 },
5369 );
5370  
5371 my %filter = (
5372 1 ▶ almanac => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5373 1 my ( undef, $line ) = @_; # $verb unused
5374 1 return ( 'location', $line );
5375 },
5376 1 ▶ flare => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5377 1 my ( undef, $line ) = @_; # $verb unused
5378 1 $line =~ s/ (?<= \s ) - (am|day|pm) \b /-no$1/smx;
5379 1 return $line;
5380 },
5381 1 ▶ localize => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
5382 1 my ( undef, $line ) = @_; # $verb unused
5383 1 my @things = split qr{ \s+ }smx, $line;
5384 1 my @output;
5385 my %duplicate;
5386 1 foreach my $token ( @things ) {
5387 $helper_map{$token}
5388 6 ▶ and $token = $helper_map{$token}{helper};
Branch: 1 branch
BranchTrueFalseTotal
$helper_map{$token} and $token = $helper_map{$token}{"helper"} 3 3 6
5389 6 ▶ $duplicate{$token}++ or push @output, $token;
Branch: 1 branch
BranchTrueFalseTotal
$duplicate{$token}++ or push @output, $token 2 4 6
5390 }
5391 1 return join ' ', @output;
5392 },
5393 1 ▶ pass => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5394 1 my ( undef, $line ) = @_; # $verb unused
5395 1 return ( 'location', $line );
5396 },
5397 1 ▶ set => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
5398 1 my ( undef, $line ) = @_; # $verb unused
5399 1 my @output = [ 'fubar' ]; # Prime the pump.
5400 1 my @input = Text::ParseWords::quotewords( qr{ \s+ }smx, 1,
5401 $line );
5402 1 shift @input;
5403 1 ▶ while ( @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@input) 6 1 7
5404 6 my ( $attr, $val ) = splice @input, 0, 2;
5405 6 ▶ if ( my $helper = $helper_map{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $helper = $helper_map{$attr}) { } 3 3 6
5406 push @output, [ $helper->{helper},
5407 # not quoter( $val ) here, because presumably it
5408 # is already quoted if it needs to be.
5409 3 ▶ $helper->{attribute} || $attr, $val ];
Condition33%1/3
$helper->{'attribute'} || $attr
l!l&&r!l&&!r
030
MC/DC0%0/2
$helper->{'attribute'} || $attr
$helper->{'attribute'} $attr
Truth table33%1/3
A || B
A= $helper->{'attribute'}B= $attr
ABresult
1X1
011
000
5410 } else {
5411 3 ▶ 'set' eq $output[-1][0]
Branch: 1 branch
BranchTrueFalseTotal
"set" eq $output[-1][0] or push @output, ["set"] 1 2 3
5412 or push @output, [ 'set' ];
5413 # not quoter( $val ) here, because presumably it is
5414 # already quoted if it needs to be.
5415 3 push @{ $output[-1] }, $attr, $val;
5416 }
5417 }
5418 1 shift @output; # Get rid of the pump priming.
5419 1 return ( map { join ' ', @{ $_ } } @output );
5420 },
5421 1 ▶ st => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
5422 1 my ( undef, $line ) = @_; # $verb unused
5423 1 ▶ m/ \A \s* st \s+ localize \b /smx
Branch: 1 branch
BranchTrueFalseTotal
/ \A \s* st \s+ localize \b /msx and return $line 0 1 1
5424 and return $line;
5425 1 $line =~ s/ \b st \b /spacetrack/smx;
5426 1 return $line;
5427 },
5428 1 ▶ show => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
5429 1 my ( undef, $line ) = @_; # $verb unused
5430 1 my @output = [ 'fubar' ];
5431 1 my @input = split qr{ \s+ }smx, $line;
5432 1 shift @input;
5433 1 foreach my $attr ( @input ) {
5434 4 ▶ if ( my $helper = $helper_map{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $helper = $helper_map{$attr}) { } 2 2 4
5435 push @output, [ $helper->{helper},
5436 2 ▶ $helper->{attribute} || $attr ];
Condition33%1/3
$helper->{'attribute'} || $attr
l!l&&r!l&&!r
020
MC/DC0%0/2
$helper->{'attribute'} || $attr
$helper->{'attribute'} $attr
Truth table33%1/3
A || B
A= $helper->{'attribute'}B= $attr
ABresult
1X1
011
000
5437 } else {
5438 2 ▶ 'show' eq $output[-1][0]
Branch: 1 branch
BranchTrueFalseTotal
"show" eq $output[-1][0] or push @output, ["show"] 1 1 2
5439 or push @output, [ 'show' ];
5440 2 push @{ $output[-1] }, $attr;
5441 }
5442 }
5443 1 shift @output;
5444 1 return ( map { join ' ', @{ $_ } } @output );
5445 },
5446 20 );
5447  
5448 # Called by macro object's __level1_rewrite().
5449 8 ▶ sub __rewrite_level1_macro_def {
Subroutine __rewrite_level1_macro_def: called CC=7 SCAR=19.5
5450 8 my ( $self, $name, $args ) = @_;
5451  
5452 8 my ( $rewrote, @rslt );
5453 8 foreach ( @{ $args } ) {
5454 8 ▶ if ( m/ ( \S+ ) /smx
Branch: 1 branch
BranchTrueFalseTotal
if (/ ( \S+ ) /msx and !$self->{'macro'}{$1} || $1 eq $name and my $code = $filter{$1}) { } 7 1 8
Condition77%7/9
/ ( \S+ ) /msx and !$self->{"macro"}{$1} || $1 eq $name and my $code = $filter{$1}
!ll&&!rl&&r
107
/ ( \S+ ) /msx and !$self->{"macro"}{$1} || $1 eq $name
!ll&&!rl&&r
017
not $self->{"macro"}{$1} or $1 eq $name
l!l&&r!l&&!r
611
MC/DC50%2/4
/ ( \S+ ) /msx and !$self->{"macro"}{$1} || $1 eq $name and my $code = $filter{$1}
/ ( \S+ ) /msx not $self->{"macro"}{$1} $1 eq $name my $code = $filter{$1}
Truth table50%3/6
A and not(B) or C and D
A= / ( \S+ ) /msxB= not $self->{"macro"}{$1}C= $1 eq $nameD= my $code = $filter{$1}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
5455 and ( not $self->{macro}{$1}
5456 or $1 eq $name )
5457 and my $code = $filter{$1} ) {
5458 7 push @rslt, $code->( $1, $_ );
5459 7 $rewrote++;
5460 } else {
5461 1 push @rslt, $_;
5462 }
5463 }
5464  
5465 8 ▶ return $rewrote ? \@rslt : $args;
Branch: 1 branch
BranchTrueFalseTotal
$rewrote ? : 7 1 8
5466 }
5467  
5468 4 ▶ sub _rewrite_level1_macros {
Subroutine _rewrite_level1_macros: called CC=2 SCAR=6.9
5469 4 my ( $self ) = @_;
5470  
5471 4 foreach my $macro ( values %{ $self->{macro} } ) {
5472 8 $macro->__level1_rewrite();
5473 }
5474  
5475 4 return;
5476 }
5477 }
5478  
5479 # @coordinates = $self->_simbad4 ($query)
5480  
5481 # Look up the given star in the SIMBAD catalog. This assumes
5482 # SIMBAD 4.
5483  
5484 # We die on any error.
5485  
5486 20 ▶sub _simbad4 {
Subroutine _simbad4: not called CC=11 SCAR=48.1
5487 0 my $self = shift;
5488 0 $self->_load_module ('Astro::SIMBAD::Client');
5489 0 my $query = shift;
5490 my $simbad = Astro::SIMBAD::Client->new (
5491 format => {txt => 'FORMAT_TXT_SIMPLE_BASIC'},
5492 parser => {
5493 script => 'Parse_TXT_Simple',
5494 txt => 'Parse_TXT_Simple',
5495 },
5496 server => $self->{simbad_url},
5497 0 type => 'txt',
5498 );
5499 # I prefer script() to query() these days because the former does
5500 # not require SOAP::Lite, which seems to be getting flakier as time
5501 # goes on.
5502 # TODO get rid of $fmt =~ s/// once I massage
5503 # FORMAT_TXT_SIMPLE_BASIC in Astro::SIMBAD::Client
5504 # my @rslt = $simbad->query (id => $query)
5505 0 my $fmt = Astro::SIMBAD::Client->FORMAT_TXT_SIMPLE_BASIC();
5506 0 $fmt =~ s/ \n //smxg;
5507 0 ▶ my @rslt = $simbad->script( <<"EOD" )
Branch: 1 branch
BranchTrueFalseTotal
my(@rslt) = $simbad->script(qq[format obj "$fmt"\nquery id $query\n]) or $self->wail("No entry found for $query") 0 0 0
5508 format obj "$fmt"
5509 query id $query
5510 EOD
5511 or $self->wail("No entry found for $query");
5512 0 ▶ @rslt > 1
Branch: 1 branch
BranchTrueFalseTotal
@rslt > 1 and $self->wail("More than one entry found for $query") 0 0 0
5513 and $self->wail("More than one entry found for $query");
5514 0 ▶ @rslt = map {$rslt[0]{$_} eq '~' ? 0 : $rslt[0]{$_} || 0} qw{
Branch: 1 branch
BranchTrueFalseTotal
$rslt[0]{$_} eq '~' ? : 0 0 0
Condition0%0/2
$rslt[0]{$_} or 0
l!l
00
MC/DC0%0/1
$rslt[0]{$_} or 0
$rslt[0]{$_}
Truth table0%0/2
A
A= $rslt[0]{$_}
Aresult
11
00
5515 ra dec plx pmra pmdec radial};
5516 0 ▶ ($rslt[0] && $rslt[1])
Branch: 1 branch
BranchTrueFalseTotal
$rslt[0] and $rslt[1] or $self->wail("No position returned by $query") 0 0 0
Condition0%0/3
$rslt[0] and $rslt[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$rslt[0] and $rslt[1]
$rslt[0] $rslt[1]
Truth table0%0/3
A and B
A= $rslt[0]B= $rslt[1]
ABresult
0X0
100
111
5517 or $self->wail("No position returned by $query");
5518 0 ▶ $rslt[2] = $rslt[2] ? 1000 / $rslt[2] : 10000;
Branch: 1 branch
BranchTrueFalseTotal
$rslt[2] ? : 0 0 0
5519 0 ▶ $rslt[3] and $rslt[3] /= 1000;
Branch: 1 branch
BranchTrueFalseTotal
$rslt[3] and $rslt[3] /= 1000 0 0 0
5520 0 ▶ $rslt[4] and $rslt[4] /= 1000;
Branch: 1 branch
BranchTrueFalseTotal
$rslt[4] and $rslt[4] /= 1000 0 0 0
5521 0 ▶ return wantarray ? @rslt : join ' ', @rslt;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
5522 }
5523  
5524 24 ▶sub _templates_to_options {
Subroutine _templates_to_options: called CC=5 SCAR=17.4
5525 24 my ( $self, $name, $opt ) = @_;
5526  
5527 24 $opt->{_template} = $name;
5528 5 ▶ my $code = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
5529 5 my ( $opt_name, $opt_value ) = @_;
5530 5 ▶ $opt->{_template} = $opt_value ? "${name}_$opt_name" : $name;
Branch: 1 branch
BranchTrueFalseTotal
$opt_value ? : 5 0 5
5531 5 return;
5532 24 };
5533 24 my $re = qr< \A \Q$name\E _ ( \w+ ) \z >smx;
5534 24 my @rslt;
5535 my %valid_format;
5536 24 my $fmtr = $self->get( 'formatter' );
5537 24 ▶ if ( $fmtr->can( '__list_templates' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmtr->can("__list_templates")) 24 0 24
5538 24 foreach ( $fmtr->__list_templates() ) {
5539 720 ▶ $_ =~ $re
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$re/ or next 52 668 720
5540 or next;
5541 52 $valid_format{$1} = 1;
5542 52 push @rslt, "$1!", $code;
5543 }
5544 }
5545 @rslt
5546 0 ▶ and push @rslt, 'format=s', sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
5547 0 my ( undef, $opt_value ) = @_;
5548 0 ▶ $valid_format{$opt_value}
Branch: 1 branch
BranchTrueFalseTotal
$valid_format{$opt_value} or $self->wail("Invalid format '${opt_value}'") 0 0 0
5549 or $self->wail( "Invalid format '$opt_value'" );
5550 0 $opt->{_template} = "${name}_$opt_value";
5551 0 return;
5552 24 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
@rslt and push @rslt, "format=s", sub { my(undef, $opt_value) = @_; $valid_format{$opt_value} or $self->wail("Invalid format '${opt_value}'"); $opt->{"_template"} = "${name}_$opt_value"; return; } 24 0 24
5553 24 return @rslt;
5554 }
5555  
5556 # ($tokens, $redirect) = $self->__tokenize(
5557 # {option => $value}, $buffer, [$arg0 ...]);
5558 #
5559 # This method tokenizes the buffer. The options hash may be
5560 # omitted, in which case the $buffer to be tokenized is the first
5561 # argument. After the buffer is an optional reference to an array
5562 # of arguments to be substituted in.
5563 #
5564 # This method attempts to parse and tokenize the buffer in a way
5565 # similar to the bash shell. That is, parameters are interpolated
5566 # inside double quotes but not single quotes, tilde expansion
5567 # takes place unless quoted, and spaces delimit tokens only when
5568 # occurring outside quotes.
5569 #
5570 # The back slash character ('\') is an escape character. Inside
5571 # single quotes only the back slash itself and a single quote may
5572 # be escaped. Otherwise, anything can be escaped.
5573 #
5574 # The returns are a reference to an array of tokens found, and a
5575 # reference to a hash of redirections found. This hash will have
5576 # zero or more of the keys '>' (standard output redirection) and
5577 # '<' (standard input redirection. The value of each key will be a
5578 # reference to a hash containing keys 'mode' ('>' or '>>' for
5579 # output, '<' or '<<' for input) and 'name' (normally the file
5580 # name).
5581 #
5582 # The recognized options are:
5583 #
5584 # single => 1
5585 # causes the buffer to be interpreted as a single token.
5586 #
5587 # noredirect => 1
5588 # causes redirects to be illegal.
5589 #
5590 # If noredirect is specified, only the $tokens reference is
5591 # returned. If noredirect and single are both specified, the
5592 # parsed and interpolated token is returned.
5593 #
5594 # If interpolation is being done, an unescaped dollar sign
5595 # introduces the interpolation. This works pretty much the same
5596 # way as under bash: if the first character after the dollar sign
5597 # is a left curly bracket, everything to the corresponding right
5598 # curly bracked specifies the interpolation; if not, the rule is
5599 # that word characters specify the interpolation.
5600 #
5601 # A number (i.e. $1) specifies interpolation of an argument.
5602 # Arguments are numbered starting at 1.
5603 #
5604 # Otherwise, if the interpolation names an attribute, the value of
5605 # that attribute is interpolated in, otherwise the named
5606 # environment variable is interpolated in.
5607 #
5608 # Most of the fancier forms of interpolation are suported. In the
5609 # following, word is expanded by recursively calling __tokenize
5610 # with options {single => 1, noredirect => 1}. But unlike bash, we
5611 # make no distinction between unset or null. The ':' can be
5612 # omitted before the '-', '=', '?' or '+', but it does not change
5613 # the functionality.
5614 #
5615 # ${parameter:-word} causes the given word to be substituted if
5616 # the parameter is undefined.
5617 #
5618 # ${parameter:=word} is the same as above, but also causes the
5619 # word to be assigned to the parameter if it is unassigned. Unlike
5620 # bash, this assignment takes place on positional parameters. If
5621 # done on an attribute or environment variable, it causes that
5622 # attribute or environment variable to be set to the given value.
5623 #
5624 # ${parameter:?word} causes the parse to fail with the error
5625 # 'word' if the parameter is undefined.
5626 #
5627 # ${parameter:+word} causes the value of the given word to be used
5628 # if the parameter is defined, otherwise '' is used.
5629 #
5630 # ${parameter:offset} and ${parameter:offset:length} take
5631 # substrings of the parameter value. The offset and length must be
5632 # numeric.
5633  
5634 {
5635  
5636 # Special variables.
5637 # Calling sequence: $special{$name}->(\@args, $relquote)
5638 my %special = (
5639 1 ▶ '0' => sub { return $0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
5640 1 ▶ '#' => sub { return scalar @{ $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
5641 ## '*' => sub { return join ' ', @{ $_[0] } },
5642 ## '@' => sub { return $_[1] ? join( ' ', @{ $_[0] } ) : $_[0] },
5643 4 ▶ '*' => sub { return $_[1] ? join( ' ', @{ $_[0] } ) : $_[0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 2 2 4
5644 11 ▶ '@' => sub { return $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
5645 1 ▶ '$' => sub { return $$ },
Subroutine __ANON__: called CC=1 SCAR=0.0
5646 1 ▶ '_' => sub { return $^X },
Subroutine __ANON__: called CC=1 SCAR=0.0
5647 20 );
5648  
5649 my %case_ctl = (
5650 2 ▶ E => sub { delete $_[0]->{_case_mod} },
Subroutine __ANON__: called CC=1 SCAR=0.0
5651 0 ▶ F => sub { $_[0]->{_case_mod}{case} = sub { fold_case( $_[1] ) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5652 1 ▶ L => sub { $_[0]->{_case_mod}{case} = sub { lc $_[1] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5653 1 ▶ U => sub { $_[0]->{_case_mod}{case} = sub { uc $_[1] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5654 0 ▶ l => sub { $_[0]->{_case_mod}{single} = sub { lcfirst $_[1] } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5655 2 ▶ u => sub { $_[0]->{_case_mod}{single} = sub { ucfirst $_[1] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5656 20 );
5657  
5658 # Leading punctuation that is equivalent to a method.
5659 20 my %command_equivalent = (
5660 '.' => 'source',
5661 '!' => 'system',
5662 );
5663 20 my $command_equiv_re = do {
5664 20 my $keys = join '', sort keys %command_equivalent;
5665 20 qr{ [$keys] }smx;
5666 };
5667  
5668 20 my %escape = (
5669 t => "\t",
5670 n => "\n",
5671 r => "\r",
5672 f => "\f",
5673 b => "\b",
5674 a => "\a",
5675 e => "\e",
5676 );
5677  
5678 381 ▶ sub __tokenize {
Subroutine __tokenize: called CC=113 SCAR=50.1
5679 381 my ($self, @parms) = @_;
5680 381 local $self->{_case_mod} = undef;
5681 381 ▶ my $opt = HASH_REF eq ref $parms[0] ? shift @parms : {};
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $parms[0] ? : 379 2 381
5682 381 my $in = $opt->{in};
5683 381 my $buffer = shift @parms;
5684 381 ▶ $buffer =~ m/ \n \z /smx or $buffer .= "\n";
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ / \n \z /msx or $buffer .= "\n" 35 346 381
5685 381 ▶ my $args = shift @parms || [];
Condition100%2/2
shift @parms || []
l!l
3792
MC/DC100%1/1
shift @parms || []
shift @parms
Truth table100%2/2
A
A= shift @parms
Aresult
11
00
5686 381 my @rslt = ( {} );
5687 381 my $absquote; # True if inside ''
5688 my $relquote; # True if inside "" (and not in '')
5689 381 my $len = length $buffer;
5690 381 my $inx = 0;
5691  
5692 # Because I'm not smart enough to do all this with a regular
5693 # expression, I take the brute force approach and iterate
5694 # through the buffer to be tokenized. It's a 'while' rather than
5695 # a 'for' or 'foreach' because that way I get to muck around
5696 # with the current position inside the loop.
5697  
5698 381 ▶ while ($inx < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx < $len) 6313 374 6687
5699 6313 my $char = substr $buffer, $inx++, 1;
5700  
5701 # If we're inside single quotes, the only escapable
5702 # characters are single quote and back slash, and all
5703 # characters until the next unescaped single quote go into
5704 # the current token
5705  
5706 6313 ▶ if ( $absquote ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($absquote) { } 621 5692 6313
elsif ($char eq '\\') { } 10 5682 5692
elsif ($char eq q['] and not $relquote) { } 35 5647 5682
elsif ($char eq '"') { } 44 5603 5647
elsif ($char =~ / \s /msx and not $relquote and not $opt->{'single'}) { } 937 4666 5603
elsif ($char eq '$' and $inx < $len) { } 72 4594 4666
elsif ($char =~ / [<>|] /msx) { } 6 4588 4594
elsif (exists $rslt[-1]{'token'} or $relquote) { } 3745 843 4588
elsif ($char eq '~') { } 12 831 843
elsif ($char eq '#') { } 2 829 831
5707 621 ▶ if ( $char eq '\\' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq '\\') { } 0 621 621
elsif ($char eq q[']) { } 34 587 621
5708 0 ▶ if ( (my $next = substr $buffer, $inx, 1) =~
Branch: 1 branch
BranchTrueFalseTotal
if ((my $next = substr($buffer, $inx, 1)) =~ / ['\\] /msx) { } 0 0 0
5709 m/ ['\\] /smx ) {
5710 0 $inx++;
5711 0 $rslt[-1]{token} .= $next;
5712 } else {
5713 0 $rslt[-1]{token} .= $char;
5714 }
5715 } elsif ( $char eq q{'} ) {
5716 34 $absquote = undef;
5717 } else {
5718 587 $rslt[-1]{token} .= $char;
5719 587 ▶ if ( $inx >= $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx >= $len) 2 585 587
5720 2 $buffer .= $self->_read_continuation( $in,
5721 'Unclosed single quote' );
5722 1 $len = length $buffer;
5723 }
5724 }
5725  
5726 # If we have a backslash, it escapes the next character,
5727 # which goes on the current token no matter what it is.
5728  
5729 } elsif ( $char eq '\\' ) {
5730 10 my $next = substr $buffer, $inx++, 1;
5731 10 ▶ if ( $inx >= $len ) { # At end of line
Branch: 2 branches
BranchTrueFalseTotal
if ($inx >= $len) { } 2 8 10
elsif ($relquote) { } 7 1 8
5732 2 ▶ if ( $relquote ) { # Inside ""
Branch: 1 branch
BranchTrueFalseTotal
if ($relquote) { } 0 2 2
5733 0 $buffer .= $self->_read_continuation( $in,
5734 'Unclosed double quote' );
5735 } else { # Between tokens
5736 2 $buffer .= $self->_read_continuation( $in,
5737 'Dangling continuation' );
5738 2 ▶ $opt->{single} or push @rslt, {}; # New token
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"single"} or push @rslt, {} 0 2 2
5739 }
5740 2 $len = length $buffer;
5741 } elsif ( $relquote ) {
5742 7 ▶ if ( my $code = $case_ctl{$next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $case_ctl{$next}) { } 6 1 7
5743 6 $code->( $self );
5744 } else {
5745 1 ▶ $rslt[-1]{token} .= $escape{$next} || $next;
Condition33%1/3
$escape{$next} || $next
l!l&&r!l&&!r
100
MC/DC0%0/2
$escape{$next} || $next
$escape{$next} $next
Truth table33%1/3
A || B
A= $escape{$next}B= $next
ABresult
1X1
011
000
5746 }
5747 } else {
5748 1 $rslt[-1]{token} .= $next;
5749 }
5750  
5751 # If we have a single quote and we're not inside double
5752 # quotes, we go into absolute quote mode. We also append an
5753 # empty string to the current token to force its value to be
5754 # defined; otherwise empty quotes do not generate tokens.
5755  
5756 ▶ } elsif ($char eq q{'} && !$relquote) {
Condition66%2/3
$char eq "'" and not $relquote
!ll&&!rl&&r
5647035
MC/DC50%1/2
$char eq "'" and not $relquote
$char eq "'" not $relquote
Truth table66%2/3
A and not(B)
A= $char eq "'"B= not $relquote
ABresult
0X0
100
111
5757 35 $rslt[-1]{token} .= ''; # Empty string, to force defined.
5758 35 $absquote++;
5759  
5760 # If we have a double quote, we toggle relative quote mode.
5761 # We also append an empty string to the current tokens for
5762 # the reasons discussed above.
5763  
5764 } elsif ($char eq '"') {
5765 44 $rslt[-1]{token} .= ''; # Empty string, to force defined.
5766 ( $relquote = !$relquote )
5767 44 ▶ or delete $self->{_case_mod};
Branch: 1 branch
BranchTrueFalseTotal
$relquote = !$relquote or delete $self->{"_case_mod"} 22 22 44
5768  
5769 # If we have a whitespace character and we're not inside
5770 # quotes and not in single-token mode, we start a new token.
5771 # It is possible that we generate redundant tokens this way,
5772 # but the unused ones are eliminated later.
5773  
5774 ▶ } elsif ($char =~ m/ \s /smx && !$relquote && !$opt->{single}) {
Condition100%6/6
$char =~ / \s /msx and not $relquote and not $opt->{"single"}
!ll&&!rl&&r
462442937
$char =~ / \s /msx and not $relquote
!ll&&!rl&&r
460123979
MC/DC100%3/3
$char =~ / \s /msx and not $relquote and not $opt->{"single"}
$char =~ / \s /msx not $relquote not $opt->{"single"}
Truth table100%4/4
A and not(B) and not(C)
A= $char =~ / \s /msxB= not $relquoteC= not $opt->{"single"}
ABCresult
0XX0
10X0
1100
1111
5775 937 push @rslt, {};
5776  
5777 # If we have a dollar sign, it introduces parameter
5778 # substitution, a non trivial endeavor.
5779  
5780 ▶ } elsif ( $char eq '$' && $inx < $len ) {
Condition66%2/3
$char eq "\$" and $inx < $len
!ll&&!rl&&r
4594072
MC/DC50%1/2
$char eq "\$" and $inx < $len
$char eq "\$" $inx < $len
Truth table66%2/3
A and B
A= $char eq "\$"B= $inx < $len
ABresult
0X0
100
111
5781 72 my $name = substr $buffer, $inx++, 1;
5782 72 my $brkt;
5783  
5784 # Names beginning with brackets are special. We note the
5785 # fact and scan for the matching close bracket, throwing
5786 # an exception if we do not have one.
5787  
5788 72 ▶ if ($name eq '{' && $inx < $len) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq '{' and $inx < $len) { } 34 38 72
elsif ($name =~ / \A [[:alpha:]_] \z /msx) { } 21 17 38
Condition66%2/3
$name eq "{" and $inx < $len
!ll&&!rl&&r
38034
MC/DC50%1/2
$name eq "{" and $inx < $len
$name eq "{" $inx < $len
Truth table66%2/3
A and B
A= $name eq "{"B= $inx < $len
ABresult
0X0
100
111
5789 34 $brkt = 1;
5790 34 $name = '';
5791 34 my $nest = 1;
5792 34 ▶ while ($inx < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx < $len) 369 1 370
5793 369 $char = substr $buffer, $inx++, 1;
5794 369 ▶ if ($char eq '{') {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq '{') { } 0 369 369
elsif ($char eq '}') { } 33 336 369
5795 0 $nest++;
5796 } elsif ($char eq '}') {
5797 33 ▶ --$nest or last;
Branch: 1 branch
BranchTrueFalseTotal
--$nest or last 0 33 33
5798 }
5799 336 $name .= $char;
5800 }
5801 34 ▶ $char eq '}'
Branch: 1 branch
BranchTrueFalseTotal
$char eq "}" or $self->wail("Missing right curly bracket") 33 1 34
5802 or $self->wail('Missing right curly bracket');
5803  
5804 # If the name begins with an alpha or an underscore, we
5805 # simply append any word ('\w') characters to it. If it
5806 # the word characters are immediately followed by a dot
5807 # and more word characters we grab them too, and advance
5808 # the current location past whatever we grabbed. The dot
5809 # syntax is in aid of accessing attributes of
5810 # attributes (e.g. $formatter.time_format)
5811  
5812 } elsif ( $name =~ m/ \A [[:alpha:]_] \z /smx ) {
5813 21 pos( $buffer ) = $inx;
5814 21 ▶ if ( $buffer =~ m/ \G ( \w* (?: [.] \w+ )? ) /smxgc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ / \G ( \w* (?: [.] \w+ )? ) /cgmsx) 21 0 21
5815 21 $name .= $1;
5816 21 $inx += length $1;
5817 }
5818 }
5819  
5820 # Only bracketed names can be indirected, and then only
5821 # if the first character is a bang.
5822  
5823 71 my ($indirect, $value);
5824 71 ▶ $brkt and $indirect = $name =~ s/ \A ! //smx;
Branch: 1 branch
BranchTrueFalseTotal
$brkt and $indirect = $name =~ s/ \A ! //msx 33 38 71
5825  
5826 # If we find a colon and/or one of the other cabbalistic
5827 # characters, we need to do some default processing.
5828  
5829 71 ▶ if ($name =~ m/ (.*?) ( [:]? [\-\+\=\?] | [:] ) (.*) /smx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ / (.*?) ( [:]? [\-\+\=\?] | [:] ) (.*) /msx) { } 28 43 71
5830 28 my ($name, $flag, $rest) = ($1, $2, $3);
5831  
5832 # First we do indirection if that was required.
5833  
5834 28 ▶ $indirect
Branch: 1 branch
BranchTrueFalseTotal
$indirect and $name = $self->_tokenize_var($name, $args, $relquote, $indirect) 0 28 28
5835 and $name = $self->_tokenize_var(
5836 $name, $args, $relquote, $indirect);
5837  
5838 # Next we find out whether we have an honest-to-God
5839 # colon, since that might specify substring
5840 # processing.
5841  
5842 ## my $colon = $flag =~ s/ \A : //smx ? ':' : '';
5843 28 $flag =~ s/ \A : //smx;
5844  
5845 # We run the stuff after the first cabbalistic
5846 # character through the tokenizer, since further
5847 # expansion is possible here.
5848  
5849 28 my $mod = __tokenize(
5850 $self,
5851 { single => 1, noredirect => 1, in => $in },
5852 $rest, $args);
5853 28 chomp $mod; # Don't want trailing \n here.
5854  
5855 # At long last we get the actual value of the
5856 # variable. This will be either undef, a scalar, or
5857 # a list reference.
5858  
5859 28 $value = $self->_tokenize_var(
5860 $name, $args, $relquote);
5861  
5862 # The value is logically defined if it is a scalar
5863 # and not undef, or if it is an array reference and
5864 # the array is not empty.
5865  
5866 28 ▶ my $defined = ref $value ? @$value : defined $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 4 24 28
5867  
5868 # The '+' cabbalistic sign replaces the value of the
5869 # variable if it is logically defined.
5870  
5871 28 ▶ if ($flag eq '+') {
Branch: 6 branches
BranchTrueFalseTotal
if ($flag eq '+') { } 4 24 28
elsif ($defined) { } 16 8 24
elsif ($flag eq '-') { } 2 6 8
elsif ($flag eq '=') { } 3 3 6
elsif ($flag eq '?') { } 2 1 3
elsif ($flag eq '') { } 1 0 1
5872 4 ▶ $value = $defined ? $mod : '';
Branch: 1 branch
BranchTrueFalseTotal
$defined ? : 2 2 4
5873  
5874 # If the variable is defined, only substring
5875 # processing is possible. This actually is
5876 # implemented as slice processing if the value is an
5877 # array reference.
5878  
5879 } elsif ($defined) {
5880 16 ▶ if ($flag eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq "") 10 6 16
5881 10 my @pos = split ':', $mod, 2;
5882 10 foreach ( @pos ) {
5883 18 s/ \A \s+ //smx;
5884 }
5885 10 ▶ @pos > 2
Branch: 1 branch
BranchTrueFalseTotal
@pos > 2 and $self->wail("Substring expansion has extra arguments") 0 10 10
5886 and $self->wail(
5887 'Substring expansion has extra arguments' );
5888 10 foreach ( @pos ) {
5889 18 ▶ m/ \A [-+]? [0-9]+ \z /smx
Branch: 1 branch
BranchTrueFalseTotal
/ \A [-+]? [0-9]+ \z /msx or $self->wail("Substring expansion argument non-numeric") 18 0 18
5890 or $self->wail(
5891 'Substring expansion argument non-numeric'
5892 );
5893 }
5894 10 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 4 6 10
5895 4 ▶ if (@pos > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pos > 1) { } 4 0 4
5896 4 $pos[1] += $pos[0] - 1;
5897 } else {
5898 0 $pos[1] = $#$args;
5899 }
5900 4 ▶ $pos[1] > $#$value and $pos[1] = $#$value;
Branch: 1 branch
BranchTrueFalseTotal
$pos[1] > $value->$#* and $pos[1] = $value->$#* 2 2 4
5901 4 $value = [@$value[$pos[0] .. $pos[1]]];
5902 } else {
5903 # We want to disable warnings if we slop
5904 # outside the string.
5905 20 ▶ no warnings qw{substr};
Subroutine BEGIN: called CC=1 SCAR=0.0
5906 6 ▶ $value = @pos == 1 ? substr $value, $pos[0] :
Branch: 1 branch
BranchTrueFalseTotal
@pos == 1 ? : 2 4 6
5907 substr $value, $pos[0], $pos[1];
5908 }
5909 }
5910  
5911 # If the cabbalistic sign is '-', we supply the
5912 # remainder of the specification as the default.
5913  
5914 } elsif ($flag eq '-') {
5915 2 $value = $mod;
5916  
5917 # If the cabbalistic sign is '=', we supply the
5918 # remainder of the specification as the default. We
5919 # also set the variable to the value, for future
5920 # use. Note that special variables may not be set,
5921 # and result in an exception.
5922  
5923 } elsif ($flag eq '=') {
5924 3 $value = $mod;
5925 3 ▶ if ( $special{$name} || $name !~ m/ \D /smx ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($special{$name} or not $name =~ / \D /msx) { } 0 3 3
elsif (exists $mutator{$name}) { } 0 3 3
Condition33%1/3
$special{$name} or not $name =~ / \D /msx
l!l&&r!l&&!r
003
MC/DC0%0/2
$special{$name} or not $name =~ / \D /msx
$special{$name} not $name =~ / \D /msx
Truth table33%1/3
A or not(B)
A= $special{$name}B= not $name =~ / \D /msx
ABresult
1X1
011
000
5926 0 $self->wail("Cannot assign to \$$name");
5927 ## } elsif ($name !~ m/\D/) {
5928 ## $args->[$name - 1] = $value;
5929 } elsif (exists $mutator{$name}) {
5930 0 $self->set($name => $value);
5931 } else {
5932 3 $self->{frame}[-1]{define}{$name} = $value;
5933 }
5934  
5935 # If the cabbalistic sign is '?', we throw an
5936 # exception with the remainder of the specification
5937 # as the text.
5938  
5939 } elsif ($flag eq '?') {
5940 2 $self->wail($mod);
5941  
5942 # If there is no cabbalistic sign at all, we fell
5943 # through here trying to do substring expansion on
5944 # an undefined variable. Since Bash allows this, we
5945 # will to, though with misgivings.
5946  
5947 } elsif ( $flag eq '' ) {
5948 1 $value = '';
5949  
5950 # Given the way the parser works, the above should
5951 # have exhausted all possibilities. But being a
5952 # cautious programmer ...
5953  
5954 } else {
5955 0 $self->weep(
5956 "\$flag = '$flag'. This should not happen"
5957 );
5958 }
5959  
5960 # Without any cabbalistic signs, variable expansion is
5961 # easy. We perform the indirection if needed, and then
5962 # grab the value of the variable, which still can be
5963 # undef, a scalar, or an array reference.
5964  
5965 } else {
5966 43 ▶ $indirect
Branch: 1 branch
BranchTrueFalseTotal
$indirect and $name = $self->_tokenize_var($name, $args, $relquote, $indirect) 3 40 43
5967 and $name = $self->_tokenize_var(
5968 $name, $args, $relquote, $indirect);
5969 43 $value = $self->_tokenize_var(
5970 $name, $args, $relquote);
5971 }
5972  
5973 # For simplicity in what follows, make the value into an
5974 # array reference.
5975 69 ▶ ref $value
Branch: 2 branches
BranchTrueFalseTotal
ref $value or $value = defined $value ? [$value] : [] 13 56 69
defined $value ? : 49 7 56
5976 or $value = defined $value ? [ $value ] : [];
5977  
5978 # If we are inside quotes
5979 69 ▶ if ( $relquote ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relquote) { } 12 57 69
5980 # do case modification
5981 # NOTE that the argument list is modified in-place.
5982 12 $self->_case_mod( @{ $value } );
5983 } else {
5984 # otherwise do word splitting
5985 57 $value = [ map { split qr{ \s+ }smx } @{ $value } ];
5986 }
5987  
5988 # If we have a value, append each element to the current
5989 # token, and then create a new token for the next
5990 # element. The last element's empty token gets
5991 # discarded, since we may need to append more data to
5992 # the last element (e.g. "$@ foo").
5993 69 ▶ if ( @{ $value } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$value;}) 58 11 69
5994 58 foreach ( @$value ) {
5995 86 $rslt[-1]{token} .= $_;
5996 86 push @rslt, {};
5997 }
5998 58 pop @rslt;
5999 }
6000  
6001 # Here ends the variable expansion code.
6002  
6003 # If the character is an angle bracket or a pipe, we have a
6004 # redirect specification. This always starts a new token. We
6005 # flag the token as a redirect, stuff all matching
6006 # characters into the mode (throwing an exception if there
6007 # are too many), consume any trailing spaces, and set the
6008 # token value to the empty string to prevent executing this
6009 # code again when we hit the first character of the file
6010 # name. Note that redirect tokens always get tilde
6011 # expansion.
6012  
6013 } elsif ( $char =~ m/ [<>|] /smx ) {
6014 6 ▶ push @rslt, {
Branch: 2 branches
BranchTrueFalseTotal
$char eq '<' ? : 4 2 6
$char eq '|' ? : 0 6 6
6015 redirect => 1,
6016 type => ($char eq '<' ? '<' : '>'),
6017 mode => ($char eq '|' ? '|-' : $char),
6018 expand => ($char ne '|')
6019 };
6020 6 ▶ while ($inx < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx < $len) 11 0 11
6021 11 my $next = substr $buffer, $inx++, 1;
6022 11 ▶ $next =~ m/ \s /smx and next;
Branch: 1 branch
BranchTrueFalseTotal
$next =~ / \s /msx and next 0 11 11
6023 11 ▶ if ($next eq $char) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next eq $char) { } 6 5 11
6024 6 $rslt[-1]{mode} .= $next;
6025 6 ▶ length $rslt[-1]{mode} > 2
Branch: 1 branch
BranchTrueFalseTotal
length $rslt[-1]{"mode"} > 2 and $self->wail(qq[Syntax error near $rslt[-1]{"mode"}]) 1 5 6
6026 and $self->wail(
6027 "Syntax error near $rslt[-1]{mode}");
6028 } else {
6029 5 --$inx;
6030 5 $rslt[-1]{token} = '';
6031 5 last;
6032 }
6033 }
6034 5 ▶ if ( '<<' eq $rslt[-1]{mode} ) { # Heredoc
Branch: 1 branch
BranchTrueFalseTotal
if ("<<" eq $rslt[-1]{"mode"}) 4 1 5
6035 4 delete $rslt[-1]{redirect};
6036 4 delete $rslt[-1]{type};
6037 4 delete $rslt[-1]{mode};
6038 4 my $quote = '';
6039 4 ▶ while ( $inx < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx < $len) 62 0 62
6040 62 my $next = substr $buffer, $inx++, 1;
6041 62 ▶ if ( $next =~ m/ \s /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ / \s /msx) { } 2 60 62
6042 2 ▶ $quote or last;
Branch: 1 branch
BranchTrueFalseTotal
$quote or last 0 2 2
6043 0 $rslt[-1]{token} .= $next;
6044 } else {
6045 '' eq $rslt[-1]{token}
6046 and $next =~ m/ ['"] /smx
6047 and $quote = $next
6048 60 ▶ or $rslt[-1]{token} .= $next;
Branch: 1 branch
BranchTrueFalseTotal
"" eq $rslt[-1]{"token"} and $next =~ / ['"] /msx and $quote = $next or $rslt[-1]{"token"} .= $next 2 58 60
Condition83%5/6
"" eq $rslt[-1]{"token"} and $next =~ / ['"] /msx and $quote = $next
!ll&&!rl&&r
5802
"" eq $rslt[-1]{"token"} and $next =~ / ['"] /msx
!ll&&!rl&&r
5442
MC/DC66%2/3
"" eq $rslt[-1]{"token"} and $next =~ / ['"] /msx and $quote = $next
"" eq $rslt[-1]{"token"} $next =~ / ['"] /msx $quote = $next
Truth table75%3/4
A and B and C
A= "" eq $rslt[-1]{"token"}B= $next =~ / ['"] /msxC= $quote = $next
ABCresult
0XX0
10X0
1100
1111
6049 $quote
6050 and $next eq $quote
6051 60 ▶ and $rslt[-1]{token} ne ''
Branch: 1 branch
BranchTrueFalseTotal
$quote and $next eq $quote and $rslt[-1]{"token"} ne "" and last 2 58 60
Condition100%6/6
$quote and $next eq $quote and $rslt[-1]{"token"} ne ""
!ll&&!rl&&r
5622
$quote and $next eq $quote
!ll&&!rl&&r
26304
MC/DC100%3/3
$quote and $next eq $quote and $rslt[-1]{"token"} ne ""
$quote $next eq $quote $rslt[-1]{"token"} ne ""
Truth table100%4/4
A and B and C
A= $quoteB= $next eq $quoteC= $rslt[-1]{"token"} ne ""
ABCresult
0XX0
10X0
1100
1111
6052 and last;
6053 }
6054 }
6055 4 ▶ $quote and $rslt[-1]{token} =~ s/ . \z //sxm;
Branch: 1 branch
BranchTrueFalseTotal
$quote and $rslt[-1]{"token"} =~ s/ . \z //msx 2 2 4
6056 4 my $terminator = $rslt[-1]{token};
6057 4 my $look_for = $terminator . "\n";
6058 4 $rslt[-1]{token} = '';
6059 4 $rslt[-1]{expand} = $quote ne q<'>;
6060 4 while ( 1 ) {
6061 9 my $buffer = $self->_read_continuation( $in,
6062 "Here doc terminator $terminator not found" );
6063 9 ▶ $buffer eq $look_for and last;
Branch: 1 branch
BranchTrueFalseTotal
$buffer eq $look_for and last 4 5 9
6064 5 $rslt[-1]{token} .= $buffer;
6065 }
6066 4 ▶ if ( $quote ne q<'> ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote ne "'") 3 1 4
6067 $rslt[-1]{token} = __tokenize(
6068 $self,
6069 { single => 1, noredirect => 1, in => $in },
6070 3 $rslt[-1]{token}, $args
6071 );
6072 }
6073 4 push @rslt, {}; # New token
6074 }
6075  
6076 # If the token already exists at this point, the current
6077 # character, whatever it is, is simply appended to it.
6078  
6079 ▶ } elsif (exists $rslt[-1]{token} || $relquote) {
Condition66%2/3
exists $rslt[-1]{"token"} or $relquote
l!l&&r!l&&!r
37450843
MC/DC50%1/2
exists $rslt[-1]{"token"} or $relquote
exists $rslt[-1]{"token"} $relquote
Truth table66%2/3
A or B
A= exists $rslt[-1]{"token"}B= $relquote
ABresult
1X1
011
000
6080 # do case modification
6081 # NOTE that the argument list is modified in-place.
6082 3745 $self->_case_mod( $char );
6083 3745 $rslt[-1]{token} .= $char;
6084  
6085 # If the character is a tilde, we flag the token for tilde
6086 # expansion.
6087  
6088 } elsif ($char eq '~') {
6089 12 $rslt[-1]{tilde}++;
6090 12 $rslt[-1]{token} .= $char;
6091  
6092 # If the character is a hash mark, it means a comment. Bail
6093 # out of the loop.
6094 } elsif ( $char eq '#' ) {
6095 2 last;
6096  
6097 # Else we just put it in the token.
6098 } else {
6099 829 $rslt[-1]{token} .= $char;
6100 }
6101  
6102 # If we're at the end of the buffer but we're inside quotes,
6103 # we need to read another line.
6104 6306 ▶ if ( $inx >= $len && ( $absquote || $relquote ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx >= $len and $absquote || $relquote) 2 6304 6306
Condition83%5/6
$inx >= $len and $absquote || $relquote
!ll&&!rl&&r
59303742
$absquote or $relquote
l!l&&r!l&&!r
02374
MC/DC66%2/3
$inx >= $len and $absquote || $relquote
$inx >= $len $absquote $relquote
Truth table75%3/4
A and B or C
A= $inx >= $lenB= $absquoteC= $relquote
ABCresult
0XX0
1000
11X1
1011
6105 2 ▶ $buffer .= $self->_read_continuation( $in,
Branch: 1 branch
BranchTrueFalseTotal
$absquote ? : 0 2 2
6106 $absquote ? 'Unclosed single quote' :
6107 'Unclosed double quote'
6108 );
6109 2 $len = length $buffer;
6110 }
6111  
6112 }
6113  
6114 # We have run through the entire string to be tokenized. If
6115 # there are unclosed quotes of either sort, we declare an error
6116 # here. This should actually not happen, since we allow
6117 # multi-line quotes, and if we have run out of input we catch it
6118 # above.
6119  
6120 376 ▶ $absquote and $self->wail( 'Unclosed terminal single quote' );
Branch: 1 branch
BranchTrueFalseTotal
$absquote and $self->wail("Unclosed terminal single quote") 0 376 376
6121 376 ▶ $relquote and $self->wail( 'Unclosed terminal double quote' );
Branch: 1 branch
BranchTrueFalseTotal
$relquote and $self->wail("Unclosed terminal double quote") 0 376 376
6122  
6123 # Replace leading punctuation with the corresponding method.
6124  
6125 shift @rslt
6126 376 ▶ while @rslt && ! defined $rslt[0]{token};
Branch: 1 branch
BranchTrueFalseTotal
@rslt and not defined $rslt[0]{"token"} and do { shift @rslt } 32 376 408
Condition100%3/3
@rslt and not defined $rslt[0]{"token"}
!ll&&!rl&&r
637032
MC/DC100%2/2
@rslt and not defined $rslt[0]{"token"}
@rslt not defined $rslt[0]{"token"}
Truth table100%3/3
A and not(B)
A= @rsltB= not defined $rslt[0]{"token"}
ABresult
0X0
100
111
6127 376 ▶ if ( defined $rslt[0]{token} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rslt[0]{"token"} and $rslt[0]{"token"} =~ s/ \A ( $command_equiv_re ) //msx) 0 376 376
Condition66%2/3
defined $rslt[0]{"token"} and $rslt[0]{"token"} =~ s/ \A ( $command_equiv_re ) //msx
!ll&&!rl&&r
63700
MC/DC0%0/2
defined $rslt[0]{"token"} and $rslt[0]{"token"} =~ s/ \A ( $command_equiv_re ) //msx
defined $rslt[0]{"token"} $rslt[0]{"token"} =~ s/ \A ( $command_equiv_re ) //msx
Truth table66%2/3
A and B
A= defined $rslt[0]{"token"}B= $rslt[0]{"token"} =~ s/ \A ( $command_equiv_re ) //msx
ABresult
0X0
100
111
6128 $rslt[0]{token} =~ s/ \A ( $command_equiv_re ) //smx ) {
6129 0 ▶ if ( $rslt[0]{token} eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rslt[0]{'token'} eq '') { } 0 0 0
elsif ($opt->{'single'}) { } 0 0 0
6130 0 $rslt[0]{token} = $command_equivalent{$1};
6131 } elsif ( $opt->{single} ) {
6132 $rslt[0]{token} = join ' ', $command_equivalent{$1},
6133 0 $rslt[0]{token};
6134 } else {
6135 unshift @rslt, {
6136 0 token => $command_equivalent{$1},
6137 };
6138 }
6139 }
6140  
6141 # Go through our prospective tokens, keeping only those that
6142 # were actually defined, and shuffling the redirects off into
6143 # the redirect hash.
6144  
6145 376 my (@tokens, %redir);
6146 376 my $expand_tildes = 1;
6147 376 ▶ if ( defined $rslt[0]{token}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rslt[0]{"token"} and my $kode = $self->can($rslt[0]{"token"})) 252 124 376
Condition100%3/3
defined $rslt[0]{"token"} and my $kode = $self->can($rslt[0]{"token"})
!ll&&!rl&&r
6118252
MC/DC100%2/2
defined $rslt[0]{"token"} and my $kode = $self->can($rslt[0]{"token"})
defined $rslt[0]{"token"} my $kode = $self->can($rslt[0]{"token"})
Truth table100%3/3
A and B
A= defined $rslt[0]{"token"}B= my $kode = $self->can($rslt[0]{"token"})
ABresult
0X0
100
111
6148 and my $kode = $self->can( $rslt[0]{token} ) ) {
6149 252 ▶ if ( my $hash = $self->__get_attr( $kode, 'Tokenize' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hash = $self->__get_attr($kode, "Tokenize")) 2 250 252
6150 2 $expand_tildes = $hash->{expand_tilde};
6151 }
6152 }
6153 376 foreach (@rslt) {
6154 1318 ▶ exists $_->{token} or next;
Branch: 1 branch
BranchTrueFalseTotal
exists $_->{"token"} or next 966 352 1318
6155 966 ▶ if ($_->{redirect}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->{'redirect'}) { } 1 965 966
elsif ($expand_tildes and $_->{'tilde'}) { } 12 953 965
6156 1 ▶ if ( $_->{mode} eq '<' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{'mode'} eq '<') { } 0 1 1
6157 push @tokens, $self->_file_reader(
6158 0 $_->{token}, { glob => 1 } );
6159 } else {
6160 1 my $type = $_->{type};
6161 $redir{$type} = {
6162 mode => $_->{mode},
6163 name => ($_->{expand} ?
6164 $self->expand_tilde($_->{token}) :
6165 1 ▶ $_->{token}),
Branch: 1 branch
BranchTrueFalseTotal
$_->{'expand'} ? : 1 0 1
6166 };
6167 }
6168 ▶ } elsif ( $expand_tildes && $_->{tilde} ) {
Condition100%3/3
$expand_tildes and $_->{"tilde"}
!ll&&!rl&&r
594812
MC/DC100%2/2
$expand_tildes and $_->{"tilde"}
$expand_tildes $_->{"tilde"}
Truth table100%3/3
A and B
A= $expand_tildesB= $_->{"tilde"}
ABresult
0X0
100
111
6169 12 push @tokens, $self->expand_tilde( $_->{token} );
6170 } else {
6171 953 push @tokens, $_->{token};
6172 }
6173 }
6174  
6175 # With the {single} and {noredirect} options both asserted,
6176 # there is only one token, so we return it directly.
6177  
6178 372 ▶ ($opt->{single} && $opt->{noredirect}) and return $tokens[0];
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"single"} and $opt->{"noredirect"} and return $tokens[0] 31 341 372
Condition66%2/3
$opt->{"single"} and $opt->{"noredirect"}
!ll&&!rl&&r
341031
MC/DC50%1/2
$opt->{"single"} and $opt->{"noredirect"}
$opt->{"single"} $opt->{"noredirect"}
Truth table66%2/3
A and B
A= $opt->{"single"}B= $opt->{"noredirect"}
ABresult
0X0
100
111
6179  
6180 # With the {noredirect} option asserted, we just return a
6181 # reference to the tokens found.
6182  
6183 341 ▶ $opt->{noredirect} and return \@tokens;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{"noredirect"} and return \@tokens 0 341 341
6184  
6185 # Otherwise we return a list, with a reference to the token list
6186 # as the first element, and a reference to the redirect hash as
6187 # the second element.
6188  
6189 341 return (\@tokens, \%redir);
6190 }
6191  
6192 # Retrieve the value of a variable.
6193 74 ▶ sub _tokenize_var {
Subroutine _tokenize_var: called CC=13 SCAR=26.8
6194 74 my ($self, $name, $args, $relquote, $indirect) = @_;
6195  
6196 74 ▶ defined $name and $name ne ''
Branch: 2 branches
BranchTrueFalseTotal
defined $name and $name ne "" or return $indirect ? "" : undef 74 0 74
$indirect ? : 0 0 0
Condition33%1/3
defined $name and $name ne ""
!ll&&!rl&&r
0074
MC/DC0%0/2
defined $name and $name ne ""
defined $name $name ne ""
Truth table33%1/3
A and B
A= defined $nameB= $name ne ""
ABresult
0X0
100
111
6197 or return $indirect ? '' : undef;
6198  
6199 74 ▶ $special{$name} and do {
Branch: 1 branch
BranchTrueFalseTotal
$special{$name} and do { my $val = $special{$name}->($args, $relquote); return $indirect && ref $val ? "" : $val } 19 55 74
6200 19 my $val = $special{$name}->($args, $relquote);
6201 19 ▶ return ($indirect && ref $val) ? '' : $val;
Branch: 1 branch
BranchTrueFalseTotal
$indirect && ref $val ? : 0 19 19
Condition33%1/3
$indirect and ref $val
!ll&&!rl&&r
1900
MC/DC0%0/2
$indirect and ref $val
$indirect ref $val
Truth table33%1/3
A and B
A= $indirectB= ref $val
ABresult
0X0
100
111
6202 };
6203  
6204 55 ▶ $name !~ m/ \D /smx
Branch: 1 branch
BranchTrueFalseTotal
$name =~ / \D /msx or return $$args[$name - 1] 40 15 55
6205 and return $args->[$name - 1];
6206  
6207 40 my $value = $self->_attribute_value( $name );
6208 40 ▶ NULL_REF eq ref $value
Branch: 1 branch
BranchTrueFalseTotal
"Null" eq ref $value or return $value 34 6 40
6209 or return $value;
6210  
6211 exists $self->{exported}{$name}
6212 34 ▶ and return $self->{exported}{$name};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"exported"}{$name} and return $self->{"exported"}{$name} 2 32 34
6213  
6214 defined $ENV{$name}
6215 32 ▶ and return $ENV{$name};
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{$name} and return $ENV{$name} 18 14 32
6216  
6217 14 foreach my $frame ( reverse @{ $self->{frame} } ) {
6218 defined $frame->{define}{$name}
6219 17 ▶ and return $frame->{define}{$name};
Branch: 1 branch
BranchTrueFalseTotal
defined $frame->{"define"}{$name} and return $frame->{"define"}{$name} 3 14 17
6220 }
6221  
6222 11 return;
6223 }
6224  
6225 }
6226  
6227 # Apply case modification to the arguments
6228 # NOTE that the argument list is modified in-place. I'm a little
6229 # surprised that this didn't tickle Perl::Critic.
6230 20 ▶sub _case_mod {
Subroutine _case_mod: called CC=4 SCAR=13.9
6231 3757 my $self = shift;
6232 3757 foreach ( @_ ) {
6233 $self->{_case_mod}{case}
6234 3760 ▶ and $_ = $self->{_case_mod}{case}->( $self, $_ );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_case_mod"}{"case"} and $_ = $self->{"_case_mod"}{"case"}->($self, $_) 12 3748 3760
6235 3760 my $code;
6236 $code = delete $self->{_case_mod}{single}
6237 3760 ▶ and $_ = $code->( $self, $_ );
Branch: 1 branch
BranchTrueFalseTotal
$code = delete $self->{"_case_mod"}{"single"} and $_ = &$code($self, $_) 2 3758 3760
6238 }
6239 3757 return;
6240 }
6241  
6242 # $self->wail(...)
6243 #
6244 # Either die or croak with the arguments, depending on the value
6245 # of the 'warning' attribute. If we die, a trailing period and
6246 # newline are provided if necessary. If we croak, any trailing
6247 # punctuation and newline are stripped.
6248  
6249 19 ▶sub wail {
Subroutine wail: called CC=1 SCAR=0.4
Pod documented
6250 19 my ($self, @args) = @_;
6251 19 $self->{_warner}->wail( @args );
6252 0 return; # We can't hit this, but Perl::Critic does not know that.
6253 }
6254  
6255 # $self->__wail(...)
6256 #
6257 # either wail() or whinge() depending on error_out.
6258 1 ▶sub __wail {
Subroutine __wail: called CC=2 SCAR=8.4
6259 1 my ($self, @args) = @_;
6260 1 ▶ if ( $self->get( 'error_out' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get('error_out')) { } 1 0 1
6261 1 $self->{_warner}->wail( @args );
6262 } else {
6263 0 $self->{_warner}->whinge( @args );
6264 }
6265 0 return;
6266 }
6267  
6268 # $self->weep(...)
6269 #
6270 # Die with a stack dump (Carp::confess).
6271  
6272 0 ▶sub weep {
Subroutine weep: not called CC=1 SCAR=6.9
Pod documented
6273 0 my ($self, @args) = @_;
6274 0 $self->{_warner}->weep( @args );
6275 0 return; # We can't hit this, but Perl::Critic does not know that.
6276 }
6277  
6278 # $self->whinge(...)
6279 #
6280 # Either warn or carp with the arguments, depending on the value
6281 # of the 'warn' attribute. If we warn, a trailing period and
6282 # newline are provided if necessary. If we carp, any trailing
6283 # punctuation and newline are stripped.
6284  
6285 3 ▶sub whinge {
Subroutine whinge: called CC=1 SCAR=0.0
Pod documented
6286 3 my ($self, @args) = @_;
6287 3 $self->{_warner}->whinge( @args );
6288 3 return;
6289 }
6290  
6291 20 1;
6292  
6293 __END__
↑ Summary blib/lib/Astro/App/Satpass2/ParseTime/Date/Manip/v5.pm »