| 1 |
elmex |
1.1 |
package Net::XMPP2::IM::Message; |
| 2 |
|
|
use strict; |
| 3 |
|
|
use overload |
| 4 |
|
|
'""' => "to_string"; |
| 5 |
|
|
|
| 6 |
|
|
=head1 NAME |
| 7 |
|
|
|
| 8 |
|
|
Net::XMPP2::IM::Message - An instant message |
| 9 |
|
|
|
| 10 |
|
|
=head1 SYNOPSIS |
| 11 |
|
|
|
| 12 |
|
|
use Net::XMPP2::IM::Message; |
| 13 |
|
|
|
| 14 |
|
|
my $con = Net::XMPP2::IM::Connection->new (...); |
| 15 |
|
|
... |
| 16 |
|
|
my $ro = Net::XMPP2::IM::Roster->new (connection => $con); |
| 17 |
|
|
|
| 18 |
|
|
=head1 DESCRIPTION |
| 19 |
|
|
|
| 20 |
|
|
This module represents a class for roster objects which contain |
| 21 |
|
|
contact information. |
| 22 |
|
|
|
| 23 |
|
|
=cut |
| 24 |
|
|
|
| 25 |
|
|
sub new { |
| 26 |
|
|
my $this = shift; |
| 27 |
|
|
my $class = ref($this) || $this; |
| 28 |
|
|
bless { @_ }, $class; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
sub to_string { |
| 32 |
|
|
my ($self) = @_; |
| 33 |
|
|
$self->body |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
sub from { |
| 37 |
|
|
my ($self, $from) = @_; |
| 38 |
|
|
$self->{from} = $from if defined $from; |
| 39 |
|
|
$self->{from} |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
|
sub to { |
| 43 |
|
|
my ($self, $to) = @_; |
| 44 |
|
|
$self->{to} = $to if defined $to; |
| 45 |
|
|
$self->{to} |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
sub make_reply { |
| 49 |
|
|
my ($self, $msg) = @_; |
| 50 |
|
|
|
| 51 |
|
|
unless ($msg) { |
| 52 |
|
|
$msg = Net::XMPP2::IM::Message->new (); |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
|
$msg->{connection} = $self->{connection}; |
| 56 |
|
|
$msg->to ($self->from); |
| 57 |
|
|
$msg->type ($self->type); |
| 58 |
|
|
|
| 59 |
|
|
$msg |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
sub reply { |
| 63 |
|
|
my ($self, $msg, $type) = @_; |
| 64 |
|
|
|
| 65 |
|
|
if (ref $msg) { |
| 66 |
|
|
$self->make_reply ($msg) |
| 67 |
|
|
|
| 68 |
|
|
} else { |
| 69 |
|
|
my $txt = $msg; |
| 70 |
|
|
$msg = $self->make_reply; |
| 71 |
|
|
$msg->add_body ($txt); |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
$msg->send |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
sub send { |
| 78 |
|
|
my ($self) = @_; |
| 79 |
|
|
|
| 80 |
|
|
my @add; |
| 81 |
|
|
push @add, (subject => $self->{subjects}) |
| 82 |
|
|
if %{$self->{subjects} || {}}; |
| 83 |
|
|
push @add, (thread => $self->thread) |
| 84 |
|
|
if $self->thread; |
| 85 |
|
|
|
| 86 |
|
|
$self->{connection}->send_message ( |
| 87 |
|
|
$self->to, $self->type, undef, |
| 88 |
|
|
body => $self->{bodies}, |
| 89 |
|
|
@add |
| 90 |
|
|
); |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
sub type { |
| 94 |
|
|
my ($self, $type) = @_; |
| 95 |
|
|
$self->{type} = $type |
| 96 |
|
|
if defined $type; |
| 97 |
|
|
$self->{type} |
| 98 |
|
|
} |
| 99 |
|
|
|
| 100 |
|
|
sub thread { |
| 101 |
|
|
my ($self, $thread) = @_; |
| 102 |
|
|
$self->{thread} = $thread |
| 103 |
|
|
if defined $thread; |
| 104 |
|
|
$self->{thread} |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
|
sub subject { |
| 108 |
|
|
my ($self, $lang) = @_; |
| 109 |
|
|
|
| 110 |
|
|
if (defined $lang) { |
| 111 |
|
|
return $self->{subjects}->{$lang} |
| 112 |
|
|
} else { |
| 113 |
|
|
return $self->{subjects}->{''} |
| 114 |
|
|
if defined $self->{subjects}->{''}; |
| 115 |
|
|
return $self->{subjects}->{en} |
| 116 |
|
|
if defined $self->{subjects}->{en}; |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
undef |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
sub add_subject { |
| 123 |
|
|
my ($self, $subject, $lang) = @_; |
| 124 |
|
|
$self->{subjects}->{$lang || ''} = $subject; |
| 125 |
|
|
} |
| 126 |
|
|
|
| 127 |
|
|
sub body { |
| 128 |
|
|
my ($self, $lang) = @_; |
| 129 |
|
|
|
| 130 |
|
|
if (defined $lang) { |
| 131 |
|
|
return $self->{bodies}->{$lang} |
| 132 |
|
|
} else { |
| 133 |
|
|
return $self->{bodies}->{''} |
| 134 |
|
|
if defined $self->{bodies}->{''}; |
| 135 |
|
|
return $self->{bodies}->{en} |
| 136 |
|
|
if defined $self->{bodies}->{en}; |
| 137 |
|
|
} |
| 138 |
|
|
|
| 139 |
|
|
undef |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
sub add_body { |
| 143 |
|
|
my ($self, $body, $lang) = @_; |
| 144 |
|
|
$self->{bodies}->{$lang || ''} = $body; |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
|
|
=head1 AUTHOR |
| 148 |
|
|
|
| 149 |
|
|
Robin Redeker, C<< <elmex at ta-sa.org> >> |
| 150 |
|
|
|
| 151 |
|
|
=head1 BUGS |
| 152 |
|
|
|
| 153 |
|
|
Please report any bugs or feature requests to |
| 154 |
|
|
C<bug-net-xmpp2 at rt.cpan.org>, or through the web interface at |
| 155 |
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-XMPP2>. |
| 156 |
|
|
I will be notified, and then you'll automatically be notified of progress on |
| 157 |
|
|
your bug as I make changes. |
| 158 |
|
|
|
| 159 |
|
|
=head1 SUPPORT |
| 160 |
|
|
|
| 161 |
|
|
You can find documentation for this module with the perldoc command. |
| 162 |
|
|
|
| 163 |
|
|
perldoc Net::XMPP2 |
| 164 |
|
|
|
| 165 |
|
|
You can also look for information at: |
| 166 |
|
|
|
| 167 |
|
|
=over 4 |
| 168 |
|
|
|
| 169 |
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
| 170 |
|
|
|
| 171 |
|
|
L<http://annocpan.org/dist/Net-XMPP2> |
| 172 |
|
|
|
| 173 |
|
|
=item * CPAN Ratings |
| 174 |
|
|
|
| 175 |
|
|
L<http://cpanratings.perl.org/d/Net-XMPP2> |
| 176 |
|
|
|
| 177 |
|
|
=item * RT: CPAN's request tracker |
| 178 |
|
|
|
| 179 |
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-XMPP2> |
| 180 |
|
|
|
| 181 |
|
|
=item * Search CPAN |
| 182 |
|
|
|
| 183 |
|
|
L<http://search.cpan.org/dist/Net-XMPP2> |
| 184 |
|
|
|
| 185 |
|
|
=back |
| 186 |
|
|
|
| 187 |
|
|
=head1 ACKNOWLEDGEMENTS |
| 188 |
|
|
|
| 189 |
|
|
=head1 COPYRIGHT & LICENSE |
| 190 |
|
|
|
| 191 |
|
|
Copyright 2007 Robin Redeker, all rights reserved. |
| 192 |
|
|
|
| 193 |
|
|
This program is free software; you can redistribute it and/or modify it |
| 194 |
|
|
under the same terms as Perl itself. |
| 195 |
|
|
|
| 196 |
|
|
=cut |
| 197 |
|
|
|
| 198 |
|
|
|
| 199 |
|
|
|
| 200 |
|
|
1; # End of Net::XMPP2 |