Software /
code /
prosody-modules
Comparison
mod_lib_ldap/dev/t/TestConnection.pm @ 809:1d51c5e38faa
Add LDAP plugin suite
author | rob@hoelz.ro |
---|---|
date | Sun, 02 Sep 2012 15:35:50 +0200 |
child | 866:8495dae58d78 |
comparison
equal
deleted
inserted
replaced
808:ba2e207e1fb7 | 809:1d51c5e38faa |
---|---|
1 package TestConnection; | |
2 | |
3 use strict; | |
4 use warnings; | |
5 use parent 'AnyEvent::XMPP::IM::Connection'; | |
6 | |
7 use 5.010; | |
8 | |
9 our $HOST = 'localhost'; | |
10 our $TIMEOUT = 5; | |
11 our %PASSWORD_FOR = ( | |
12 one => '12345', | |
13 two => '23451', | |
14 three => '34512', | |
15 four => '45123', | |
16 five => '51234', | |
17 ); | |
18 | |
19 sub new { | |
20 my ( $class, $username, %options ) = @_; | |
21 | |
22 my $cond = AnyEvent->condvar; | |
23 my $timer = AnyEvent->timer( | |
24 after => $TIMEOUT, | |
25 cb => sub { | |
26 $cond->send('timeout'); | |
27 }, | |
28 ); | |
29 | |
30 my $self = $class->SUPER::new( | |
31 username => $username, | |
32 domain => $HOST, | |
33 password => $options{'password'} // $PASSWORD_FOR{$username}, | |
34 ); | |
35 | |
36 $self->reg_cb(error => sub { | |
37 my ( undef, $error ) = @_; | |
38 | |
39 $cond->send($error->string); | |
40 }); | |
41 | |
42 bless $self, $class; | |
43 | |
44 $self->{'condvar'} = $cond; | |
45 $self->{'timeout_timer'} = $timer; | |
46 | |
47 $self->connect; | |
48 | |
49 return $self; | |
50 } | |
51 | |
52 sub cond { | |
53 my ( $self ) = @_; | |
54 | |
55 return $self->{'condvar'}; | |
56 } | |
57 | |
58 1; |