ChatBots/Auth.pm

filter: Statementstmt 100% 50 / 50 Branchbran 83.3% 10 / 12 Conditioncond 72.2% 13 / 18 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 86.0% 86 / 100 CC 13 SCAR 20.5
CC
13
Cov
91%
process
12.1
__ANON__
2.3
BEGIN
1.0
CRAP 7.8
« ChatBots/Role/Source.pm ↑ Summary ChatBots/Role/UserAgent.pm »
1 package Bot::ChatBots::Auth;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 { our $VERSION = '0.014'; }
5  
6 2 ▶use Log::Any qw< $log >;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 with 'Bot::ChatBots::Role::Processor';
10  
11 1 ▶has channels => (is => 'rw', default => sub { return {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 1 ▶has name => (is => 'ro', default => sub { return ref($_[0]) || $_[0] });
Subroutine __ANON__: called CC=2 SCAR=8.1
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
13 1 ▶has users => (is => 'rw', default => sub { return {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 9 ▶sub process {
Subroutine process: called CC=12 SCAR=24.9
Pod documented
16 9 my ($self, $record) = @_;
17 9 my $name = $self->name;
18  
19 9 my $users = $self->users;
20 9 ▶ if (keys %$users) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$users) 9 0 9
21 9 ▶ my $id = $record->{sender}{id} // do {
Condition66%2/3
$record->{"sender"}{"id"} // do { $Bot::ChatBots::Auth::log->info("${name}: sender id is not present"); return }
l!l&&r!l&&!r
720
MC/DC0%0/2
$record->{"sender"}{"id"} // do { $Bot::ChatBots::Auth::log->info("${name}: sender id is not present"); return }
$record->{"sender"}{"id"} do { $Bot::ChatBots::Auth::log->info("${name}: sender id is not present"); return }
Truth table33%1/3
A // B
A= $record->{"sender"}{"id"}B= do { $Bot::ChatBots::Auth::log->info("${name}: sender id is not present"); return }
ABresult
1X1
011
000
22 2 $log->info("$name: sender id is not present");
23 2 return;
24 };
25 7 ▶ if (exists $users->{blacklist}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $users->{"blacklist"}{$id}) 1 6 7
26 1 $log->info("$name: sender '$id' is blacklisted, blocking");
27 1 return;
28 }
29 6 ▶ if (scalar(keys %{$users->{whitelist}})
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$users{"whitelist"};} and not exists $users->{"whitelist"}{$id}) 1 5 6
Condition100%3/3
scalar keys %{$$users{"whitelist"};} and not exists $users->{"whitelist"}{$id}
!ll&&!rl&&r
321
MC/DC100%2/2
scalar keys %{$$users{"whitelist"};} and not exists $users->{"whitelist"}{$id}
scalar keys %{$$users{"whitelist"};} not exists $users->{"whitelist"}{$id}
Truth table100%3/3
A and not(B)
A= scalar keys %{$$users{"whitelist"};}B= not exists $users->{"whitelist"}{$id}
ABresult
0X0
100
111
30 && (!exists($users->{whitelist}{$id})))
31 {
32 1 $log->info("$name: sender '$id' not whitelisted, blocking");
33 1 return;
34 } ## end if (scalar(keys %{$users...}))
35 } ## end if (keys %$users)
36  
37 5 my $channels = $self->channels;
38 5 ▶ if (keys %$channels) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$channels) 5 0 5
39 5 ▶ my $id = $record->{channel}{fqid} // $record->{channel}{id} // do {
Condition66%4/6
($record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}) // do { $Bot::ChatBots::Auth::log->info("${name}: chat id is not present"); return }
l!l&&r!l&&!r
410
$record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}
l!l&&r!l&&!r
041
MC/DC0%0/3
($record->{"channel"}{"fqid"} // $record->{"channel"}{"id"}) // do { $Bot::ChatBots::Auth::log->info("${name}: chat id is not present"); return }
$record->{"channel"}{"fqid"} $record->{"channel"}{"id"} do { $Bot::ChatBots::Auth::log->info("${name}: chat id is not present"); return }
Truth table25%1/4
A // B // C
A= $record->{"channel"}{"fqid"}B= $record->{"channel"}{"id"}C= do { $Bot::ChatBots::Auth::log->info("${name}: chat id is not present"); return }
ABCresult
1XX1
01X1
0011
0000
40 1 $log->info("$name: chat id is not present");
41 1 return;
42 };
43 4 ▶ if (exists $channels->{blacklist}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $channels->{"blacklist"}{$id}) 1 3 4
44 1 $log->info("$name: chat '$id' is blacklisted, blocking");
45 1 return;
46 }
47 3 ▶ if (scalar(keys %{$channels->{whitelist}})
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$channels{"whitelist"};} and not exists $channels->{"whitelist"}{$id}) 1 2 3
Condition100%3/3
scalar keys %{$$channels{"whitelist"};} and not exists $channels->{"whitelist"}{$id}
!ll&&!rl&&r
111
MC/DC100%2/2
scalar keys %{$$channels{"whitelist"};} and not exists $channels->{"whitelist"}{$id}
scalar keys %{$$channels{"whitelist"};} not exists $channels->{"whitelist"}{$id}
Truth table100%3/3
A and not(B)
A= scalar keys %{$$channels{"whitelist"};}B= not exists $channels->{"whitelist"}{$id}
ABresult
0X0
100
111
48 && (!exists($channels->{whitelist}{$id})))
49 {
50 1 $log->info("$name: chat '$id' not whitelisted, blocking");
51 1 return;
52 } ## end if (scalar(keys %{$channels...}))
53 } ## end if (keys %$channels)
54  
55 2 $log->info("$name: no reason to block, allowing");
56 2 return $record;
57 } ## end sub process
58  
59 2 42;
« ChatBots/Role/Source.pm ↑ Summary ChatBots/Role/UserAgent.pm »