Backbone/DispatchSugar.pm

filter: Statementstmt 86.1% 81 / 94 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 86.2% 25 / 29 Podpod 0.0% 0 / 20 totaltotal 70.0% 110 / 157 CC 5 SCAR 3.3
CC
5
Cov
82%
_respond
2.1
_run_this
2.1
__ANON__
2.1
CRAP 1.4
« Backbone/Service/Role/BareMetalChat.pm ↑ Summary Backbone/Service/Role/Chat.pm »
1 package Bot::Backbone::DispatchSugar;
2 4 $Bot::Backbone::DispatchSugar::VERSION = '0.142220';
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moose();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Bot::Backbone::Dispatcher::Predicate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Shared sugar methods for dispatch
11  
12  
13 4 Moose::Exporter->setup_import_methods(
14 with_meta => [ qw(
15 command not_command
16 to_me not_to_me
17 spoken shouted whispered
18 given_parameters
19 also
20 respond respond_by_method
21 run_this run_this_method
22 redispatch_to
23 ) ],
24 as_is => [ qw( parameter as ) ],
25 );
26  
27 sub redispatch_to($) {
28 3 ▶ my ($meta, $name) = @_;
Subroutine redispatch_to: called CC=1 SCAR=0.0
Pod undocumented
29 3 my $dispatcher = $meta->building_dispatcher;
30  
31 3 $dispatcher->add_predicate_or_return(
32 Bot::Backbone::Dispatcher::Predicate::RedispatchTo->new(
33 name => $name,
34 )
35 );
36 }
37  
38 sub also($) {
39 1 ▶ my ($meta, $predicate) = @_;
Subroutine also: called CC=1 SCAR=0.0
Pod undocumented
40 1 my $dispatcher = $meta->building_dispatcher;
41 1 $dispatcher->add_also_predicate($predicate);
42 }
43  
44 sub command($$) {
45 23 ▶ my ($meta, $match, $predicate) = @_;
Subroutine command: called CC=1 SCAR=0.0
Pod undocumented
46 23 my $dispatcher = $meta->building_dispatcher;
47  
48 23 $dispatcher->add_predicate_or_return(
49 Bot::Backbone::Dispatcher::Predicate::Command->new(
50 match => $match,
51 next_predicate => $predicate,
52 )
53 );
54 }
55  
56 sub not_command($) {
57 1 ▶ my ($meta, $predicate) = @_;
Subroutine not_command: called CC=1 SCAR=0.0
Pod undocumented
58 1 my $dispatcher = $meta->building_dispatcher;
59  
60 1 $dispatcher->add_predicate_or_return(
61 Bot::Backbone::Dispatcher::Predicate::NotCommand->new(
62 next_predicate => $predicate,
63 )
64 );
65 }
66  
67 sub to_me($) {
68 1 ▶ my ($meta, $predicate) = @_;
Subroutine to_me: called CC=1 SCAR=0.0
Pod undocumented
69 1 my $dispatcher = $meta->building_dispatcher;
70  
71 1 $dispatcher->add_predicate_or_return(
72 Bot::Backbone::Dispatcher::Predicate::ToMe->new(
73 next_predicate => $predicate,
74 )
75 );
76 }
77  
78 sub not_to_me($) {
79 1 ▶ my ($meta, $predicate) = @_;
Subroutine not_to_me: called CC=1 SCAR=0.0
Pod undocumented
80 1 my $dispatcher = $meta->building_dispatcher;
81  
82 1 $dispatcher->add_predicate_or_return(
83 Bot::Backbone::Dispatcher::Predicate::ToMe->new(
84 negate => 1,
85 next_predicate => $predicate,
86 )
87 );
88 }
89  
90 sub spoken($) {
91 1 ▶ my ($meta, $predicate) = @_;
Subroutine spoken: called CC=1 SCAR=0.0
Pod undocumented
92 1 my $dispatcher = $meta->building_dispatcher;
93  
94 1 $dispatcher->add_predicate_or_return(
95 Bot::Backbone::Dispatcher::Predicate::Volume->new(
96 volume => 'spoken',
97 next_predicate => $predicate,
98 )
99 );
100 }
101  
102 sub shouted($) {
103 1 ▶ my ($meta, $predicate) = @_;
Subroutine shouted: called CC=1 SCAR=0.0
Pod undocumented
104 1 my $dispatcher = $meta->building_dispatcher;
105  
106 1 $dispatcher->add_predicate_or_return(
107 Bot::Backbone::Dispatcher::Predicate::Volume->new(
108 volume => 'shout',
109 next_predicate => $predicate,
110 )
111 );
112 }
113  
114 sub whispered($) {
115 1 ▶ my ($meta, $predicate) = @_;
Subroutine whispered: called CC=1 SCAR=0.0
Pod undocumented
116 1 my $dispatcher = $meta->building_dispatcher;
117  
118 1 $dispatcher->add_predicate_or_return(
119 Bot::Backbone::Dispatcher::Predicate::Volume->new(
120 volume => 'whisper',
121 next_predicate => $predicate,
122 )
123 );
124 }
125  
126 4 our $WITH_ARGS;
127 sub given_parameters(&$) {
128 1 ▶ my ($meta, $arg_code, $predicate) = @_;
Subroutine given_parameters: called CC=1 SCAR=0.0
Pod undocumented
129 1 my $dispatcher = $meta->building_dispatcher;
130  
131 1 my @args;
132 {
133 1 local $WITH_ARGS = \@args;
134 1 $arg_code->();
135 }
136  
137 $dispatcher->add_predicate_or_return(
138 1 Bot::Backbone::Dispatcher::Predicate::GivenParameters->new(
139 parameters => \@args,
140 next_predicate => $predicate,
141 )
142 );
143 }
144  
145 sub parameter($@) {
146 1 ▶ my ($name, %config) = @_;
Subroutine parameter: called CC=1 SCAR=0.0
Pod undocumented
147 1 push @$WITH_ARGS, [ $name, \%config ];
148 }
149  
150 sub as(&) {
151 4 ▶ my $code = shift;
Subroutine as: called CC=1 SCAR=0.0
Pod undocumented
152 4 return $code;
153 }
154  
155 sub _respond {
156 5 ▶ my ($meta, $code, $dispatcher_type) = @_;
Subroutine _respond: called CC=2 SCAR=7.4
157 5 my $dispatcher = $meta->building_dispatcher;
158  
159 5 ▶ $dispatcher_type //= $meta;
Condition33%1/3
$dispatcher_type //= $meta
l!l&&r!l&&!r
050
MC/DC0%0/2
$dispatcher_type //= $meta
$dispatcher_type $meta
Truth table33%1/3
A //= B
A= $dispatcher_typeB= $meta
ABresult
1X1
011
000
160 5 $dispatcher->add_predicate_or_return(
161 Bot::Backbone::Dispatcher::Predicate::Respond->new(
162 dispatcher_type => $dispatcher_type,
163 the_code => $code,
164 )
165 );
166 }
167  
168 sub respond(&) {
169 1 ▶ my ($meta, $code, $dispatcher_type) = @_;
Subroutine respond: called CC=1 SCAR=0.0
Pod undocumented
170 1 _respond($meta, $code, $dispatcher_type);
171 }
172  
173 sub _run_this {
174 19 ▶ my ($meta, $code, $dispatcher_type) = @_;
Subroutine _run_this: called CC=2 SCAR=7.4
175 19 my $dispatcher = $meta->building_dispatcher;
176  
177 19 ▶ $dispatcher_type //= $meta;
Condition33%1/3
$dispatcher_type //= $meta
l!l&&r!l&&!r
0190
MC/DC0%0/2
$dispatcher_type //= $meta
$dispatcher_type $meta
Truth table33%1/3
A //= B
A= $dispatcher_typeB= $meta
ABresult
1X1
011
000
178 19 $dispatcher->add_predicate_or_return(
179 Bot::Backbone::Dispatcher::Predicate::Run->new(
180 dispatcher_type => $dispatcher_type,
181 the_code => $code,
182 )
183 );
184 }
185  
186 sub run_this(&) {
187 15 ▶ my ($meta, $code, $dispatcher_type) = @_;
Subroutine run_this: called CC=1 SCAR=0.0
Pod undocumented
188 15 _run_this($meta, $code, $dispatcher_type);
189 }
190  
191 sub _by_method {
192 8 ▶ my ($meta, $name) = @_;
Subroutine _by_method: called CC=2 SCAR=7.2
193  
194 8 ▶ Carp::croak("no such method as $name found on ", $meta->name)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $meta->find_method_by_name($name) 0 8 8
195 unless defined $meta->find_method_by_name($name);
196  
197 return sub {
198 8 ▶ my ($self, $message) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.4
199  
200 8 my $method = $self->can($name);
201 8 ▶ if (defined $method) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $method) { } 8 0 8
202 8 return $self->$method($message);
203 }
204 else {
205 0 Carp::croak("no such method as $name found on ", $self->meta->name);
206 }
207 8 };
208 }
209  
210 sub respond_by_method($) {
211 4 ▶ my ($meta, $name) = @_;
Subroutine respond_by_method: called CC=1 SCAR=0.0
Pod undocumented
212  
213 4 my $code = _by_method($meta, $name);
214 4 _respond($meta, \&$code);
215 }
216  
217 sub run_this_method($) {
218 4 ▶ my ($meta, $name) = @_;
Subroutine run_this_method: called CC=1 SCAR=0.0
Pod undocumented
219  
220 4 my $code = _by_method($meta, $name);
221 4 _run_this($meta, \&$code);
222 }
223  
224 sub respond_by_service_method($) {
225 0 ▶ my ($meta, $name) = @_;
Subroutine respond_by_service_method: not called CC=1 SCAR=6.9
Pod undocumented
226  
227 0 my $code = _by_method($meta, $name);
228 0 _respond($meta, \&$code, 'service');
229 }
230  
231 sub respond_by_bot_method($) {
232 0 ▶ my ($meta, $name) = @_;
Subroutine respond_by_bot_method: not called CC=1 SCAR=6.9
Pod undocumented
233  
234 0 my $code = _by_method($meta, $name);
235 0 _respond($meta, \&$code, 'bot');
236 }
237  
238 sub run_this_service_method($) {
239 0 ▶ my ($meta, $name) = @_;
Subroutine run_this_service_method: not called CC=1 SCAR=6.9
Pod undocumented
240  
241 0 my $code = _by_method($meta, $name);
242 0 _run_this($meta, \&$code, 'service');
243 }
244  
245 sub run_this_bot_method($) {
246 0 ▶ my ($meta, $name) = @_;
Subroutine run_this_bot_method: not called CC=1 SCAR=6.9
Pod undocumented
247  
248 0 my $code = _by_method($meta, $name);
249 0 _run_this($meta, \&$code, 'bot');
250 }
251  
252 # These are documented in Bot::Backbone and Bot::Backbone::Service
253  
254  
255  
256 4 1;
257  
258 __END__
259  
260 =pod
261  
262 =encoding UTF-8
263  
264 =head1 NAME
265  
266 Bot::Backbone::DispatchSugar - Shared sugar methods for dispatch
267  
268 =head1 VERSION
269  
270 version 0.142220
271  
272 =head1 DESCRIPTION
273  
274 Do not use this package directly.
275  
276 See L<Bot::Backbone> and L<Bot::Backbone::Service>.
277  
278 =for Pod::Coverage also
279 as
280 command
281 given_parameters
282 not_command
283 not_to_me
284 parameter
285 redispatch_to
286 respond
287 respond_by_method
288 respond_by_service_method
289 respond_by_bot_method
290 run_this
291 run_this_method
292 run_this_service_method
293 run_this_bot_method
294 shouted
295 spoken
296 to_me
297 whispered
298  
299 =head1 AUTHOR
300  
301 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
302  
303 =head1 COPYRIGHT AND LICENSE
304  
305 This software is copyright (c) 2014 by Qubling Software LLC.
306  
307 This is free software; you can redistribute it and/or modify it under
308 the same terms as the Perl 5 programming language system itself.
309  
310 =cut
« Backbone/Service/Role/BareMetalChat.pm ↑ Summary Backbone/Service/Role/Chat.pm »