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.161950';
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 3 ▶sub redispatch_to($) {
Subroutine redispatch_to: called CC=1 SCAR=0.0
Pod undocumented
28 3 my ($meta, $name) = @_;
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 1 ▶sub also($) {
Subroutine also: called CC=1 SCAR=0.0
Pod undocumented
39 1 my ($meta, $predicate) = @_;
40 1 my $dispatcher = $meta->building_dispatcher;
41 1 $dispatcher->add_also_predicate($predicate);
42 }
43  
44 23 ▶sub command($$) {
Subroutine command: called CC=1 SCAR=0.0
Pod undocumented
45 23 my ($meta, $match, $predicate) = @_;
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 1 ▶sub not_command($) {
Subroutine not_command: called CC=1 SCAR=0.0
Pod undocumented
57 1 my ($meta, $predicate) = @_;
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 1 ▶sub to_me($) {
Subroutine to_me: called CC=1 SCAR=0.0
Pod undocumented
68 1 my ($meta, $predicate) = @_;
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 1 ▶sub not_to_me($) {
Subroutine not_to_me: called CC=1 SCAR=0.0
Pod undocumented
79 1 my ($meta, $predicate) = @_;
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 1 ▶sub spoken($) {
Subroutine spoken: called CC=1 SCAR=0.0
Pod undocumented
91 1 my ($meta, $predicate) = @_;
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 1 ▶sub shouted($) {
Subroutine shouted: called CC=1 SCAR=0.0
Pod undocumented
103 1 my ($meta, $predicate) = @_;
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 1 ▶sub whispered($) {
Subroutine whispered: called CC=1 SCAR=0.0
Pod undocumented
115 1 my ($meta, $predicate) = @_;
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 1 ▶sub given_parameters(&$) {
Subroutine given_parameters: called CC=1 SCAR=0.0
Pod undocumented
128 1 my ($meta, $arg_code, $predicate) = @_;
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 1 ▶sub parameter($@) {
Subroutine parameter: called CC=1 SCAR=0.0
Pod undocumented
146 1 my ($name, %config) = @_;
147 1 push @$WITH_ARGS, [ $name, \%config ];
148 }
149  
150 4 ▶sub as(&) {
Subroutine as: called CC=1 SCAR=0.0
Pod undocumented
151 4 my $code = shift;
152 4 return $code;
153 }
154  
155 5 ▶sub _respond {
Subroutine _respond: called CC=2 SCAR=7.4
156 5 my ($meta, $code, $dispatcher_type) = @_;
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 1 ▶sub respond(&) {
Subroutine respond: called CC=1 SCAR=0.0
Pod undocumented
169 1 my ($meta, $code, $dispatcher_type) = @_;
170 1 _respond($meta, $code, $dispatcher_type);
171 }
172  
173 19 ▶sub _run_this {
Subroutine _run_this: called CC=2 SCAR=7.4
174 19 my ($meta, $code, $dispatcher_type) = @_;
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 15 ▶sub run_this(&) {
Subroutine run_this: called CC=1 SCAR=0.0
Pod undocumented
187 15 my ($meta, $code, $dispatcher_type) = @_;
188 15 _run_this($meta, $code, $dispatcher_type);
189 }
190  
191 8 ▶sub _by_method {
Subroutine _by_method: called CC=2 SCAR=7.2
192 8 my ($meta, $name) = @_;
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 8 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
198 8 my ($self, $message) = @_;
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 4 ▶sub respond_by_method($) {
Subroutine respond_by_method: called CC=1 SCAR=0.0
Pod undocumented
211 4 my ($meta, $name) = @_;
212  
213 4 my $code = _by_method($meta, $name);
214 4 _respond($meta, \&$code);
215 }
216  
217 4 ▶sub run_this_method($) {
Subroutine run_this_method: called CC=1 SCAR=0.0
Pod undocumented
218 4 my ($meta, $name) = @_;
219  
220 4 my $code = _by_method($meta, $name);
221 4 _run_this($meta, \&$code);
222 }
223  
224 0 ▶sub respond_by_service_method($) {
Subroutine respond_by_service_method: not called CC=1 SCAR=6.9
Pod undocumented
225 0 my ($meta, $name) = @_;
226  
227 0 my $code = _by_method($meta, $name);
228 0 _respond($meta, \&$code, 'service');
229 }
230  
231 0 ▶sub respond_by_bot_method($) {
Subroutine respond_by_bot_method: not called CC=1 SCAR=6.9
Pod undocumented
232 0 my ($meta, $name) = @_;
233  
234 0 my $code = _by_method($meta, $name);
235 0 _respond($meta, \&$code, 'bot');
236 }
237  
238 0 ▶sub run_this_service_method($) {
Subroutine run_this_service_method: not called CC=1 SCAR=6.9
Pod undocumented
239 0 my ($meta, $name) = @_;
240  
241 0 my $code = _by_method($meta, $name);
242 0 _run_this($meta, \&$code, 'service');
243 }
244  
245 0 ▶sub run_this_bot_method($) {
Subroutine run_this_bot_method: not called CC=1 SCAR=6.9
Pod undocumented
246 0 my ($meta, $name) = @_;
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__
« Backbone/Service/Role/BareMetalChat.pm ↑ Summary Backbone/Service/Role/Chat.pm »