DJabberd/BotContext.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 62 CC 6 SCAR 21.7
CC
6
Cov
0%
reply
20.0
last_text
6.0
last_html
6.0
CRAP 8.8
1 package DJabberd::BotContext;
2 use strict;
3 use fields (
4 # expire times,
5 # start time,
6 # history of chat...
7 # etc, etc
8 'vhost',
9 'method',
10 'fromjid',
11 'myjid',
12 'lasttext',
13 );
14 use warnings;
15  
16 sub new {
17 my ($class, $vhost, $method, $fromjid, $myjid) = @_;
18 my $self = fields::new($class);
19 $self->{vhost} = $vhost;
20 $self->{method} = $method;
21 $self->{fromjid} = $fromjid;
22 $self->{myjid} = $myjid;
23 return $self;
24 }
25  
26 sub add_text {
27 my ($self, $text, $html) = @_;
28 $self->{lasttext} = [$text, $html];
29 }
30  
31 sub last_text {
32 my $self = shift;
33 return $self->{lasttext} ? $self->{lasttext}[0] : undef;
34 }
35  
36 sub last_html {
37 my $self = shift;
38 return $self->{lasttext} ? $self->{lasttext}[1] : undef;
39 }
40  
41 sub reply {
42 my ($self, $text, $html) = @_;
43 return unless $text || $html;
44  
45 my $body = "";
46 if ($text) {
47 $body .= "<body>". DJabberd::Util::exml($text) . "</body>";
48 }
49 if ($html) {
50 $body .= qq{<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>$html</body></html>};
51 }
52  
53 my $reply = DJabberd::Message->new('jabber:client', 'message', {
54 '{}type' => 'chat',
55 '{}to' => $self->{fromjid}->as_string,
56 '{}from' => $self->{myjid}->as_string,
57 }, []);
58 $reply->set_raw($body);
59 $reply->deliver($self->{vhost});
60 }
61  
62 1;