Net::UCP::IntTimeout - Perl Timeout Manager for Net::UCP Module


Net-UCP-IntTimeout documentation Contained in the Net-UCP-IntTimeout distribution.

Index


Code Index:

NAME

Top

Net::UCP::IntTimeout - Perl Timeout Manager for Net::UCP Module

SYNOPSIS

Top

  use Net::UCP::IntTimeout;

DESCRIPTION

Top

This module is used by Net::UCP to manage timeout during message transmission

EXPORT

None

SEE ALSO

Top

Net::UCP

AUTHOR

Top

Marco Romano, <nemux@cpan.org>

COPYRIGHT AND LICENSE

Top


Net-UCP-IntTimeout documentation Contained in the Net-UCP-IntTimeout distribution.

package Net::UCP::IntTimeout;

use 5.008007;
use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw();

our $VERSION = '0.05';

use constant MIN_TIMEOUT     => 0;           # No timeout at all!
use constant DEFAULT_TIMEOUT => 15;
use constant MAX_TIMEOUT     => 60;

sub new { bless({}, shift())->_init(@_); }

sub _init {
    my $self = shift;
    my %opt = @_;

    $self->set($opt{timeout}) if (exists $opt{timeout});
    return $self;
}

sub set {
    my $self = shift;
    my $timeout = shift || DEFAULT_TIMEOUT;

    if ($timeout > MAX_TIMEOUT) {
        $timeout = MAX_TIMEOUT;
    }
    elsif ($timeout < MIN_TIMEOUT) {
        $timeout = MIN_TIMEOUT;
    }
    
    return $self->{timeout} = $timeout;
}

sub get {
    my $self = shift;
    return $self->{timeout};
}

1;
__END__