My::Macros - Implement 'macros' using code.
The following assumes this file is actually findable in @INC:
@INC
satpass2> macro load My::Macros satpass2> hi Yehudi Hello, Yehudi! satpass2> angle sun moon -places 2 102.12 satpass2>
This Perl package defines code macros for Astro::App::Satpass2. These are implemented as subroutines, but do not appear as methods of Astro::App::Satpass2. Nonetheless, they are defined and called the same way an Astro::App::Satpass2 interactive method is called, and return their results as text.
This class supports the following public subroutines, which are documented as though they are methods of Astro::App::Satpass2:
If this subroutine exists, it will be called after the code macro is successfully loaded, and passed the processed arguments of the macro load command. That is, the first argument (after the invocant) will be the option hash, followed by the non-option arguments in order.
macro load
This subroutine returns the options (if any) one per line, followed by the arguments, also one per line.
$output = $satpass2->dispatch( angle => 'sun', 'moon', 'today noon' ); satpass2> angle sun moon 'today noon'
This subroutine computes and returns the angle between the two named bodies at the given time. The time defaults to the current time.
The following options may be specified, either as command-line-style options or in a hash as the second argument to dispatch():
dispatch()
This option specifies the number of places to display after the decimal. If it is specified, the number of degrees is formatted with sprintf. If not, it is simply interpolated into a string.
sprintf
This option specifies that the angle is to be returned in radians. Otherwise it is returned in degrees.
$output = $satpass2->dispatch( 'dumper', 'foo', 'bar' ); satpass2> dumper foo bar
This subroutine is a diagnostic that displays the class name of its first argument (which under more normal circumstances would be its invocant), and a YAML Dump() of a reference to the array of subsequent arguments.
YAML
Dump()
There are no options.
$output = $satpass2->dispatch( 'hi', 'sailor' ); satpass2> hi sailor Hello sailor!
This subroutine simply returns its optional argument $name (which defaults to 'world') interpolated into the string "Hello, $name\n".
$name
'world'
"Hello, $name\n"
$output = $satpass2->spaceflight( qw{ -all -effective } ); $output .= $satpass2->dispatch( qw{ test 25544 choose else spacetrack retrieve 25544 } ); satpass2> spaceflight -all -full satpass2> test 25544 choose else spacetrack retrieve 25544 # In either of the above cases, the orbital elements come # from Space Track only if they could not be retrieved from # the NASA's Human Space Flight web site.
This subroutine implements conditional logic. Its arguments are a logical expression expressed in reverse Polish notation, and a command to dispatch if the expression is true.
In a reverse Polish system, everything can be evaluated as it is encountered. Operands (in practice, anything not recognized as an operator) are placed on the stack. Operators remove their operands from the stack, and place their results on the stack.
The last operator is either then or else (but not both!). Everything after this is taken as a command, to be dispatched only if the single operand left on the stack has the expected logical value: true for then, or false for else.
then
else
The following operators are implemented:
This operator removes two arguments from the top of the stack, takes the logical and of them, and pushes the result onto the stack.
and
This operator removes an operand from the stack, which is interpreted as a satellite OID or name, or perhaps more than one, comma-delimited. It pushes onto the stack the number of satellites matching any of the names or numbers given. Note that this produces a true value provided any satellites were found.
This operator requires an argument on the stack, but does not remove it. Instead it logically negates it, and causes the Polish notation code to terminate.
This operator removes two arguments from the top of the stack, takes the logical or of them, and pushes the result onto the stack.
or
This operator removes an argument from the top of the stack, logically negates it, and pushes the result onto the stack.
This operator requires an argument on the stack, but does not remove it. Instead it causes the Polish notation code to terminate.
Astro::App::Satpass2
Astro::App::Satpass2::Macro::Code.
The Code Macros write-up in the TUTORIAL.
Support is by the author. Please file bug reports at http://rt.cpan.org, or in electronic mail to the author.
Thomas R. Wyant, III wyant at cpan dot org
Copyright (C) 2013-2017 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Astro::App::Satpass2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Astro::App::Satpass2
CPAN shell
perl -MCPAN -e shell install Astro::App::Satpass2
For more information on module installation, please visit the detailed CPAN module installation guide.