Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a small example program that shows how to read from a filehandl…

…e with POE::Wheel::ReadWrite
  • Loading branch information...
commit 4f21b5dd0743ff832a5b1e28915eeeae99ac7210 1 parent 076f3d8
@bingos bingos authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 small-programs/reading-filehandle.pl
View
39 small-programs/reading-filehandle.pl
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+use POE qw[Wheel::ReadWrite];
+
+$|=1;
+
+my $file = shift or die "Please specify a file to read\n";
+
+POE::Session->create(
+ package_states => [
+ 'main' => [qw(_start _input _error)],
+ ],
+);
+
+$poe_kernel->run();
+exit 0;
+
+sub _start {
+ open my $fh, '<', $file or die "$!\n";
+ $_[HEAP]->{file} = POE::Wheel::ReadWrite->new(
+ Handle => $fh,
+ InputEvent => '_input',
+ ErrorEvent => '_error',
+ );
+ return;
+}
+
+sub _input {
+ my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1];
+ print "$input\n";
+ return;
+}
+
+sub _error {
+ my ($operation, $errnum, $errstr, $id) = @_[ARG0..ARG3];
+ warn "Wheel $id encountered $operation error $errnum: $errstr\n";
+ delete $_[HEAP]{file}; # shut down that wheel
+ return;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.