line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package X10::MacroProc; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# this package implements a macro processor using an event callback mechanism |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use X10::Event; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
634
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
0
|
|
my $type = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $self = bless { @_ }, $type; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
return undef unless $self->{controller}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$self->{logger} ||= sub { |
20
|
0
|
|
|
0
|
|
|
shift; |
21
|
0
|
|
|
|
|
|
printf(@_); |
22
|
0
|
|
|
|
|
|
print "\n"; |
23
|
0
|
|
0
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
$self->{verbose} = 1 if $self->{debug}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->{controller}->register_listener($self->event_callback); |
28
|
0
|
|
|
|
|
|
$self->{macros} = {}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ($self->{configfile}) |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
0
|
|
|
|
my $config = eval { require $self->{configfile} } || die $@; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
foreach (keys %$config) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
$self->add( $_ => $config->{$_} ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
### |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub add |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my ($key, $macro) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $nkey = X10::Event->new($key)->as_string; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
$self->{logger}->('info', "Replacing old macro for %s", $nkey) |
53
|
|
|
|
|
|
|
if exists $self->{macros}->{$nkey}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->{macros}->{$nkey} = $macro; |
56
|
0
|
|
|
|
|
|
$self->{macros}->{$nkey}->controller($self->{controller}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub setup |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (@_) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
|
while (my $key = shift) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
|
my $nkey = X10::Event->new($key)->as_string; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if ($nkey) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
$self->{macros}->{$nkey} = shift; |
72
|
0
|
|
|
|
|
|
$self->{macros}->{$nkey}->controller($self->{controller}); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
|
|
|
$self->{logger}->('info', "Throwing away macro for ", $key); |
77
|
0
|
|
|
|
|
|
shift; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self->{macros}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub event_callback |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
89
|
0
|
|
|
0
|
|
|
return sub { $self->handle_event(shift) }; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub handle_event |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
95
|
0
|
|
|
|
|
|
my $event = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (exists $self->{macros}->{$event->as_string}) |
|
|
0
|
|
|
|
|
|
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
0
|
|
|
|
$self->{logger}->('info', "Macro: %s", |
100
|
|
|
|
|
|
|
$self->{macros}->{$event->as_string}->description || $event->as_string |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
0
|
|
|
|
$self->{macros}->{$event->as_string}->run |
104
|
|
|
|
|
|
|
|| $self->{logger}->('info', "Problem running macro: %s", |
105
|
|
|
|
|
|
|
$self->{macros}->{$event->as_string}->description |
106
|
|
|
|
|
|
|
|| $event->as_string); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif ($self->{debug}) |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
|
|
|
$self->{logger}->('info', "No macro for %s", $event->as_string); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub select_fds |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
0
|
|
return (); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|