blib/lib/Langertha/Raider/Hall/Protocol.pm

filter: Statementstmt 66.6% 40 / 60 Branchbran 50.0% 3 / 6 Conditioncond 30.4% 7 / 23 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 1 totaltotal 50.0% 57 / 114 CC 14 SCAR 20.5
CC
14
Cov
56%
__ANON__
15.6
__ANON__
6.0
__ANON__
6.0
CRAP 7.8
« blib/lib/Langertha/Raider/Config/Migrate.pm ↑ Summary blib/lib/Langertha/Raider/Config.pm »
1 package Langertha::Raider::Hall::Protocol;
2 73 our $VERSION = '0.503';
3 # ABSTRACT: Internal control-socket command handlers for the raider hall
4  
5  
6 73 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 73 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 73 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 73 has hall => (
11 is => 'ro',
12 isa => 'Langertha::Raider::Hall',
13 required => 1,
14 weak_ref => 1,
15 );
16  
17 6 ▶sub setup_handlers {
Subroutine setup_handlers: called CC=1 SCAR=1.3
Pod undocumented
18 6 my ($self) = @_;
19 6 my $hall = $self->hall;
20  
21 1 ▶ $hall->_register_cmd(spawn => sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
22 1 my ($hall, $stream, $payload) = @_;
23 1 ▶ my $name = $payload->{name} // '';
Condition50%1/2
$payload->{"name"} // ""
l!l
10
MC/DC0%0/1
$payload->{"name"} // ""
$payload->{"name"}
Truth table50%1/2
A
A= $payload->{"name"}
Aresult
11
00
24 1 ▶ my $mission = $payload->{mission} // '';
Condition50%1/2
$payload->{"mission"} // ""
l!l
10
MC/DC0%0/1
$payload->{"mission"} // ""
$payload->{"mission"}
Truth table50%1/2
A
A= $payload->{"mission"}
Aresult
11
00
25 1 my $result = $hall->spawn(name => $name, mission => $mission);
26 1 $stream->write(JSON::MaybeXS->new->encode($result) . "\n");
27 6 });
28  
29 0 ▶ $hall->_register_cmd(ps => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 my ($hall, $stream, $payload) = @_;
31 0 my @list = $hall->ps;
32 0 $stream->write(JSON::MaybeXS->new->encode({raiders => \@list}) . "\n");
33 6 });
34  
35 0 ▶ $hall->_register_cmd(attach => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
36 0 my ($hall, $stream, $payload) = @_;
37 0 ▶ my $id = $payload->{id} // '';
Condition0%0/2
$payload->{"id"} // ""
l!l
00
MC/DC0%0/1
$payload->{"id"} // ""
$payload->{"id"}
Truth table0%0/2
A
A= $payload->{"id"}
Aresult
11
00
38 0 my $info = $hall->attach($id);
39 0 $stream->write(JSON::MaybeXS->new->encode($info) . "\n");
40 6 });
41  
42 0 ▶ $hall->_register_cmd(kill => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
43 0 my ($hall, $stream, $payload) = @_;
44 0 ▶ my $id = $payload->{id} // '';
Condition0%0/2
$payload->{"id"} // ""
l!l
00
MC/DC0%0/1
$payload->{"id"} // ""
$payload->{"id"}
Truth table0%0/2
A
A= $payload->{"id"}
Aresult
11
00
45 0 my $result = $hall->kill_raider($id);
46 0 $stream->write(JSON::MaybeXS->new->encode($result) . "\n");
47 6 });
48  
49 0 ▶ $hall->_register_cmd(logs => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 my ($hall, $stream, $payload) = @_;
51 0 ▶ my $id = $payload->{id} // '';
Condition0%0/2
$payload->{"id"} // ""
l!l
00
MC/DC0%0/1
$payload->{"id"} // ""
$payload->{"id"}
Truth table0%0/2
A
A= $payload->{"id"}
Aresult
11
00
52 0 my $result = $hall->logs(id => $id);
53 0 $stream->write(JSON::MaybeXS->new->encode($result) . "\n");
54 6 });
55  
56 0 ▶ $hall->_register_cmd(status => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 my ($hall, $stream, $payload) = @_;
58 $stream->write(JSON::MaybeXS->new->encode({
59 0 running => scalar(keys %{$hall->raiders}),
60 root => $hall->root->stringify,
61 slots => $hall->_running_slots,
62 }) . "\n");
63 6 });
64  
65 3 ▶ $hall->_register_cmd(session_reset => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
66 3 my ($hall, $stream, $payload) = @_;
67 3 my $result = $hall->reset_session($payload->{binding});
68 3 $stream->write(JSON::MaybeXS->new->encode($result) . "\n");
69 6 });
70  
71 1 ▶ $hall->_register_cmd(telegram_reply => sub {
Subroutine __ANON__: called CC=9 SCAR=27.5
72 1 my ($hall, $stream, $payload) = @_;
73 1 ▶ my $bot = $payload->{bot} // '';
Condition50%1/2
$payload->{"bot"} // ""
l!l
10
MC/DC0%0/1
$payload->{"bot"} // ""
$payload->{"bot"}
Truth table50%1/2
A
A= $payload->{"bot"}
Aresult
11
00
74 1 my $chat_id = $payload->{chat_id};
75 1 ▶ my $text = $payload->{text} // '';
Condition50%1/2
$payload->{"text"} // ""
l!l
10
MC/DC0%0/1
$payload->{"text"} // ""
$payload->{"text"}
Truth table50%1/2
A
A= $payload->{"text"}
Aresult
11
00
76 1 my $result;
77 1 ▶ if (!$bot || !defined $chat_id || !length $text) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $bot && defined $chat_id && length $text) { } 0 1 1
elsif (not $hall->config->{'telegram'} && $hall->config->{'telegram'}{'bots'}) { } 0 1 1
Condition33%2/6
$bot && defined $chat_id && length $text
!ll&&!rl&&r
001
$bot and defined $chat_id
!ll&&!rl&&r
001
MC/DC0%0/3
$bot && defined $chat_id && length $text
$bot defined $chat_id length $text
Truth table25%1/4
A and B && C
A= $botB= defined $chat_idC= length $text
ABCresult
0XX0
10X0
1100
1111
78 0 $result = { error => 'telegram_reply requires bot, chat_id, text' };
79 }
80 ▶ elsif (!$hall->config->{telegram} || !$hall->config->{telegram}{bots}) {
Condition33%1/3
$hall->config->{'telegram'} && $hall->config->{'telegram'}{'bots'}
!ll&&!rl&&r
001
MC/DC0%0/2
$hall->config->{'telegram'} && $hall->config->{'telegram'}{'bots'}
$hall->config->{'telegram'} $hall->config->{'telegram'}{'bots'}
Truth table33%1/3
A && B
A= $hall->config->{'telegram'}B= $hall->config->{'telegram'}{'bots'}
ABresult
0X0
100
111
81 0 $result = { error => 'telegram not configured in .raider-hall.yml' };
82 }
83 else {
84 $result = $hall->telegram->send_message(
85 bot => $bot, chat_id => $chat_id, text => $text,
86 defined $payload->{message_thread_id}
87 1 ▶ ? ( message_thread_id => $payload->{message_thread_id} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $payload->{'message_thread_id'} ? : 1 0 1
88 );
89 # Strip the Future before serialising.
90 1 delete $result->{future};
91 }
92 1 $stream->write(JSON::MaybeXS->new->encode($result) . "\n");
93 6 });
94 }
95  
96 73 __PACKAGE__->meta->make_immutable;
97  
98 73 1;
99  
100 __END__
101  
102 =pod
103  
104 =encoding UTF-8
105  
106 =head1 NAME
107  
108 Langertha::Raider::Hall::Protocol - Internal control-socket command handlers for the raider hall
109  
110 =head1 VERSION
111  
112 version 0.503
113  
114 =head1 DESCRIPTION
115  
116 B<Internal module.> Its interface may change without notice.
117  
118 Registers the JSON line commands (spawn, ps, attach, kill, logs, status,
119 session_reset, telegram_reply) on a L<Langertha::Raider::Hall> control
120 socket. C<telegram_reply> takes an optional C<message_thread_id> to answer
121 in a forum topic.
122  
123 =head1 SUPPORT
124  
125 =head2 Issues
126  
127 Please report bugs and feature requests on GitHub at
128 L<https://github.com/Getty/langertha-raider/issues>.
129  
130 =head2 IRC
131  
132 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
133  
134 =head1 CONTRIBUTING
135  
136 Contributions are welcome! Please fork the repository and submit a pull request.
137  
138 =head1 AUTHOR
139  
140 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This software is copyright (c) 2026 by Torsten Raudssus.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =cut
« blib/lib/Langertha/Raider/Config/Migrate.pm ↑ Summary blib/lib/Langertha/Raider/Config.pm »