File Coverage

eg/My/Macros.pm
Criterion Covered Total %
statement 66 130 50.7
branch 0 26 0.0
condition 0 14 0.0
subroutine 23 28 82.1
pod n/a
total 89 198 44.9


line stmt bran cond sub pod time code
1             package My::Macros;
2              
3 1     1   24 use 5.008;
  1         4  
4              
5 1     1   12 use strict;
  1         1  
  1         21  
6 1     1   4 use warnings;
  1         2  
  1         27  
7              
8 1     1   4 use parent qw{ Astro::App::Satpass2 };
  1         1  
  1         6  
9              
10 1     1   65 use Astro::App::Satpass2::Utils qw{ __arguments };
  1         2  
  1         68  
11 1     1   6 use Astro::Coord::ECI::Utils 0.059 qw{ rad2deg };
  1         15  
  1         50  
12 1     1   7 use Attribute::Handlers;
  1         18  
  1         11  
13 1     1   39 use Scalar::Util 1.26 qw{ refaddr };
  1         15  
  1         134  
14              
15             our $VERSION = '0.052';
16              
17             {
18             my %operands;
19              
20             sub Operands : ATTR(CODE,RAWDATA) {
21 6     6   1447 my ( undef, undef, $code, $name, $data ) = @_;
22 6         22 $operands{$code}{$name} = 0 + $data;
23 6         14 return;
24 1     1   7 }
  1         2  
  1         23  
25              
26             sub operands {
27 0     0     my ( $code ) = @_;
28 0 0 0       return defined $code ? $operands{$code} || 0 : \%operands;
29             }
30             }
31              
32             sub after_load : Verb() {
33 0     0   0 my ( undef, $opt, @args ) = @_; # Invocant unused
34 0         0 my $rslt;
35 0         0 foreach my $key ( keys %{ $opt } ) {
  0         0  
36 0         0 $rslt .= "-$key $opt->{$key}\n";
37             }
38 0         0 foreach my $val ( @args ) {
39 0         0 $rslt .= "$val\n";
40             }
41 0         0 return $rslt;
42 1     1   625 }
  1         3  
  1         4  
43              
44             sub angle : Verb( radians! places=i ) {
45 0     0   0 my ( $self, $opt, $name1, $name2, $time ) = __arguments( @_ );
46 0         0 $time = $self->__parse_time( $time, time );
47 0 0 0     0 defined $name1
48             and defined $name2
49             or $self->wail( 'Two names or OIDs must be provided' );
50 0         0 my @things = $self->__choose(
51             { bodies => 1, sky => 1 },
52             [ $name1, $name2 ],
53             );
54             @things
55 0 0       0 or $self->wail( 'No bodies chosen' );
56 0 0       0 @things < 2
57             and $self->wail( 'Only 1 body (',
58             $things[0]->get( 'name' ),
59             ') chosen' );
60 0 0       0 @things > 2
61             and $self->wail( scalar @things, ' bodies chosen' );
62 0         0 my $station = $self->station()->universal( $time );
63 0         0 foreach my $body ( @things ) {
64 0         0 $body->universal( $time );
65             }
66 0         0 my $angle = $station->angle( @things );
67             $opt->{radians}
68 0 0       0 or $angle = rad2deg( $angle );
69             defined $opt->{places}
70 0 0       0 or return "$angle\n";
71 0         0 return sprintf "%.*f\n", $opt->{places}, $angle;
72 1     1   390 }
  1         12  
  1         38  
73              
74             sub hi : Verb() {
75 0     0   0 my ( undef, undef, $name ) = __arguments( @_ );
76 0 0       0 defined $name
77             or $name = 'world';
78 0         0 return "Hello, $name!\n";
79 1     1   227 }
  1         1  
  1         5  
80              
81             {
82             my %operator = (
83             and => sub : Operands(2) {
84 0         0 my ( undef, $stack ) = @_; # Invocant unused
85 0   0     0 push @{ $stack }, pop @{ $stack } && pop @{ $stack };
  0         0  
86 0         0 return;
87 1     1   228 },
  1         1  
  1         4  
88             choose => sub : Operands(1) {
89 0         0 my ( $self, $stack ) = @_;
90             # We want the number of bodies, but __choose(), for better
91             # or worse, provides a reference to the array of bodies in
92             # scalar context. So the empty parens provide list context
93             # to __choose(), hiding the fact that ultimately we do a
94             # scalar assign.
95             my $count = () = $self->__choose(
96             { bodies => 1 },
97 0         0 [ pop @{ $stack } ],
  0         0  
98             );
99 0         0 push @{ $stack }, $count;
  0         0  
100 0         0 return;
101 1     1   205 },
  1         2  
  1         3  
102             else => sub : Operands(1) {
103 0         0 my ( undef, $stack ) = @_; # Invocant unused
104 0         0 $stack->[-1] = ! $stack->[-1];
105 1     1   167 no warnings qw{ exiting };
  1         4  
  1         118  
106 0         0 last TEST_LOOP;
107 1     1   9 },
  1         1  
  1         4  
108             not => sub : Operands(1) {
109 0         0 my ( undef, $stack ) = @_; # Invocant unused
110 0         0 $stack->[-1] = ! $stack->[-1];
111 0         0 return;
112 1     1   205 },
  1         2  
  1         4  
113             or => sub : Operands(2) {
114 0         0 my ( undef, $stack ) = @_; # Invocant unused
115 0   0     0 push @{ $stack }, pop @{ $stack } || pop @{ $stack };
  0         0  
116 0         0 return;
117 1     1   186 },
  1         2  
  1         4  
118             then => sub : Operands(1) {
119 1     1   126 no warnings qw{ exiting };
  1         2  
  1         51  
120 0         0 last TEST_LOOP;
121 1     1   6 },
  1         1  
  1         4  
122             );
123              
124             sub test : Verb() {
125 0     0   0 my ( $self, undef, @arg ) = __arguments( @_ );
126 0         0 my @stack;
127              
128 0 0       0 eval {
129             TEST_LOOP:
130 0         0 while ( @arg ) {
131 0         0 my $current = shift @arg;
132 0 0       0 if ( my $code = $operator{$current} ) {
133 0         0 my $operands = operands( $code );
134 0 0       0 @stack >= $operands
135             or $self->wail( "Not enough operands. Need $operands" );
136 0         0 $code->( $self, \@stack );
137             } else {
138 0         0 push @stack, $current;
139             }
140             }
141 0         0 1;
142             } or $self->wail( $@ );
143 0 0       0 @stack > 1
144             and $self->wail( 'More than one value left on stack' );
145 0 0 0     0 $stack[-1]
146             and @arg
147             or return;
148 0         0 return $self->dispatch( @arg );
149 1     1   319 }
  1         2  
  1         6  
150             }
151              
152             sub dumper : Verb() {
153             my ( $self, @args ) = @_;
154 1     1   378 use YAML;
  0            
  0            
155             return ref( $self ) . "\n" . Dump( \@args );
156             }
157              
158             1;
159              
160             __END__