AnyEvent-Connection
view release on metacpan or search on metacpan
lib/AnyEvent/Connection.pm view on Meta::CPAN
weaken( my $self = shift );
my $interval = shift;
my $cb = shift;
#warn "Create after $interval";
$self->{timers}{int $cb} = AnyEvent->timer(
after => $interval,
cb => sub {
$self or return;
delete $self->{timers}{int $cb};
$cb->();
undef $cb;
},
);
defined wantarray and return AnyEvent::Util::guard(sub {
delete $self->{timers}{int $cb};
undef $cb;
});
return;
}
sub reconnect {
my $self = shift;
$self->disconnect;
$self->connect;
}
sub disconnect {
my $self = shift;
#$self->{con} or return;
#warn "Disconnecting $self->{connected} || $self->{connecting} || $self->{reconnect} by @{[ (caller)[1,2] ]}";
ref $self->{con} eq 'HASH' and warn dumper($self->{con});
$self->{con} and eval{ $self->{con}->close; };
warn if $@;
delete $self->{con};
my $wascon = $self->{connected} || $self->{connecting};
$self->{connected} = 0;
$self->{connecting} = 0;
#$self->{reconnect} = 0;
delete $self->{timers}{reconnect};
$self->event('disconnect',@_) if $wascon;
return;
}
sub AnyEvent::Connection::destroyed::AUTOLOAD {}
sub destroy {
my ($self) = @_;
$self->DESTROY;
bless $self, "AnyEvent::Connection::destroyed";
}
sub DESTROY {
my $self = shift;
warn "(".int($self).") Destroying AE::CNN" if $self->{debug};
$self->disconnect;
%$self = ();
}
BEGIN {
no strict 'refs';
for my $m (qw(push_write push_read unshift_read say reply recv command want_command)) {
*$m = sub {
my $self = shift;
$self->{connected} or return $self->event( error => "Not connected for $m" );
$self->{con}->$m(@_);
};
}
}
=head1 AUTHOR
Mons Anderson, C<< <mons at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-anyevent-connection at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Connection>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc AnyEvent::Connection
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Connection>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/AnyEvent-Connection>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/AnyEvent-Connection>
=item * Search CPAN
L<http://search.cpan.org/dist/AnyEvent-Connection/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 COPYRIGHT & LICENSE
Copyright 2009 Mons Anderson, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
( run in 0.978 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )