ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/IM/Account.pm
Revision: 1.4
Committed: Wed Jul 4 16:05:22 2007 UTC (19 years, 4 months ago) by elmex
Branch: MAIN
Changes since 1.3: +25 -6 lines
Log Message:
major documentation refresh. preparing for release

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     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     my ($self) = @_;
41    
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     )
48     }
49    
50 elmex 1.4 =head1 METHODS
51    
52     =over 4
53    
54     =item B<connection ()>
55 elmex 1.1
56     Returns the L<Net::XMPP2::IM::Connection> object if this account already
57     has one (undef otherwise).
58    
59     =cut
60    
61     sub connection { $_[0]->{con} }
62    
63 elmex 1.4 =item B<is_connected ()>
64 elmex 1.1
65     Returns true if this accunt is connected.
66    
67     =cut
68    
69     sub is_connected {
70     my ($self) = @_;
71     $self->{con} && $self->{con}->is_connected
72     }
73    
74 elmex 1.4 =item B<jid ()>
75 elmex 1.1
76     Returns either the full JID if the account is
77     connected or returns the bare jid if not.
78    
79     =cut
80    
81     sub jid {
82     my ($self) = @_;
83     if ($self->is_connected) {
84     return $self->{con}->jid;
85     }
86     $_[0]->{jid}
87     }
88    
89 elmex 1.4 =item B<bare_jid ()>
90 elmex 1.1
91     Returns always the bare jid of this account.
92    
93     =cut
94    
95     sub bare_jid {
96     my ($self) = @_;
97     prep_bare_jid $self->jid
98     }
99    
100 elmex 1.4 =item B<nickname ()>
101 elmex 1.2
102     Your nickname for this account.
103    
104     =cut
105    
106     sub nickname {
107     my ($self) = @_;
108     # FIXME: fetch real nickname from server somehow? Does that exist?
109     # eg. from the roster?
110     my ($user, $host, $res) = split_jid ($self->bare_jid);
111     $user
112     }
113    
114 elmex 1.4 =back
115    
116     =head1 AUTHOR
117    
118     Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
119    
120     =head1 COPYRIGHT & LICENSE
121    
122     Copyright 2007 Robin Redeker, all rights reserved.
123    
124     This program is free software; you can redistribute it and/or modify it
125     under the same terms as Perl itself.
126    
127     =cut
128    
129    
130 elmex 1.1 1;