| 1 | package XAS::Lib::Process; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | my $mixin; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | BEGIN { | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | $mixin = 'XAS::Lib::Process::Unix'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | $mixin = 'XAS::Lib::Process::Win32' if ($^O eq 'MSWin32'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Set::Light; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Badger::Filesystem 'Cwd Dir'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use POE qw(Wheel Driver::SysRW Filter::Line); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | use XAS::Class | ||||||||||||||||||||||||||||
| 17 | 1 | debug => 0, | |||||||||||||||||||||||||||
| 18 | version => $VERSION, | ||||||||||||||||||||||||||||
| 19 | base => 'XAS::Lib::POE::Service', | ||||||||||||||||||||||||||||
| 20 | mixin => $mixin, | ||||||||||||||||||||||||||||
| 21 | utils => 'dotid', | ||||||||||||||||||||||||||||
| 22 | mutators => 'is_active input_handle output_handle status retries', | ||||||||||||||||||||||||||||
| 23 | accessors => 'pid exit_code exit_signal process ID', | ||||||||||||||||||||||||||||
| 24 | vars => { | ||||||||||||||||||||||||||||
| 25 | PARAMS => { | ||||||||||||||||||||||||||||
| 26 | -command => 1, | ||||||||||||||||||||||||||||
| 27 | -auto_start => { optional => 1, default => 1 }, | ||||||||||||||||||||||||||||
| 28 | -auto_restart => { optional => 1, default => 1 }, | ||||||||||||||||||||||||||||
| 29 | -environment => { optional => 1, default => {} }, | ||||||||||||||||||||||||||||
| 30 | -exit_codes => { optional => 1, default => '0,1' }, | ||||||||||||||||||||||||||||
| 31 | -exit_retries => { optional => 1, default => 5 }, | ||||||||||||||||||||||||||||
| 32 | -group => { optional => 1, default => 'nobody' }, | ||||||||||||||||||||||||||||
| 33 | -priority => { optional => 1, default => 0 }, | ||||||||||||||||||||||||||||
| 34 | -umask => { optional => 1, default => '0022' }, | ||||||||||||||||||||||||||||
| 35 | -user => { optional => 1, default => 'nobody' }, | ||||||||||||||||||||||||||||
| 36 | -redirect => { optional => 1, default => 0 }, | ||||||||||||||||||||||||||||
| 37 | -input_driver => { optional => 1, default => POE::Driver::SysRW->new() }, | ||||||||||||||||||||||||||||
| 38 | -output_driver => { optional => 1, default => POE::Driver::SysRW->new() }, | ||||||||||||||||||||||||||||
| 39 | -input_filter => { optional => 1, default => POE::Filter::Line->new(Literal => "\n") }, | ||||||||||||||||||||||||||||
| 40 | -output_filter => { optional => 1, default => POE::Filter::Line->new(Literal => "\n") }, | ||||||||||||||||||||||||||||
| 41 | -directory => { optional => 1, default => Cwd, isa => 'Badger::Filesystem::Directory' }, | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #use Data::Dumper; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 49 | # Public Methods | ||||||||||||||||||||||||||||
| 50 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub session_initialize { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_initialize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $self->log->debug("$alias: entering session_initialize()"); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | $poe_kernel->state('get_output', $self); | |||||||||||||||||||||||||||
| 60 | 0 | $poe_kernel->state('put_input', $self); | |||||||||||||||||||||||||||
| 61 | 0 | $poe_kernel->state('flush_event', $self); | |||||||||||||||||||||||||||
| 62 | 0 | $poe_kernel->state('error_event', $self); | |||||||||||||||||||||||||||
| 63 | 0 | $poe_kernel->state('close_event', $self); | |||||||||||||||||||||||||||
| 64 | 0 | $poe_kernel->state('poll_child', $self, '_poll_child'); | |||||||||||||||||||||||||||
| 65 | 0 | $poe_kernel->state('child_exit', $self, '_child_exit'); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # walk the chain | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | $self->SUPER::session_initialize(); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | $poe_kernel->post($alias, 'session_startup'); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $self->log->debug("$alias: leaving session_initialize()"); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub session_startup { | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_startup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->log->debug("$alias: entering session_startup()"); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($self->auto_start) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $self->start_process(); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # walk the chain | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | $self->SUPER::session_startup(); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $self->log->debug("$alias: leaving session_startup()"); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub session_pause { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_pause: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | $self->log->debug("$alias: entering session_pause()"); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | $self->pause_process(); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # walk the chain | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | $self->SUPER::session_pause(); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | $self->log->debug("$alias: leaving session_pause()"); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | sub session_resume { | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_resume: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | $self->log->debug("$alias: entering session_resume()"); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | $self->resume_process(); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # walk the chain | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | $self->SUPER::session_resume(); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | $self->log->debug("$alias: leaving session_resume()"); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub session_stop { | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | $self->log->debug("$alias: entering session_stop()"); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $self->stop_process(); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # walk the chain | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | $self->SUPER::session_stop(); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | $self->log->debug("$alias: leaving session_stop()"); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub session_shutdown { | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
session_shutdown: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | $self->log->debug("$alias: entering session_shutdown()"); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | $self->kill_process(); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # walk the chain | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | $self->SUPER::session_shutdown(); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | $self->log->debug("$alias: leaving session_shutdown()"); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 167 | # Public Events | ||||||||||||||||||||||||||||
| 168 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | sub get_output { | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my ($self, $output, $wheel) = @_[OBJECT,ARG0,ARG1]; | ||||||||||||||||||||||||||
|
Subroutine
get_output: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | print $output . "\n"; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | sub put_input { | ||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my ($self, $chunk) = @_[OBJECT,ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
put_input: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my @chunks; | |||||||||||||||||||||||||||
| 181 | 0 | my $driver = $self->input_driver; | |||||||||||||||||||||||||||
| 182 | 0 | my $filter = $self->input_filter; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # Avoid big bada boom if someone put()s on a dead wheel. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | unless ($self->input_handle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | $self->throw_msg( | |||||||||||||||||||||||||||
| 189 | dotid($self->class) . '.put_input.writerr', | ||||||||||||||||||||||||||||
| 190 | 'process_writerr', | ||||||||||||||||||||||||||||
| 191 | 'called put() on a wheel without an open INPUT handle' | ||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | push(@chunks, $chunk); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ($self->{buffer} = $driver->put($filter->put(\@chunks))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | $poe_kernel->select_resume_write($self->input_handle); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | return 0; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | sub flush_event { | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my ($self, $wheel) = @_[OBJECT,ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
flush_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | $self->log->debug("$alias: flush_event"); | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub error_event { | ||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my ($self, $operation, $errno, $errstr, $wheel, $type) = @_[OBJECT,ARG0..ARG4]; | ||||||||||||||||||||||||||
|
Subroutine
error_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | $self->log->debug( | |||||||||||||||||||||||||||
| 223 | sprintf('%s: error_event - ops: %s, errno: %s, errstr: %s', | ||||||||||||||||||||||||||||
| 224 | $alias, $operation, $errno, $errstr) | ||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | sub close_event { | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my ($self, $wheel) = @_[OBJECT,ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
close_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | $self->log->debug("$alias: close_event"); | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 239 | # Private Methods | ||||||||||||||||||||||||||||
| 240 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | sub _child_exit { | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ($self, $signal, $pid, $exitcode) = @_[OBJECT,ARG0,ARG1,ARG2]; | ||||||||||||||||||||||||||
|
Subroutine
_child_exit: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | my $alias = $self->alias; | |||||||||||||||||||||||||||
| 246 | 0 | my $status = $self->status; | |||||||||||||||||||||||||||
| 247 | 0 | my $retries = $self->retries; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | $self->{pid} = undef; | |||||||||||||||||||||||||||
| 250 | 0 | $self->{exit_code} = $exitcode >> 8; | |||||||||||||||||||||||||||
| 251 | 0 | $self->{exit_signal} = $exitcode & 127; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | $self->log->warn_msg('process_exited', $alias, $pid, $self->exit_code); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($status == STOPPED) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ($self->auto_restart) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ($retries < $self->exit_retries) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | $retries += 1; | |||||||||||||||||||||||||||
| 262 | 0 | $self->retries($retries); | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if ($self->exit_codes->has($self->exit_code)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | $self->start_process(); | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | $self->log->warn_msg('process_unknown_exitcode', $alias); | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | $self->log->warn_msg('process_nomore_retries', $alias); | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | $self->log->warn_msg('process_no_autorestart', $alias); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | sub _process_output { | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_process_output: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | my $id = $self->ID; | |||||||||||||||||||||||||||
| 294 | 0 | my $is_active = $self->is_active; | |||||||||||||||||||||||||||
| 295 | 0 | my $driver = $self->output_driver; | |||||||||||||||||||||||||||
| 296 | 0 | my $filter = $self->output_filter; | |||||||||||||||||||||||||||
| 297 | 0 | my $output = $self->output_handle; | |||||||||||||||||||||||||||
| 298 | 0 | my $state = ref($self) . "($id) -> select output"; | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($filter->can('get_one') and $filter->can('get_one_start')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter->can("get_one") and $filter->can("get_one_start")
MC/DC0%0/2
$filter->can("get_one") and $filter->can("get_one_start")
$filter->can("get_one")
$filter->can("get_one_start")
Truth table0%0/3
A and B
A= $filter->can("get_one")B= $filter->can("get_one_start")
| |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | $poe_kernel->state( | ||||||||||||||||||||||||||||
| 303 | $state, | ||||||||||||||||||||||||||||
| 304 | sub { | ||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if (defined(my $raw_output = $driver->get($handle))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 0 | $filter->get_one_start($raw_output); | |||||||||||||||||||||||||||
| 308 | 0 | while (1) { | |||||||||||||||||||||||||||
| 309 | 0 | my $next_rec = $filter->get_one(); | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | last unless @$next_rec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | foreach my $cooked_output (@$next_rec) { | |||||||||||||||||||||||||||
| 312 | 0 | $k->call($me, 'get_output', $cooked_output, $id); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||
| 316 | 0 | $k->call($me, 'error_event', 'read', ($!+0), $!, $id, 'OUTPUT'); | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | unless (--$is_active) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | $k->call($me, 'close_event', $id); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | 0 | $k->select_read($output); | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | 0 | ); | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | $poe_kernel->state( | ||||||||||||||||||||||||||||
| 328 | $state, | ||||||||||||||||||||||||||||
| 329 | sub { | ||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my ($k, $me, $handle) = @_[KERNEL, SESSION, ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if (defined(my $raw_output = $driver->get($handle))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | foreach my $cooked_output (@{$filter->get($raw_output)}) { | |||||||||||||||||||||||||||
| 333 | 0 | $k->call($me, 'get_output', $cooked_output, $id); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||
| 336 | 0 | $k->call($me, 'error_event', 'read', ($!+0), $!, $id, 'OUTPUT'); | |||||||||||||||||||||||||||
| 337 | 0 | ▶ | unless (--$is_active) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | $k->call($me, 'close_event', $id); | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | 0 | $k->select_read($output); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | 0 | ); | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | $poe_kernel->select_read($output, $state); | |||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | sub _process_input { | ||||||||||||||||||||||||||||
| 352 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_process_input: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | my $id = $self->ID; | |||||||||||||||||||||||||||
| 355 | 0 | my $driver = $self->input_driver; | |||||||||||||||||||||||||||
| 356 | 0 | my $filter = $self->input_filter; | |||||||||||||||||||||||||||
| 357 | 0 | my $input = $self->input_handle; | |||||||||||||||||||||||||||
| 358 | 0 | my $buffer = \$self->{buffer}; | |||||||||||||||||||||||||||
| 359 | 0 | my $state = ref($self) . "($id) -> select input"; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | $poe_kernel->state( | ||||||||||||||||||||||||||||
| 362 | $state, | ||||||||||||||||||||||||||||
| 363 | sub { | ||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my ($k, $me, $handle) = @_[KERNEL,SESSION,ARG0]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 365 | 0 | $$buffer = $driver->flush($handle); | |||||||||||||||||||||||||||
| 366 | # When you can't write, nothing else matters. | ||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ($!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | $k->call($me, 'error_event', 'write', ($!+0), $!, $id, 'INPUT'); | |||||||||||||||||||||||||||
| 369 | 0 | $k->select_write($handle); | |||||||||||||||||||||||||||
| 370 | } else { | ||||||||||||||||||||||||||||
| 371 | # Could write, or perhaps couldn't but only because the | ||||||||||||||||||||||||||||
| 372 | # filehandle's buffer is choked. | ||||||||||||||||||||||||||||
| 373 | # All chunks written; fire off a "flushed" event. | ||||||||||||||||||||||||||||
| 374 | 0 | ▶ | unless ($$buffer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | $k->select_pause_write($handle); | |||||||||||||||||||||||||||
| 376 | 0 | $k->call($me, 'flush_event', $id); | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | 0 | ); | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 0 | $poe_kernel->select_write($input, $state); | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | # Pause the write select immediately, unless output is pending. | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $poe_kernel->select_pause_write($input) unless ($buffer); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | sub DESTROY { | ||||||||||||||||||||||||||||
| 391 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($self->input_handle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | $poe_kernel->select_write($self->input_handle); | |||||||||||||||||||||||||||
| 396 | 0 | $self->input_handle(undef); | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if ($self->output_handle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 0 | $poe_kernel->select_read($self->output_handle); | |||||||||||||||||||||||||||
| 403 | 0 | $self->output_handle(undef); | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | POE::Wheel::free_wheel_id($self->ID); | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | sub _resolve_path { | ||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_resolve_path: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||
| 413 | 0 | my $command = shift; | |||||||||||||||||||||||||||
| 414 | 0 | my $is_absolute_re = shift; | |||||||||||||||||||||||||||
| 415 | 0 | my $has_dir_element_re = shift; | |||||||||||||||||||||||||||
| 416 | 0 | my $extensions = shift; | |||||||||||||||||||||||||||
| 417 | 0 | my $xpath = shift; | |||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | # Stolen from Proc::Background | ||||||||||||||||||||||||||||
| 420 | # | ||||||||||||||||||||||||||||
| 421 | # Make the path to the progam absolute if it isn't already. If the | ||||||||||||||||||||||||||||
| 422 | # path is not absolute and if the path contains a directory element | ||||||||||||||||||||||||||||
| 423 | # separator, then only prepend the current working to it. If the | ||||||||||||||||||||||||||||
| 424 | # path is not absolute, then look through the PATH environment to | ||||||||||||||||||||||||||||
| 425 | # find the executable. In all cases, look for the programs with any | ||||||||||||||||||||||||||||
| 426 | # extensions added to the original path name. | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | my $path; | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($command =~ /$is_absolute_re/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | foreach my $ext (@$extensions) { | |||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 0 | my $p = "$command$ext"; | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (-f $p and -x _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $p and -x _
MC/DC0%0/2
-f $p and -x _
-f $p
-x _
Truth table0%0/3
A and B
A= -f $pB= -x _
| |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | $path = $p; | |||||||||||||||||||||||||||
| 439 | 0 | last; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | ▶ | unless (defined $path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | $self->throw_msg( | |||||||||||||||||||||||||||
| 448 | dotid($self->class) . '.resolve_path.path', | ||||||||||||||||||||||||||||
| 449 | 'process_location', | ||||||||||||||||||||||||||||
| 450 | $command | ||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | } else { | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | my $cwd = Cwd->path; | |||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ($command =~ /$has_dir_element_re/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | my $p1 = "$cwd/$command"; | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 0 | foreach my $ext (@$extensions) { | |||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 0 | my $p2 = "$p1$ext"; | |||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | 0 | ▶ | if (-f $p2 and -x _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $p2 and -x _
MC/DC0%0/2
-f $p2 and -x _
-f $p2
-x _
Truth table0%0/3
A and B
A= -f $p2B= -x _
| |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 0 | $path = $p2; | |||||||||||||||||||||||||||
| 470 | 0 | last; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | } else { | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 0 | foreach my $dir (@$xpath) { | |||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 0 | ▶ | next unless length $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | $dir = "$cwd/$dir" unless $dir =~ /$is_absolute_re/o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 0 | my $p1 = "$dir/$command"; | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | foreach my $ext (@$extensions) { | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 0 | my $p2 = "$p1$ext"; | |||||||||||||||||||||||||||
| 488 | 0 | ▶ | if (-f $p2 and -x _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $p2 and -x _
MC/DC0%0/2
-f $p2 and -x _
-f $p2
-x _
Truth table0%0/3
A and B
A= -f $p2B= -x _
| |||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 0 | $path = $p2; | |||||||||||||||||||||||||||
| 491 | 0 | last; | |||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 0 | ▶ | last if defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 0 | ▶ | unless (defined $path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | $self->throw_msg( | |||||||||||||||||||||||||||
| 506 | dotid($self->class) . '.resolve_path.path', | ||||||||||||||||||||||||||||
| 507 | 'process_location', | ||||||||||||||||||||||||||||
| 508 | $command | ||||||||||||||||||||||||||||
| 509 | ); | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 0 | return $path; | |||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | sub init { | ||||||||||||||||||||||||||||
| 520 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 0 | my $self = $class->SUPER::init(@_); | |||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 0 | my @exit_codes = split(',', $self->exit_codes); | |||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 0 | $self->{exit_codes} = Set::Light->new(@exit_codes); | |||||||||||||||||||||||||||
| 527 | 0 | $self->{ID} = POE::Wheel::allocate_wheel_id(); | |||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 0 | $self->retries(1); | |||||||||||||||||||||||||||
| 530 | 0 | $self->is_active(1); | |||||||||||||||||||||||||||
| 531 | 0 | $self->init_process(); | |||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 0 | return $self; | |||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 1 | 1; | |||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | __END__ | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | =head1 NAME | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | XAS::Lib::Process - A class for managing processes within the XAS environment | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | use XAS::Lib::Process; | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | my $process = XAS::Lib::Process->new( | ||||||||||||||||||||||||||||
| 550 | -command => 'perl test.pl' | ||||||||||||||||||||||||||||
| 551 | ); | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | $process->run(); | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | This class manages a sub process in a platform independent way. Mixins | ||||||||||||||||||||||||||||
| 558 | are loaded to handle the differences between Unix/Linux and Windows. | ||||||||||||||||||||||||||||
| 559 | This module inherits from L<XAS::Lib::POE::Service|XAS::Lib::POE::Service>. | ||||||||||||||||||||||||||||
| 560 | Please refer to that module for additional help. | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | =head1 METHODS | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =head2 new | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | This method initialized the module and takes the following parameters: | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =over 4 | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | =item B<-command> | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | The command to run. | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | =item B<-auto_start> | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | This indicates wither to autostart the process. The default is true. | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | =item B<-auto_restart> | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | This indicates wither to restart the process if it exits. The default | ||||||||||||||||||||||||||||
| 581 | is true. | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | =item B<-directory> | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | The optional directory to start the process in. Defaults to the current | ||||||||||||||||||||||||||||
| 586 | directory of the parent process. | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =item B<-environment> | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | Optional, addtitional environment variables to provide to the process. | ||||||||||||||||||||||||||||
| 591 | The default is none. | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | =item B<-exit_codes> | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | Optional exit codes to check for the process. They default to '0,1'. | ||||||||||||||||||||||||||||
| 596 | If the exit code matches, then the process is auto restarted. This should | ||||||||||||||||||||||||||||
| 597 | be a comma delimited list of values. | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | =item B<-exit_retries> | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | The optional number of retries for restarting the process. The default | ||||||||||||||||||||||||||||
| 602 | is 5. | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | =item B<-group> | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | The group to run the process under. Defaults to 'nobody'. This group | ||||||||||||||||||||||||||||
| 607 | may not be defined on your system. This option is not implemented on Windows. | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | =item B<-priority> | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | The optional priority to run the process at. Defaults to 0. This option | ||||||||||||||||||||||||||||
| 612 | is not implemented on Windows. | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | =item B<-umask> | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | The optional protection mask for the process. Defaults to '0022'. This | ||||||||||||||||||||||||||||
| 617 | option is not implemented on Windows. | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | =item B<-user> | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | The optional user to run the process under. Defaults to 'nobody'. This user | ||||||||||||||||||||||||||||
| 622 | may not be defined on your system. This option is not implemented on Windows. | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | =item B<-redirect> | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | This option is used to indicate wither to redirect stdout and stderr | ||||||||||||||||||||||||||||
| 627 | from the child process to the parent and stdin from the parent to the | ||||||||||||||||||||||||||||
| 628 | child process. The redirection combines stderr with stdout. Redirection | ||||||||||||||||||||||||||||
| 629 | is implemented using sockets. This may cause buffering problems with the | ||||||||||||||||||||||||||||
| 630 | child process. | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | The default is no. | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | =item B<-input_driver> | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | The optional input driver to use. Defaults to POE::Driver::SysRW. | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | =item B<-output_driver> | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | The optional output driver to use. Defaults to POE::Driver::SysRW. | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | =item B<-input_filter> | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | The optional filter to use for input. Defaults to POE::Filter::Line. | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | =item B<-output_filter> | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | The optional output filter to use. Defaults to POE::Filter::Line. | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | =back | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | =head1 PUBLIC EVENTS | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | The following public events have been defined. The following arguments | ||||||||||||||||||||||||||||
| 655 | are provided by POE as offsets into the argument array. | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | =head2 put_input(OBJECT, ARG0) | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | This event will write a buffer to stdin. | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | =over 4 | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | =item B<ARGO> is the buffer to write out. | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | =back | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | =head2 get_output(OBJECT, ARG0, ARG1) | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | This event will read a buffer for stdout/stderr. | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | =over | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | =item B<ARG0> is the buffer. | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | =item B<ARG1> is the wheel ID. | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | =back | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | =head2 flush_event(OBJECT, ARG0) | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | This event is fired when a flush event happens on stdin. | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | =over 4 | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | =item B<ARG0> is the wheel id that the event happened too. | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | =back | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | =head2 error_event(OBJECT, ARG0..ARG4) | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | This event is fired whenever an error occurs. | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | =over 4 | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | =item B<ARG0> - the operation that was being performed i.e. read/write | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | =item B<ARG1> - the errno that occurred | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | =item B<ARG2> - the errstr for that errno | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | =item B<ARG3> - the wheel ID | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | =item B<ARG4> - the type i.e. INPUT/OUTPUT | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | =back | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | =head2 close_event(OBJECT) | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | This event is fired when a "close" happens on the sockets. | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | =over 4 | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | =item L<XAS|XAS> | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | =back | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | Copyright (C) 2015 Kevin L. Esteb | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 728 | the terms of the Artistic License 2.0. For details, see the full text | ||||||||||||||||||||||||||||
| 729 | of the license at http://www.perlfoundation.org/artistic_license_2_0. | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | =cut | ||||||||||||||||||||||||||||