|
Revision 13211, 1.4 kB
(checked in by daisuke, 5 years ago)
|
|
more coersion control
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | package XMPP::Bomber::Role::Client; |
|---|
| 2 | use Moose::Role; |
|---|
| 3 | use XMPP::Bomber::Types; |
|---|
| 4 | |
|---|
| 5 | requires 'run'; |
|---|
| 6 | |
|---|
| 7 | has 'xmpp_args' => ( |
|---|
| 8 | is => 'rw', |
|---|
| 9 | isa => 'HashRef', |
|---|
| 10 | auto_deref => 1, |
|---|
| 11 | default => sub { +{} } |
|---|
| 12 | ); |
|---|
| 13 | |
|---|
| 14 | has 'server' => ( |
|---|
| 15 | is => 'rw', |
|---|
| 16 | isa => 'XMPP::Bomber::Server', |
|---|
| 17 | coerce => 1, |
|---|
| 18 | required => 1, |
|---|
| 19 | ); |
|---|
| 20 | |
|---|
| 21 | has 'accounts' => ( |
|---|
| 22 | is => 'rw', |
|---|
| 23 | isa => 'AccountList', |
|---|
| 24 | auto_deref => 1, |
|---|
| 25 | coerce => 1, |
|---|
| 26 | required => 1, |
|---|
| 27 | ); |
|---|
| 28 | |
|---|
| 29 | has 'recipients' => ( |
|---|
| 30 | is => 'rw', |
|---|
| 31 | isa => 'AccountList', |
|---|
| 32 | auto_deref => 1, |
|---|
| 33 | ); |
|---|
| 34 | |
|---|
| 35 | has 'condvar' => ( |
|---|
| 36 | is => 'rw', |
|---|
| 37 | default => sub { AnyEvent->condvar } |
|---|
| 38 | ); |
|---|
| 39 | |
|---|
| 40 | has 'content_provider' => ( |
|---|
| 41 | is => 'rw', |
|---|
| 42 | does => 'XMPP::Bomber::Role::ContentProvider', |
|---|
| 43 | coerce => 1, |
|---|
| 44 | ); |
|---|
| 45 | |
|---|
| 46 | has 'recipient_chooser' => ( |
|---|
| 47 | is => 'rw', |
|---|
| 48 | does => 'XMPP::Bomber::Role::RecipientChooser', |
|---|
| 49 | coerce => 1, |
|---|
| 50 | ); |
|---|
| 51 | |
|---|
| 52 | no Moose; |
|---|
| 53 | |
|---|
| 54 | use Net::XMPP2; |
|---|
| 55 | use Net::XMPP2::Client; |
|---|
| 56 | use XMPP::Bomber::Server; |
|---|
| 57 | |
|---|
| 58 | sub create_client |
|---|
| 59 | { |
|---|
| 60 | my $self = shift; |
|---|
| 61 | |
|---|
| 62 | my $client = Net::XMPP2::Client->new( $self->xmpp_args ); |
|---|
| 63 | |
|---|
| 64 | $client->set_exception_cb( sub { |
|---|
| 65 | print STDERR "Received exception $_[0]\n"; |
|---|
| 66 | $self->condvar->broadcast |
|---|
| 67 | } ); |
|---|
| 68 | my $server = $self->server; |
|---|
| 69 | |
|---|
| 70 | foreach my $account ($self->accounts) { |
|---|
| 71 | $client->add_account( |
|---|
| 72 | $account->destination, |
|---|
| 73 | $account->password, |
|---|
| 74 | $server->hostname, |
|---|
| 75 | $server->port, |
|---|
| 76 | ) |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | return $client; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | 1; |
|---|