There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

NAME

PerlIO::via::Timeout - a PerlIO layer that adds read & write timeout to a handle

VERSION

version 0.14

SYNOPSIS

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') { ... }

DESCRIPTION

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.

FUNCTIONS

timeout_strategy

# 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 an alarm strategy instance directly
my $strategy = PerlIO::via::Timeout::Strategy::Alarm->new(write_timeout => 2)
timeout_strategy($fh, $strategy);

# used as a getter, returns the current strategy
my $strategy = timeout_strategy($fh);

AVAILABLE STRATEGIES

PerlIO::via::Timeout::Strategy::Select
PerlIO::via::Timeout::Strategy::Alarm

SEE ALSO

PerlIO::via

THANKS TO

Vincent Pit
Christian Hansen
Leon Timmmermans

AUTHOR

Damien "dams" Krotkine

COPYRIGHT AND LICENSE

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.