Telegram/Role/Source.pm

filter: Statementstmt 90.3% 47 / 52 Branchbran 41.6% 5 / 12 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 79.2% 65 / 82 CC 9 SCAR 15.0
CC
9
Cov
80%
_normalize_record_chan
8.7
normalize_record
4.0
__ANON__
2.0
CRAP 4.5
« Telegram/Keyboard.pm ↑ Summary Telegram.pm »
1 package Bot::ChatBots::Telegram::Role::Source;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 { our $VERSION = '0.014'; }
5  
6 3 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 has token => (
12 is => 'ro',
13 lazy => 1,
14 predicate => 1,
15 0 ▶ default => sub { ouch 500, 'token is not defined' }
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 3 );
17  
18 has sender => (
19 is => 'ro',
20 lazy => 1,
21 1 ▶ default => sub { # prefer has-a in this case
Subroutine __ANON__: called CC=1 SCAR=0.0
22 1 my $self = shift;
23 1 require Bot::ChatBots::Telegram::Sender;
24 1 return Bot::ChatBots::Telegram::Sender->new(token => $self->token);
25 },
26 3 );
27  
28 {
29 3 my %data_type_for = (
30 message => 'Message',
31 edited_message => 'Message',
32 channel_post => 'Message',
33 edited_channel_post => 'Message',
34 inline_query => 'InlineQuery',
35 chosen_inline_result => 'ChosenInlineResult',
36 callback_query => 'CallbackQuery',
37 shipping_query => 'ShippingQuery',
38 pre_checkout_query => 'PreCheckoutQuery',
39 );
40  
41 3 ▶ sub normalize_record {
Subroutine normalize_record: called CC=4 SCAR=13.9
Pod documented
42 3 my ($self, $record) = @_;
43  
44 3 ▶ my $update = $record->{update} or ouch 500, 'no update found!';
Branch: 1 branch
BranchTrueFalseTotal
my $update = $record->{"update"} or ouch(500, "no update found!") 2 1 3
45 2 $record->{source}{technology} = 'telegram';
46 2 ▶ $record->{source}{token} //= $record->{source}{object_token};
Condition66%2/3
$record->{"source"}{"token"} //= $record->{"source"}{"object_token"}
l!l&&r!l&&!r
101
MC/DC50%1/2
$record->{"source"}{"token"} //= $record->{"source"}{"object_token"}
$record->{"source"}{"token"} $record->{"source"}{"object_token"}
Truth table66%2/3
A //= B
A= $record->{"source"}{"token"}B= $record->{"source"}{"object_token"}
ABresult
1X1
011
000
47  
48 2 my ($type) = grep { $_ ne 'update_id' } keys %$update;
49 2 $record->{type} = $type;
50  
51 2 ▶ $record->{data_type} = $data_type_for{$type} || 'unknown';
Condition50%1/2
$data_type_for{$type} || 'unknown'
l!l
20
MC/DC0%0/1
$data_type_for{$type} || 'unknown'
$data_type_for{$type}
Truth table50%1/2
A
A= $data_type_for{$type}
Aresult
11
00
52  
53 2 my $payload = $record->{payload} = $update->{$type};
54  
55 2 $record->{sender} = $payload->{from};
56  
57 2 return $self->_normalize_record_chan($record);
58 }
59 }
60  
61 3 ▶sub _normalize_record_chan {
Subroutine _normalize_record_chan: called CC=6 SCAR=21.7
62 2 my ($self, $record) = @_;
63 2 my ($dtype, $payload) = @{$record}{qw< data_type payload >};
64 2 my $chan;
65 2 ▶ if ($dtype eq 'Message') {
Branch: 2 branches
BranchTrueFalseTotal
if ($dtype eq 'Message') { } 2 0 2
elsif ($dtype eq 'CallbackQuery') { } 0 0 0
66 2 $chan = {%{$payload->{chat}}};
67 }
68 elsif ($dtype eq 'CallbackQuery') {
69 0 ▶ if (exists $payload->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $payload->{'message'}) { } 0 0 0
70 0 $chan = {%{$payload->{message}{chat}}};
71 }
72 else { # FIXME guessing correctly here?
73 0 $chan = {id => $payload->{chat_instance}};
74 }
75 }
76 2 ▶ if ($chan) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chan) 2 0 2
77 2 ▶ $chan->{fqid} = "$chan->{type}/$chan->{id}" if exists $chan->{id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $chan->{"id"} 2 0 2
78 2 $record->{channel} = $chan;
79 }
80  
81 2 return $record;
82 }
83  
84 3 1;
« Telegram/Keyboard.pm ↑ Summary Telegram.pm »