PerlIO::via::Timeout - a PerlIO layer that adds read & write timeout to a handle
version 0.13
use PerlIO::via::Timeout qw(timeout_strategy); open my $fh, '<:via(Timeout)', 'foo.html'; # creates a new timeout strategy with 0.5 second timeout, using select as # timeout system timeout_strategy($fh, 'Select', read_timeout => 0.5); my $line = <$fh>; if ($line == undef && $! eq 'Operation timed out') { ... }
This package implements a PerlIO layer, that adds read / write timeout. This can be useful to avoid blocking while accessing a filehandle, and fail after some time.
# creates a L<PerlIO::via::Timeout::Strategy::Select strategy> with 0.5 # read_timeout and set it to $fh timeout_strategy($fh, 'Select', read_timeout => 0.5); # same but give a strategy instance directly my $strategy = PerlIO::via::Timeout::Strategy::Select->new(write_timeout => 2) timeout_strategy($fh, $strategy); # used as a getter, returns the current strategy my $strategy = timeout_strategy($fh);
Damien "dams" Krotkine
This software is copyright (c) 2013 by Damien "dams" Krotkine.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install PerlIO::via::Timeout, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PerlIO::via::Timeout
CPAN shell
perl -MCPAN -e shell install PerlIO::via::Timeout
For more information on module installation, please visit the detailed CPAN module installation guide.