AOL-TOC
view release on metacpan or search on metacpan
package AOL::SFLAP;
use IO;
use IO::Select;
use Socket;
$VERSION = "0.33";
$SFLAP_SIGNON = 1;
$SFLAP_DATA = 2;
$SFLAP_ERROR = 3;
$SFLAP_SIGNOFF = 4;
$SFLAP_KEEPALIVE = 5;
sub register_callback {
my ($self, $chan, $func, @args) = @_;
#print "register_callback() func $func for chan $chan adding to $self->{callback}{$chan}\n";
#print " self $self selfcb = $self->{callback}\n";
push (@{$self->{callback}{$chan}}, $func);
@{$self->{callback}{$func}} = @args;
return;
}
sub clear_callbacks {
my ($self) = @_;
my $k;
print "...............C SFLAP clear_callbacks\n";
for $k (keys %{$self->{callback}}) {
print ".............C Clear key ($k)\n";
delete $self->{callback}{$k};
}
print "...............S SFLAP scan callbacks\n";
for $k (keys %{$self->{callback}}) {
print ".............S Scan key ($k)\n";
}
}
sub callback {
my ($self, $chan, @args) = @_;
my $func;
for $func (@{$self->{callback}{$chan}}) {
#print ("callback() calling a func $func for $chan fd $self->{fd}..\n");
eval { &{$func} ($self, @args, @{$self->{callback}{$func}}) };
}
return;
}
sub new {
my ($tochost, $authorizer, $port, $nickname) = @_;
my $self;
my $ipaddr;
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "invalid port" unless $port;
$ipaddr = inet_aton($tochost);
die "unknown host" unless $ipaddr;
$self = {
tochost => $tochost,
authorizer => $authorizer,
ipaddr => $ipaddr,
port => $port,
nickname => $nickname,
sequence => 1
};
bless($self);
return $self;
}
sub destroy {
my ($self) = @_;
print "sflap destroy\n";
CORE::close($self->{fd});
$self = undef;
return;
}
sub close {
my ($self) = @_;
my $k;
print "sflap close\n";
$self->clear_callbacks();
#CORE::close($self->{fd});
return;
}
sub set_debug {
my ($self, $level) = @_;
$self->{debug_level} = $level;
print "slfap debug level $level\n";
}
( run in 1.974 second using v1.01-cache-2.11-cpan-98e64b0badf )