AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/IM/Account.pm view on Meta::CPAN
package AnyEvent::XMPP::IM::Account;
use strict;
use AnyEvent::XMPP::Util qw/stringprep_jid prep_bare_jid split_jid cmp_jid node_jid/;
use AnyEvent::XMPP::IM::Connection;
use base Object::Event::;
=head1 NAME
AnyEvent::XMPP::IM::Account - Instant messaging account
=head1 SYNOPSIS
my $cl = AnyEvent::XMPP::IM::Client->new;
...
my $acc = $cl->get_account ($jid);
=head1 DESCRIPTION
This module represents a class for IM accounts. It is used
by L<AnyEvent::XMPP::Client>.
You can get an instance of this class only by calling the C<get_account>
method on a L<AnyEvent::XMPP::Client> object.
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = bless { @_ }, $class;
$self
}
sub remove_connection {
my ($self) = @_;
delete $self->{con}
}
sub spawn_connection {
my ($self, %args) = @_;
$self->{con} = AnyEvent::XMPP::IM::Connection->new (
jid => $self->jid,
password => $self->{password},
(defined $self->{host} ? (host => $self->{host}) : ()),
(defined $self->{port} ? (port => $self->{port}) : ()),
%args,
%{$self->{args} || {}},
);
$self->{con}->reg_cb (
ext_before_session_ready => sub {
my ($con) = @_;
$self->{track} = {};
},
ext_before_message => sub {
my ($con, $msg) = @_;
my $t = $self->{track};
my $pfrom = prep_bare_jid $msg->from;
if (not (exists $t->{$pfrom}) || !cmp_jid ($t->{$pfrom}, $msg->from)) {
$t->{$pfrom} = $msg->from;
$self->event (tracked_message_destination => $pfrom, $msg->from);
}
}
);
$self->{con}
}
=head1 METHODS
=over 4
=item B<connection ()>
Returns the L<AnyEvent::XMPP::IM::Connection> object if this account already
has one (undef otherwise).
=cut
sub connection { $_[0]->{con} }
=item B<is_connected ()>
Returns true if this accunt is connected.
=cut
sub is_connected {
my ($self) = @_;
$self->{con} && $self->{con}->is_connected
}
=item B<jid ()>
Returns either the full JID if the account is
connected or returns the bare jid if not.
=cut
sub jid {
my ($self) = @_;
if ($self->is_connected) {
( run in 0.591 second using v1.01-cache-2.11-cpan-39bf76dae61 )