#!/usr/bin/perl # Simple process manager, using POE::Wheel::Run. # Illustrates using POE::Wheel::Run to manage a # child process while possibly doing other work. # May be extended to manage multiple child # processes. Combine with a worker pool for more # enjoyment. # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! use warnings; use strict; use POE qw(Wheel::Run); $| = 1; POE::Session->create( inline_states => { _start => \&handle_start, got_input => \&handle_input, ping => \&handle_ping, }, ); POE::Kernel->run(); exit; sub handle_start { $_[HEAP]->{runner} = POE::Wheel::Run->new( Program => \&process_input, StdoutEvent => 'got_input', ); $_[HEAP]->{runner}->put("gnat"); $_[KERNEL]->delay(ping => 0.1); } sub handle_input { print "Got child output: $_[ARG0]\n"; $_[HEAP]->{runner}->put($_[ARG0]); } sub handle_ping { print "."; $_[KERNEL]->delay(ping => 0.1); } sub process_input { while () { tr[a-zA-Z][n-za-mN-ZA-M]; print; sleep 1; } }