| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Astro::App::Satpass2::Macro; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 20 |  |  | 20 |  | 10961 | use 5.008; | 
|  | 20 |  |  |  |  | 97 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 20 |  |  | 20 |  | 144 | use strict; | 
|  | 20 |  |  |  |  | 39 |  | 
|  | 20 |  |  |  |  | 524 |  | 
| 6 | 20 |  |  | 20 |  | 103 | use warnings; | 
|  | 20 |  |  |  |  | 59 |  | 
|  | 20 |  |  |  |  | 798 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 20 |  |  |  |  | 2247 | use Astro::App::Satpass2::Utils qw{ | 
| 9 |  |  |  |  |  |  | instance | 
| 10 |  |  |  |  |  |  | CODE_REF | 
| 11 |  |  |  |  |  |  | @CARP_NOT | 
| 12 | 20 |  |  | 20 |  | 158 | }; | 
|  | 20 |  |  |  |  | 62 |  | 
| 13 | 20 |  |  | 20 |  | 8766 | use Astro::App::Satpass2::Warner; | 
|  | 20 |  |  |  |  | 53 |  | 
|  | 20 |  |  |  |  | 757 |  | 
| 14 | 20 |  |  | 20 |  | 157 | use Scalar::Util 1.26 qw{ weaken }; | 
|  | 20 |  |  |  |  | 399 |  | 
|  | 20 |  |  |  |  | 14046 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our $VERSION = '0.051'; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub new { | 
| 19 | 17 |  |  | 17 | 1 | 156 | my ( $class, %arg ) = @_; | 
| 20 | 17 |  | 33 |  |  | 87 | my $self = bless \%arg, ref $class || $class; | 
| 21 | 17 |  |  |  |  | 86 | $self->init(); | 
| 22 | 16 |  |  |  |  | 63 | return $self; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub execute { | 
| 26 | 0 |  |  | 0 | 1 | 0 | __PACKAGE__->weep( 'execute() must be overridden' ); | 
| 27 | 0 |  |  |  |  | 0 | return;	# weep() dies, but Perl::Critic does not know this. | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub generator { | 
| 31 | 9 |  |  | 9 | 1 | 26 | my ( $self, @args ) = @_; | 
| 32 |  |  |  |  |  |  | $self->{generate} | 
| 33 | 9 | 50 |  |  |  | 30 | or $self->weep( q{'generate' attribute not specified} ); | 
| 34 |  |  |  |  |  |  | @args | 
| 35 | 9 | 50 |  |  |  | 25 | or return $self->{generate}->( $self, sort $self->implements() ); | 
| 36 | 9 |  |  |  |  | 21 | foreach my $macro ( @args ) { | 
| 37 | 9 |  |  |  |  | 57 | $self->implements( $macro, required => 1 ); | 
| 38 |  |  |  |  |  |  | } | 
| 39 | 9 |  |  |  |  | 31 | return $self->{generate}->( $self, @args ); | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub implements { | 
| 43 | 28 |  |  | 28 | 1 | 77 | my ( $self, $name, %arg ) = @_; | 
| 44 |  |  |  |  |  |  | defined $name | 
| 45 | 28 | 50 |  |  |  | 70 | or return ( keys %{ $self->{implements} } ); | 
|  | 0 |  |  |  |  | 0 |  | 
| 46 |  |  |  |  |  |  | $self->{implements}{$name} | 
| 47 |  |  |  |  |  |  | or not $arg{required} | 
| 48 | 28 | 50 | 33 |  |  | 78 | or $self->wail( "This object does not implement macro $name" ); | 
| 49 | 28 |  |  |  |  | 88 | return $self->{implements}{$name}; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub init { | 
| 53 | 17 |  |  | 17 | 1 | 30 | my ( $self ) = @_; | 
| 54 | 17 |  | 33 |  |  | 66 | $self->{warner} ||= Astro::App::Satpass2::Warner->new(); | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | defined $self->{generate} | 
| 57 |  |  |  |  |  |  | and CODE_REF ne ref $self->{generate} | 
| 58 | 17 | 50 | 33 |  |  | 98 | and $self->wail( q{If specified, 'generate' must be a code ref} ); | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | defined $self->{name} | 
| 61 | 17 | 50 |  |  |  | 44 | or $self->wail( q{Attribute 'name' is required} ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | defined $self->{parent} | 
| 64 | 17 | 50 |  |  |  | 38 | or $self->wail( q{Attribute 'parent' is required} ); | 
| 65 | 17 | 50 |  |  |  | 55 | instance( $self->{parent}, 'Astro::App::Satpass2' ) | 
| 66 |  |  |  |  |  |  | or $self->wail( q{Attribute 'parent' must be an Astro::App::Satpass2} ); | 
| 67 | 17 |  |  |  |  | 65 | weaken( $self->{parent} ); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 17 |  |  |  |  | 35 | return; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub name { | 
| 73 | 25 |  |  | 25 | 1 | 51 | my ( $self ) = @_; | 
| 74 | 25 |  |  |  |  | 75 | return $self->{name}; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | sub parent { | 
| 78 | 28 |  |  | 28 | 1 | 58 | my ( $self ) = @_; | 
| 79 | 28 |  |  |  |  | 70 | return $self->{parent}; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | sub wail { | 
| 83 | 1 |  |  | 1 | 1 | 3 | my ( $self, @args ) = @_; | 
| 84 | 1 |  |  |  |  | 6 | $self->warner()->wail( @args ); | 
| 85 | 0 |  |  |  |  | 0 | return;	# wail() dies, but Perl::Critic does not know this. | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub warner { | 
| 89 | 1 |  |  | 1 | 1 | 4 | my ( $self ) = @_; | 
| 90 | 1 | 50 |  |  |  | 4 | ref $self | 
| 91 |  |  |  |  |  |  | or return Astro::App::Satpass2::Warner->new(); | 
| 92 | 1 |  |  |  |  | 7 | return $self->{warner}; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | sub weep { | 
| 96 | 0 |  |  | 0 | 1 |  | my ( $self, @args ) = @_; | 
| 97 | 0 |  |  |  |  |  | $self->warner()->weep( @args ); | 
| 98 | 0 |  |  |  |  |  | return;	# weep() dies, but Perl::Critic does not know this. | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub whinge { | 
| 102 | 0 |  |  | 0 | 1 |  | my ( $self, @args ) = @_; | 
| 103 | 0 |  |  |  |  |  | $self->warner()->whinge( @args ); | 
| 104 | 0 |  |  |  |  |  | return; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | # TODO get rid of this when level1 support goes away. | 
| 108 |  |  |  |  |  |  | sub __level1_rewrite { | 
| 109 | 0 |  |  | 0 |  |  | return; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | 1; | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | __END__ |