Backbone/Service/GroupChat.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 43 CC 3 SCAR 14.6
CC
3
Cov
0%
initialize
6.0
receive_message
6.0
send_message
2.0
CRAP 4.3
1 package Bot::Backbone::Service::GroupChat;
2 $Bot::Backbone::Service::GroupChat::VERSION = '0.161950';
3 use v5.10;
4 use Bot::Backbone::Service;
5  
6 with qw(
7 Bot::Backbone::Service::Role::Service
8 Bot::Backbone::Service::Role::Dispatch
9 Bot::Backbone::Service::Role::Chat
10 );
11  
12 with 'Bot::Backbone::Service::Role::ChatConsumer' => {
13 -excludes => [ 'send_message' ],
14 };
15  
16 with_bot_roles qw(
17 Bot::Backbone::Bot::Role::GroupChat
18 );
19  
20 # ABSTRACT: A helper chat for performing group chats
21  
22  
23 has group => (
24 is => 'ro',
25 isa => 'Str',
26 required => 1,
27 );
28  
29  
30 has nickname => (
31 is => 'ro',
32 isa => 'Str',
33 predicate => 'has_nickname',
34 );
35  
36  
37 sub initialize {
38 my $self = shift;
39  
40 my %options = (
41 group => $self->group,
42 );
43  
44 $options{nickname} = $self->nickname if $self->has_nickname;
45  
46 $self->chat->join_group(\%options);
47 }
48  
49  
50 sub send_message {
51 my ($self, $params) = @_;
52 my $text = $params->{text};
53 $self->chat->send_message({
54 group => $self->group,
55 text => $text,
56 });
57 }
58  
59  
60 sub receive_message {
61 my ($self, $message) = @_;
62  
63 return unless $message->is_group
64 and $message->group eq $self->group;
65  
66 $self->resend_message($message);
67 $self->dispatch_message($message);
68 }
69  
70 __PACKAGE__->meta->make_immutable;
71  
72 __END__