ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/IM/Account.pm
Revision: 1.2
Committed: Sun Jun 24 17:17:43 2007 UTC (19 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.1: +16 -1 lines
Log Message:
fixed some issues and rounded up the client for usage in Net::Bummskraut

File Contents

# User Rev Content
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     Net::XMPP2::IM::Account - An instant messaging account
9    
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    
27     sub new {
28     my $this = shift;
29     my $class = ref($this) || $this;
30     my $self = bless { @_ }, $class;
31     $self->{jid} = stringprep_jid $self->{jid};
32     $self
33     }
34    
35     sub remove_connection {
36     my ($self) = @_;
37     delete $self->{con}
38     }
39    
40     sub spawn_connection {
41     my ($self) = @_;
42    
43     $self->{con} = Net::XMPP2::IM::Connection->new (
44     jid => $self->jid,
45     password => $self->{password},
46 elmex 1.2 disable_ssl => 1,
47 elmex 1.1 ($self->{host} ? (override_host => $self->{host}) : ()),
48     ($self->{port} ? (override_port => $self->{port}) : ()),
49     )
50     }
51    
52     =head2 connection ()
53    
54     Returns the L<Net::XMPP2::IM::Connection> object if this account already
55     has one (undef otherwise).
56    
57     =cut
58    
59     sub connection { $_[0]->{con} }
60    
61     =head2 is_connected ()
62    
63     Returns true if this accunt is connected.
64    
65     =cut
66    
67     sub is_connected {
68     my ($self) = @_;
69     $self->{con} && $self->{con}->is_connected
70     }
71    
72     =head2 jid ()
73    
74     Returns either the full JID if the account is
75     connected or returns the bare jid if not.
76    
77     =cut
78    
79     sub jid {
80     my ($self) = @_;
81     if ($self->is_connected) {
82     return $self->{con}->jid;
83     }
84     $_[0]->{jid}
85     }
86    
87     =head2 bare_jid ()
88    
89     Returns always the bare jid of this account.
90    
91     =cut
92    
93     sub bare_jid {
94     my ($self) = @_;
95     prep_bare_jid $self->jid
96     }
97    
98 elmex 1.2 =head2 nickname ()
99    
100     Your nickname for this account.
101    
102     =cut
103    
104     sub nickname {
105     my ($self) = @_;
106     # FIXME: fetch real nickname from server somehow? Does that exist?
107     # eg. from the roster?
108     my ($user, $host, $res) = split_jid ($self->bare_jid);
109     $user
110     }
111    
112 elmex 1.1 1;