| 1 |
elmex |
1.1 |
package Net::XMPP2::IM::Account; |
| 2 |
|
|
use strict; |
| 3 |
elmex |
1.2 |
use Net::XMPP2::Util qw/stringprep_jid prep_bare_jid split_jid/; |
| 4 |
elmex |
1.1 |
use Net::XMPP2::IM::Connection; |
| 5 |
|
|
|
| 6 |
|
|
=head1 NAME |
| 7 |
|
|
|
| 8 |
elmex |
1.5 |
Net::XMPP2::IM::Account - Instant messaging account |
| 9 |
elmex |
1.1 |
|
| 10 |
|
|
=head1 SYNOPSIS |
| 11 |
|
|
|
| 12 |
|
|
my $cl = Net::XMPP2::IM::Client->new; |
| 13 |
|
|
... |
| 14 |
|
|
my $acc = $cl->get_account ($jid); |
| 15 |
|
|
|
| 16 |
|
|
=head1 DESCRIPTION |
| 17 |
|
|
|
| 18 |
|
|
This module represents a class for IM accounts. It is used |
| 19 |
|
|
by L<Net::XMPP2::Client>. |
| 20 |
|
|
|
| 21 |
|
|
You can get an instance of this class only by calling the C<get_account> |
| 22 |
|
|
method on a L<Net::XMPP2::Client> object. |
| 23 |
|
|
|
| 24 |
|
|
=cut |
| 25 |
|
|
|
| 26 |
|
|
sub new { |
| 27 |
|
|
my $this = shift; |
| 28 |
|
|
my $class = ref($this) || $this; |
| 29 |
|
|
my $self = bless { @_ }, $class; |
| 30 |
|
|
$self->{jid} = stringprep_jid $self->{jid}; |
| 31 |
|
|
$self |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
sub remove_connection { |
| 35 |
|
|
my ($self) = @_; |
| 36 |
|
|
delete $self->{con} |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
sub spawn_connection { |
| 40 |
elmex |
1.6 |
my ($self, %args) = @_; |
| 41 |
elmex |
1.1 |
|
| 42 |
|
|
$self->{con} = Net::XMPP2::IM::Connection->new ( |
| 43 |
|
|
jid => $self->jid, |
| 44 |
|
|
password => $self->{password}, |
| 45 |
|
|
($self->{host} ? (override_host => $self->{host}) : ()), |
| 46 |
|
|
($self->{port} ? (override_port => $self->{port}) : ()), |
| 47 |
elmex |
1.6 |
%args |
| 48 |
elmex |
1.1 |
) |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
elmex |
1.4 |
=head1 METHODS |
| 52 |
|
|
|
| 53 |
|
|
=over 4 |
| 54 |
|
|
|
| 55 |
|
|
=item B<connection ()> |
| 56 |
elmex |
1.1 |
|
| 57 |
|
|
Returns the L<Net::XMPP2::IM::Connection> object if this account already |
| 58 |
|
|
has one (undef otherwise). |
| 59 |
|
|
|
| 60 |
|
|
=cut |
| 61 |
|
|
|
| 62 |
|
|
sub connection { $_[0]->{con} } |
| 63 |
|
|
|
| 64 |
elmex |
1.4 |
=item B<is_connected ()> |
| 65 |
elmex |
1.1 |
|
| 66 |
|
|
Returns true if this accunt is connected. |
| 67 |
|
|
|
| 68 |
|
|
=cut |
| 69 |
|
|
|
| 70 |
|
|
sub is_connected { |
| 71 |
|
|
my ($self) = @_; |
| 72 |
|
|
$self->{con} && $self->{con}->is_connected |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
elmex |
1.4 |
=item B<jid ()> |
| 76 |
elmex |
1.1 |
|
| 77 |
|
|
Returns either the full JID if the account is |
| 78 |
|
|
connected or returns the bare jid if not. |
| 79 |
|
|
|
| 80 |
|
|
=cut |
| 81 |
|
|
|
| 82 |
|
|
sub jid { |
| 83 |
|
|
my ($self) = @_; |
| 84 |
|
|
if ($self->is_connected) { |
| 85 |
|
|
return $self->{con}->jid; |
| 86 |
|
|
} |
| 87 |
|
|
$_[0]->{jid} |
| 88 |
|
|
} |
| 89 |
|
|
|
| 90 |
elmex |
1.4 |
=item B<bare_jid ()> |
| 91 |
elmex |
1.1 |
|
| 92 |
|
|
Returns always the bare jid of this account. |
| 93 |
|
|
|
| 94 |
|
|
=cut |
| 95 |
|
|
|
| 96 |
|
|
sub bare_jid { |
| 97 |
|
|
my ($self) = @_; |
| 98 |
|
|
prep_bare_jid $self->jid |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
elmex |
1.4 |
=item B<nickname ()> |
| 102 |
elmex |
1.2 |
|
| 103 |
|
|
Your nickname for this account. |
| 104 |
|
|
|
| 105 |
|
|
=cut |
| 106 |
|
|
|
| 107 |
|
|
sub nickname { |
| 108 |
|
|
my ($self) = @_; |
| 109 |
|
|
# FIXME: fetch real nickname from server somehow? Does that exist? |
| 110 |
|
|
# eg. from the roster? |
| 111 |
|
|
my ($user, $host, $res) = split_jid ($self->bare_jid); |
| 112 |
|
|
$user |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
elmex |
1.4 |
=back |
| 116 |
|
|
|
| 117 |
|
|
=head1 AUTHOR |
| 118 |
|
|
|
| 119 |
|
|
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> |
| 120 |
|
|
|
| 121 |
|
|
=head1 COPYRIGHT & LICENSE |
| 122 |
|
|
|
| 123 |
|
|
Copyright 2007 Robin Redeker, all rights reserved. |
| 124 |
|
|
|
| 125 |
|
|
This program is free software; you can redistribute it and/or modify it |
| 126 |
|
|
under the same terms as Perl itself. |
| 127 |
|
|
|
| 128 |
|
|
=cut |
| 129 |
|
|
|
| 130 |
|
|
|
| 131 |
elmex |
1.1 |
1; |