Net-Async-XMPP

 view release on metacpan or  search on metacpan

lib/Net/Async/XMPP/Protocol.pm  view on Meta::CPAN

package Net::Async::XMPP::Protocol;
$Net::Async::XMPP::Protocol::VERSION = '0.003';
use strict;
use warnings;
use parent qw{IO::Async::Stream};

=head1 NAME

Net::Async::XMPP::Protocol - common protocol support for L<Net::Async::XMPP>

=head1 VERSION

Version 0.003

=head1 METHODS

=cut

use IO::Async::Resolver::DNS;
use IO::Async::SSL;
use IO::Socket::SSL qw(SSL_VERIFY_NONE);
use Socket qw(getnameinfo IPPROTO_TCP NI_NUMERICHOST NI_NUMERICSERV SOCK_STREAM);
use Protocol::XMPP::Stream;
use Future::Utils 'repeat';
use curry::weak;

# 'resolver' for regular lookup, 'dns' for DNS-specific
# regular resolver does not appear to implement weight/priority,
# so if you're using a service such as google.com then you'll need
# 'dns' here.
use constant SRV_IMPLEMENTATION => 'dns';

=head2 xmpp

Accessor for the underyling XMPP L<Protocol::XMPP::Stream> object.

=cut

sub xmpp {
	my $self = shift;
	unless($self->{xmpp}) {
		$self->{xmpp} = Protocol::XMPP::Stream->new(
			debug => $self->{debug} ? 1 : 0,
			future_factory => $self->loop->curry::weak::new_future,
			on_queued_write => $self->_capture_weakself(sub {
				my $self = shift;
				$self->{_writing_future} = (repeat {
					my $next = $self->xmpp->extract_write_and_future;
					$self->write($next->[0])->on_ready($next->[1]);
				} while => sub {
					$self->xmpp->ready_to_send
				})->on_ready(sub {
					$self->maybe_invoke_event('on_write_finished');
					delete $self->{_writing_future}
				});
			}),
			on_starttls => $self->_capture_weakself(sub {
				my $self = shift;
				$self->on_starttls;
			}),
		);
	}
	return $self->{xmpp};
}

=head2 configure

Configure our handlers.

=cut

sub configure {
	my $self = shift;
	my %params = @_;

	$self->{state} ||= {
		connected => 0,
		loggedin => 0
	};
	$self->{debug} = delete $params{debug} if exists $params{debug};



( run in 2.145 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )