| 1 | |||||||||||||||||||||||||||||
| 2 | # Copyright (c) 1999-2017 Rob Fugina <robf@fugina.com> | ||||||||||||||||||||||||||||
| 3 | # Distributed under the terms of the GNU Public License, Version 3.0 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package X10::MacroProc; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # this package implements a macro processor using an event callback mechanism | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use X10::Event; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my $self = bless { @_ }, $type; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | return undef unless $self->{controller}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $self->{logger} ||= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | shift; | |||||||||||||||||||||||||||
| 25 | 0 | printf(@_); | |||||||||||||||||||||||||||
| 26 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"logger"} ||= sub {
shift();
printf @_;
print "\n";
}
MC/DC0%0/2
$self->{"logger"} ||= sub {
shift();
printf @_;
print "\n";
}
$self->{"logger"}
sub {
shift();
printf @_;
print "\n";
}
Truth table0%0/3
A ||= B
A= $self->{"logger"}B= sub {
shift();
printf @_;
print "\n";
}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $self->{verbose} = 1 if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | $self->{controller}->register_listener($self->event_callback); | |||||||||||||||||||||||||||
| 32 | 0 | $self->{macros} = {}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($self->{configfile}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $config = eval { require $self->{configfile} } || die $@; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
require $self->{'configfile'}
}
} || die($@)
MC/DC0%0/1
eval {
do {
require $self->{'configfile'}
}
} || die($@)
eval {
do {
require $self->{'configfile'}
}
}
Truth table0%0/2
A
A= eval {
do {
require $self->{'configfile'}
}
}
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | foreach (keys %$config) | |||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | $self->add( $_ => $config->{$_} ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | return $self; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | ### | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub add | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 0 | my ($key, $macro) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my $nkey = X10::Event->new($key)->as_string; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $self->{logger}->('info', "Replacing old macro for %s", $nkey) | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if exists $self->{macros}->{$nkey}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | $self->{macros}->{$nkey} = $macro; | |||||||||||||||||||||||||||
| 60 | 0 | $self->{macros}->{$nkey}->controller($self->{controller}); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub setup | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | while (my $key = shift) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | my $nkey = X10::Event->new($key)->as_string; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($nkey) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 0 | $self->{macros}->{$nkey} = shift; | |||||||||||||||||||||||||||
| 76 | 0 | $self->{macros}->{$nkey}->controller($self->{controller}); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | $self->{logger}->('info', "Throwing away macro for ", $key); | |||||||||||||||||||||||||||
| 81 | 0 | shift; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | return $self->{macros}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub event_callback | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
event_callback: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | return sub { $self->handle_event(shift) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub handle_event | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handle_event: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | 0 | my $event = shift; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (exists $self->{macros}->{$event->as_string}) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | $self->{logger}->('info', "Macro: %s", | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $self->{macros}->{$event->as_string}->description || $event->as_string | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'macros'}{$event->as_string}->description || $event->as_string
MC/DC0%0/2
$self->{'macros'}{$event->as_string}->description || $event->as_string
$self->{'macros'}{$event->as_string}->description
$event->as_string
Truth table0%0/3
A || B
A= $self->{'macros'}{$event->as_string}->descriptionB= $event->as_string
| |||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | $self->{macros}->{$event->as_string}->run | ||||||||||||||||||||||||||||
| 108 | || $self->{logger}->('info', "Problem running macro: %s", | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $self->{macros}->{$event->as_string}->description | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{'macros'}{$event->as_string}->description || $event->as_string
MC/DC0%0/2
$self->{'macros'}{$event->as_string}->description || $event->as_string
$self->{'macros'}{$event->as_string}->description
$event->as_string
Truth table0%0/3
A || B
A= $self->{'macros'}{$event->as_string}->descriptionB= $event->as_string
| |||||||||||||||||||||||||||||
| 110 | || $event->as_string); | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | elsif ($self->{debug}) | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 0 | $self->{logger}->('info', "No macro for %s", $event->as_string); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub select_fds | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
select_fds: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | return (); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||