ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/IM/Account.pm
Revision: 1.1
Committed: Fri Apr 20 14:56:45 2007 UTC (19 years, 6 months ago) by elmex
Branch: MAIN
Log Message:
implemented Client.pm. Implemented error objects which simplyfied
the error reporting.

File Contents

# User Rev Content
1 elmex 1.1 package Net::XMPP2::IM::Account;
2     use strict;
3     use Net::XMPP2::Util qw/stringprep_jid prep_bare_jid/;
4     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     ($self->{host} ? (override_host => $self->{host}) : ()),
47     ($self->{port} ? (override_port => $self->{port}) : ()),
48     )
49     }
50    
51     =head2 connection ()
52    
53     Returns the L<Net::XMPP2::IM::Connection> object if this account already
54     has one (undef otherwise).
55    
56     =cut
57    
58     sub connection { $_[0]->{con} }
59    
60     =head2 is_connected ()
61    
62     Returns true if this accunt is connected.
63    
64     =cut
65    
66     sub is_connected {
67     my ($self) = @_;
68     $self->{con} && $self->{con}->is_connected
69     }
70    
71     =head2 jid ()
72    
73     Returns either the full JID if the account is
74     connected or returns the bare jid if not.
75    
76     =cut
77    
78     sub jid {
79     my ($self) = @_;
80     if ($self->is_connected) {
81     return $self->{con}->jid;
82     }
83     $_[0]->{jid}
84     }
85    
86     =head2 bare_jid ()
87    
88     Returns always the bare jid of this account.
89    
90     =cut
91    
92     sub bare_jid {
93     my ($self) = @_;
94     prep_bare_jid $self->jid
95     }
96    
97     1;