« blib/lib/Astro/App/Satpass2/ParseTime/Code.pm
↑ Summary
blib/lib/Astro/App/Satpass2/Format/Template.pm »
| 1 | package Astro::App::Satpass2::Macro::Code; | ||||||||||||||||||||||||||||||||||||||||||
| 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 parent qw{ Astro::App::Satpass2::Macro }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use Astro::App::Satpass2::Utils qw{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | expand_tilde | ||||||||||||||||||||||||||||||||||||||||||
| 12 | load_package | ||||||||||||||||||||||||||||||||||||||||||
| 13 | quoter | ||||||||||||||||||||||||||||||||||||||||||
| 14 | @CARP_NOT | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | }; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 20 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | our $VERSION = '0.059'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=12 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my $parent = $self->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my %popt = ( complaint => 'wail', fatal => 'wail' ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | exists $self->{lib} | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | and $popt{lib} = $self->expand_tilde( $self->{lib} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | defined $self->{lib} | ||||||||||||||||||||||||||||||||||||||||||
| 28 | and not $self->{relative} | ||||||||||||||||||||||||||||||||||||||||||
| 29 | and not $self->{lib} =~ m/ \A ~ /smx | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | and $self->{lib} = File::Spec->rel2abs( $self->{lib} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $self->{"lib"} and not $self->{"relative"} and not $self->{"lib"} =~ / \A ~ /msx
defined $self->{"lib"} and not $self->{"relative"}
MC/DC0%0/3
defined $self->{"lib"} and not $self->{"relative"} and not $self->{"lib"} =~ / \A ~ /msx
defined $self->{"lib"}
not $self->{"relative"}
not $self->{"lib"} =~ / \A ~ /msx
Truth table25%1/4
A and not(B) and not(C)
A= defined $self->{"lib"}B= not $self->{"relative"}C= not $self->{"lib"} =~ / \A ~ /msx
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $module = $self->load_package( | |||||||||||||||||||||||||||||||||||||||||
| 32 | \%popt, $self->name(), 'Astro::App::Satpass2::Macro::Code' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | $module->isa( 'Astro::App::Satpass2' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | or $self->wail( "$module is not a subclass of Astro::App::Satpass2" ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my %implements; # Names and references to found code | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $stb = "${module}::"; # Name of loaded symbol table | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # Fairly deep magic begins here. We need symbolic references to | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # traverse the symbol table of the loaded code, so: | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | ▶ | no strict qw{ refs }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | foreach my $name ( keys %$stb ) { | |||||||||||||||||||||||||||||||||||||||||
| 45 | 21 | my $val = $stb->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # We are only interested in symbols that start with alphabetics. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 21 | ▶ | $name =~ m/ \A [[:alpha:]] /smx | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # We do not want symbols unless they contain at least one | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # lower-case character. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | ▶ | $name =~ m/ [[:lower:]] /smx | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # We need a reference to the entry's glob, which we obtain by | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # symbolic reference. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | my $glob = \$val; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # If $name refers to an inlineable function, $val is going to be | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # its value. This is not what we want, so ... | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | ▶ | 'GLOB' eq ref $glob | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # If the code slot is empty we ignore it. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | *{$glob}{CODE} | |||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # If the code does not have the Verb() attribute, we ignore it. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # TODO technically we have an encapsulation failure here which | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # needs to be fixed up. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | $parent->__get_attr( *{$glob}{CODE}, 'Verb' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Record the fact that the module defines this name. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | $implements{$name} = *{$glob}{CODE}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # End of symbol table magic. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $self->{implements} = \%implements; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my ( $self, $name, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | my $code = $self->implements( $name, required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | return $code->( $self->parent(), @args ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | sub has_lib { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_lib: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | return exists $self->{lib}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | sub lib { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lib: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | return $self->{lib}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | sub relative { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
relative: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | return $self->{relative}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||||||||||||||||