Created
January 7, 2010 02:08
-
-
Save hinrik/270905 to your computer and use it in GitHub Desktop.
t/90_regression/hinrik-followtail.t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# vim: ts=2 sw=2 filetype=perl expandtab | |
use strict; | |
use POE qw(Wheel::FollowTail); | |
use Test::More tests => 2; | |
my $filename = 'hinrik-followtail'; | |
open FH, ">$filename" or die "$!\n"; | |
print FH "moocow\n"; | |
POE::Session->create( | |
package_states => [ | |
'main' => [qw(_start _input _error _shutdown)], | |
], | |
heap => { filename => $filename, }, | |
); | |
$poe_kernel->run(); | |
exit 0; | |
sub _start { | |
my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
$heap->{wheel} = POE::Wheel::FollowTail->new( | |
Filter => POE::Filter::Line->new( Literal => "\n" ), | |
Filename => $heap->{filename}, | |
InputEvent => '_input', | |
ErrorEvent => '_error', | |
); | |
$heap->{counter} = 0; | |
print FH "Cows go moo, yes they do\n"; | |
close FH; | |
return; | |
} | |
sub _shutdown { | |
delete $_[HEAP]->{wheel}; | |
return; | |
} | |
sub _input { | |
my ($kernel,$heap,$input) = @_[KERNEL,HEAP,ARG0]; | |
# make sure we got the right line | |
is($input, 'Cows go moo, yes they do', 'Got the right line'); | |
$heap->{counter}++; | |
ok( $heap->{counter} == 1, 'Cows went moo' ); | |
$kernel->delay( '_shutdown', 5 ); # Wait five seconds. | |
return; | |
} | |
sub _error { | |
my ($heap,$operation, $errnum, $errstr, $wheel_id) = @_[HEAP,ARG0..ARG3]; | |
diag("Wheel $wheel_id generated $operation error $errnum: $errstr\n"); | |
delete $heap->{wheel}; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment