Tom Wyant
and 1 contributors

NAME

My::Macros - Implement 'macros' using code.

SYNOPSIS

The following assumes this file is actually findable in @INC:

 satpass2> macro load My::Macros
 satpass2> hi Yehudi
 Hello, Yehudi!
 satpass2> angle sun moon -places 2
 102.12
 satpass2>

DESCRIPTION

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.

SUBROUTINES

This class supports the following public subroutines, which are documented as though they are methods of Astro::App::Satpass2:

after_load

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.

This subroutine returns the options (if any) one per line, followed by the arguments, also one per line.

angle

 $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():

-places number

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.

-radians

This option specifies that the angle is to be returned in radians. Otherwise it is returned in degrees.

dumper

 $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.

There are no options.

hi

 $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".

There are no options.

test

 $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.

The following operators are implemented:

and

This operator removes two arguments from the top of the stack, takes the logical and of them, and pushes the result onto the stack.

choose

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.

else

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.

or

This operator removes two arguments from the top of the stack, takes the logical or of them, and pushes the result onto the stack.

not

This operator removes an argument from the top of the stack, logically negates it, and pushes the result onto the stack.

then

This operator requires an argument on the stack, but does not remove it. Instead it causes the Polish notation code to terminate.

There are no options.

SEE ALSO

Astro::App::Satpass2

Astro::App::Satpass2::Macro::Code.

The Code Macros write-up in the TUTORIAL.

SUPPORT

Support is by the author. Please file bug reports at http://rt.cpan.org, or in electronic mail to the author.

AUTHOR

Thomas R. Wyant, III wyant at cpan dot org

COPYRIGHT AND LICENSE

Copyright (C) 2013-2015 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.