<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package TestConnection;

use strict;
use warnings;
use parent 'AnyEvent::XMPP::IM::Connection';

use 5.010;

our $HOST         = 'localhost';
our $TIMEOUT      = 5;
our %PASSWORD_FOR = (
    one   =&gt; '12345',
    two   =&gt; '23451',
    three =&gt; '34512',
    four  =&gt; '45123',
    five  =&gt; '51234',
    six   =&gt; '123456',
    seven =&gt; '1234567',
);

sub new {
    my ( $class, $username, %options ) = @_;

    my $cond  = AnyEvent-&gt;condvar;
    my $timer = AnyEvent-&gt;timer(
        after =&gt; $TIMEOUT,
        cb    =&gt; sub {
            $cond-&gt;send('timeout');
        },
    );

    my $self = $class-&gt;SUPER::new(
        username =&gt; $username,
        domain   =&gt; $HOST,
        password =&gt; $options{'password'} // $PASSWORD_FOR{$username},
        resource =&gt; 'test bot',
    );

    $self-&gt;reg_cb(error =&gt; sub {
        my ( undef, $error ) = @_;

        $cond-&gt;send($error-&gt;string);
    });

    bless $self, $class;

    $self-&gt;{'condvar'}       = $cond;
    $self-&gt;{'timeout_timer'} = $timer;

    $self-&gt;connect;

    return $self;
}

sub cond {
    my ( $self ) = @_;

    return $self-&gt;{'condvar'};
}

1;
</pre></body></html>