XMPP/Ext/MUC/Message.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 83 CC 7 SCAR 24.8
CC
7
Cov
0%
send
30.0
make_reply
12.0
new
2.0
CRAP 12.0
1 package AnyEvent::XMPP::Ext::MUC::Message;
2 use strict;
3 use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
4 use AnyEvent::XMPP::Util qw/bare_jid res_jid/;
5 use AnyEvent::XMPP::IM::Message;
6  
7 our @ISA = qw/AnyEvent::XMPP::IM::Message/;
8  
9 =head1 NAME
10  
11 AnyEvent::XMPP::Ext::MUC::Message - A room message
12  
13 =head1 SYNOPSIS
14  
15 =head1 DESCRIPTION
16  
17 This message represents a message from a MUC room. It is
18 derived from L<AnyEvent::XMPP::IM::Message>. (You can use the
19 methods from that class to access it for example).
20  
21 Also the methods like eg. C<make_reply> return a
22 L<AnyEvent::XMPP::Ext::MUC::Message>.
23  
24 =head1 METHODS
25  
26 =over 4
27  
28 =item B<new (%args)>
29  
30 This constructor takes the same arguments that the constructor for
31 L<AnyEvent::XMPP::IM::Message> takes.
32  
33 =cut
34  
35 sub new {
36 my $this = shift;
37 my $class = ref($this) || $this;
38 my $self = $class->SUPER::new (@_);
39 $self->{connection} = $self->{room}->{connection};
40 $self
41 }
42  
43 sub from_node {
44 my ($self, $node) = @_;
45 $self->SUPER::from_node ($node);
46 }
47  
48 =item B<room>
49  
50 Returns the chatroom in which' context this message
51 was sent.
52  
53 =cut
54  
55 sub room { $_[0]->{room} }
56  
57 =item B<send ([$room])>
58  
59 This method send this message. If C<$room>
60 is defined it will set the connection of this
61 message object before it is send.
62  
63 =cut
64  
65 sub send {
66 my ($self, $room) = @_;
67  
68 if ($room) {
69 $self->{room} = $room;
70 $self->{connection} = $self->{room}->{connection};
71 }
72  
73 my @add;
74 push @add, (subject => $self->{subjects})
75 if %{$self->{subjects} || {}};
76 push @add, (thread => $self->thread)
77 if $self->thread;
78 push @add, (from => $self->from)
79 if defined $self->from;
80  
81 $self->{connection}->send_message (
82 $self->to, $self->type, $self->{create_cbs},
83 body => $self->{bodies},
84 @add
85 );
86 }
87  
88 =item B<make_reply ([$msg])>
89  
90 This method returns a new instance of L<AnyEvent::XMPP::Ext::MUC::Message>.
91 The destination address, connection and type of the returned message
92 object will be set.
93  
94 If C<$msg> is defined and an instance of L<AnyEvent::XMPP::Ext::MUC::Message>
95 the destination address, connection and type of C<$msg> will be changed
96 and this method will not return a new instance of L<AnyEvent::XMPP::Ext::MUC::Message>.
97  
98 If C<$self> is a message of type 'groupchat' the C<to> attribute
99 will be set to the bare JID of the room for the reply.
100  
101 =cut
102  
103 sub make_reply {
104 my ($self, $msg) = @_;
105  
106 unless ($msg) {
107 $msg = $self->new (room => $self->room);
108 }
109  
110 $msg->{connection} = $self->{connection};
111 $msg->{room} = $self->{room};
112  
113 if ($self->type eq 'groupchat') {
114 $msg->to (bare_jid $self->from);
115  
116 } else {
117 $msg->to ($self->from);
118 }
119 $msg->type ($self->type);
120  
121 $msg
122 }
123  
124 =item B<from_nick>
125  
126 This method returns the nickname of the source
127 of this message.
128  
129 =cut
130  
131 sub from_nick {
132 my ($self) = @_;
133 res_jid ($self->from)
134 }
135  
136 =item B<is_private>
137  
138 This method returns true when the message was not directed to the
139 room, but privately to you.
140  
141 =cut
142  
143 sub is_private {
144 my ($self) = @_;
145 $self->type ne 'groupchat'
146 }
147  
148 =back
149  
150 =head1 AUTHOR
151  
152 Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
153  
154 =head1 COPYRIGHT & LICENSE
155  
156 Copyright 2007, 2008 Robin Redeker, all rights reserved.
157  
158 This program is free software; you can redistribute it and/or modify it
159 under the same terms as Perl itself.
160  
161 =cut
162  
163 1;