| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::Pipe; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $mixin; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
|
8
|
1
|
|
|
1
|
|
1678
|
$mixin = 'XAS::Lib::Pipe::Unix'; |
|
9
|
|
|
|
|
|
|
}; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use POE; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
12
|
1
|
|
|
1
|
|
533
|
use XAS::Lib::POE::PubSub; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
53
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use XAS::Class |
|
15
|
1
|
|
|
|
|
13
|
debug => 0, |
|
16
|
|
|
|
|
|
|
version => $VERSION, |
|
17
|
|
|
|
|
|
|
base => 'XAS::Lib::POE::Session', |
|
18
|
|
|
|
|
|
|
mixin => $mixin, |
|
19
|
|
|
|
|
|
|
accessors => 'pipe event', |
|
20
|
|
|
|
|
|
|
utils => ':validation trim dotid', |
|
21
|
|
|
|
|
|
|
vars => { |
|
22
|
|
|
|
|
|
|
PARAMS => { |
|
23
|
|
|
|
|
|
|
-fifo => { isa => 'Badger::Filesystem::File' }, |
|
24
|
|
|
|
|
|
|
-filter => { optional => 1, default => undef }, |
|
25
|
|
|
|
|
|
|
-eol => { optional => 1, default => "\n" }, |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
} |
|
28
|
1
|
|
|
1
|
|
4
|
; |
|
|
1
|
|
|
|
|
1
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#use Data::Dumper; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
33
|
|
|
|
|
|
|
# Public Methods |
|
34
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub session_initialize { |
|
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->log->debug("$alias: entering session_initialize()"); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# public events |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# private events |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$poe_kernel->state('pipe_error', $self, '_pipe_error'); |
|
48
|
0
|
|
|
|
|
|
$poe_kernel->state('pipe_input', $self, '_pipe_input'); |
|
49
|
0
|
|
|
|
|
|
$poe_kernel->state('pipe_output', $self, '_pipe_output'); |
|
50
|
0
|
|
|
|
|
|
$poe_kernel->state('pipe_connect', $self, '_pipe_connect'); |
|
51
|
0
|
|
|
|
|
|
$poe_kernel->state('process_error', $self, '_process_error'); |
|
52
|
0
|
|
|
|
|
|
$poe_kernel->state('process_input', $self, '_process_input'); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# walk the chain |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->SUPER::session_initialize(); |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving session_initialize()"); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub process_input { |
|
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
64
|
0
|
|
|
|
|
|
my ($input) = validate_params(\@_, [1]); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->log->debug("$alias: process_input()"); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->process_output($input); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub process_error { |
|
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
76
|
0
|
|
|
|
|
|
my ($syscall, $errnum, $errstr) = validate_params(\@_, [1,1,1]); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->log->debug("$alias: process_error()"); |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->log->error_msg('net_client_error', $alias, $errnum, $errstr); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub process_output { |
|
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
88
|
0
|
|
|
|
|
|
my ($output) = validate_params(\@_, [1]); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->log->debug("$alias: process_output()"); |
|
93
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'pipe_output', $output); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
98
|
|
|
|
|
|
|
# Public Events |
|
99
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
102
|
|
|
|
|
|
|
# Private Events |
|
103
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _process_input { |
|
106
|
0
|
|
|
0
|
|
|
my ($self, $input) = @_[OBJECT,ARG0]; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _process_input()"); |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->process_input($input); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _process_error { |
|
117
|
0
|
|
|
0
|
|
|
my ($self, $syscall, $errnum, $errstr) = @_[OBJECT,ARG0..ARG2]; |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _process_error()"); |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->process_error($syscall, $errnum, $errstr); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
128
|
|
|
|
|
|
|
# Private Methods |
|
129
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub init { |
|
132
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
|
135
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$self->{'event'} = XAS::Lib::POE::PubSub->new(); |
|
138
|
0
|
|
|
|
|
|
$self->event->subscribe($alias); |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$self->init_pipe(); |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $self; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 NAME |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
XAS::Lib::Pipe - Interact with named pipes |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
use XAS::Lib::Pipe; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $client = XAS::Lib::Pipe->new( |
|
159
|
|
|
|
|
|
|
-fifo => File('/var/lib/xas/pipe'), |
|
160
|
|
|
|
|
|
|
-filter => POE::Filter::Line->new(), |
|
161
|
|
|
|
|
|
|
-eol => "\n", |
|
162
|
|
|
|
|
|
|
); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$client->run(); |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The module provides a POE based framework for reading and writing to named |
|
169
|
|
|
|
|
|
|
pipes. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 METHODS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 new |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This initializes the module and starts listening on the pipe. The following |
|
176
|
|
|
|
|
|
|
parametrs are used: |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item B<-alias> |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
The name of the POE session. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item B<-fifo> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
The name of the pipe to interact with. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item B<-filter> |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
An optional filter to use, defaults to POE::Filter::Line |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item B<-eol> |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
An optional EOL, defaults to "\n"; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=back |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 process_input($input) |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This method will process the input from the pipe. It takes the |
|
201
|
|
|
|
|
|
|
following parameters: |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=over 4 |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item B<$input> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The input received from the pipe. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=back |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 process_output($output) |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This method will process the output for the pipe. It takes the |
|
214
|
|
|
|
|
|
|
following parameters: |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=over 4 |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item B<$output> |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
The output to be sent to the pipe. |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 process_error($syscall, $errnum, $errstr) |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This method will process any errors from the pipe. It takes the |
|
227
|
|
|
|
|
|
|
following parameters: |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B<$syscall> |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
The function that caused the error. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item B<$errnum> |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
The OS error number. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item B<$errstr> |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
The OS error string. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=over 4 |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item L<XAS|XAS> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=back |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 AUTHOR |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Copyright (c) 2012-2016 Kevin L. Esteb |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
262
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
|
263
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |