Backbone/Service/Role/Chat.pm

filter: Statementstmt 94.4% 17 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 96.1% 25 / 26 CC 2 SCAR 2.8
CC
2
Cov
94%
resend_message
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Backbone/DispatchSugar.pm ↑ Summary Backbone/Dispatcher/PredicateIterator.pm »
1 package Bot::Backbone::Service::Role::Chat;
2 4 $Bot::Backbone::Service::Role::Chat::VERSION = '0.142220';
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 with 'Bot::Backbone::Service::Role::SendPolicy';
7  
8 4 ▶use Bot::Backbone::SendPolicy::Aggregate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Chat services must implement this role
11  
12  
13 has chat_consumers => (
14 is => 'ro',
15 isa => 'ArrayRef', # 'ArrayRef[DOES Bot::Backbone::Service::Role::ChatConsumer]',
16 required => 1,
17 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 4 traits => [ 'Array' ],
19 handles => {
20 register_chat_consumer => 'push',
21 list_chat_consumers => 'elements',
22 },
23 );
24  
25  
26 sub send_reply {
27 3 ▶ my ($self, $message, $options) = @_;
Subroutine send_reply: called CC=1 SCAR=0.0
Pod documented
28  
29 3 $self->send_message({
30 group => $message->group,
31 to => $message->from->username,
32 %$options,
33 });
34 }
35  
36  
37 sub resend_message {
38 21 ▶ my ($self, $message) = @_;
Subroutine resend_message: called CC=2 SCAR=7.6
Pod documented
39  
40 21 for my $consumer ($self->list_chat_consumers) {
41 0 $consumer->receive_message($message);
42 }
43 }
44  
45 4 1;
46  
47 __END__
48  
49 =pod
50  
51 =encoding UTF-8
52  
53 =head1 NAME
54  
55 Bot::Backbone::Service::Role::Chat - Chat services must implement this role
56  
57 =head1 VERSION
58  
59 version 0.142220
60  
61 =head1 DESCRIPTION
62  
63 A chat service is one that sends and receives messages to other entities.
64  
65 See L<Bot::Backbone::Service::ConsoleChat> and
66 L<Bot::Backbone::Service::JabberChat>.
67  
68 =head1 ATTRIBUTES
69  
70 =head2 chat_consumers
71  
72 This is a list of L<Bot::Backbone::Service::Role::ChatConsumer>s that have registered to
73 receive messages from this chat service. A chat consumer is registered using the
74 C<register_chat_cnosumer> method. A C<list_chat_consumers> method is provided to
75 list the registered consumers.
76  
77 =head1 REQUIRED METHODS
78  
79 =head2 send_message
80  
81 # Send a direct message
82 $chat->send_message({
83 to => $to_username,
84 text => 'blah blah blah',
85 });
86  
87 # Send a group message
88 $chat->send_message({
89 group => $to_group,
90 text => 'blah blah blah',
91 });
92  
93 Sends a message to a group or individual using this chat service. This is used
94 when the message is not being made as a direct reply to a message received from
95 the chat service.
96  
97 If both C<group> and C<to> are passed, the preference should be to send to the C<group>.
98  
99 This role also provides a wrapper around your chat's implementation of
100 C<send_message>, which will apply the current service's send policy to the
101 message. The most restrictive send policy encountered at any point will win.
102  
103 A send policy may be explicitly provided by setting the C<send_policy> setting
104 in the parameters to a L<Bot::Backbone::SendPolicy> object. Missing this
105 parameter will result in an error. The C<send_policy_result> may also be set to
106 reflect the most restrictive send policy result encountered so far.
107  
108 =head1 METHODS
109  
110 =head2 send_reply
111  
112 $chat->send_reply($message, \%options);
113  
114 Given a message generated by this chat service, this should send a reply to the
115 origin of the message, whether that be a group or individual or other entity.
116  
117 The second argument is a hash reference of options, which is used to modify the
118 reply further. See L</send_message> for additional options and be aware that
119 individual chat implementations may provide more options in addition to those
120 shown here.
121  
122 =head2 resend_message
123  
124 $chat->resend_message($message);
125  
126 This should be called whenever a message is received from the chat service. This
127 message willb e forwarded to all of the registered L</chat_consumers>.
128  
129 =head1 AUTHOR
130  
131 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
132  
133 =head1 COPYRIGHT AND LICENSE
134  
135 This software is copyright (c) 2014 by Qubling Software LLC.
136  
137 This is free software; you can redistribute it and/or modify it under
138 the same terms as the Perl 5 programming language system itself.
139  
140 =cut
« Backbone/DispatchSugar.pm ↑ Summary Backbone/Dispatcher/PredicateIterator.pm »