line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::ChatBots::Role::Source; |
2
|
5
|
|
|
5
|
|
39909
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
134
|
|
3
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
187
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.009'; } |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
856
|
use Ouch; |
|
5
|
|
|
|
|
3709
|
|
|
5
|
|
|
|
|
27
|
|
7
|
5
|
|
|
5
|
|
1211
|
use Log::Any qw< $log >; |
|
5
|
|
|
|
|
14715
|
|
|
5
|
|
|
|
|
40
|
|
8
|
5
|
|
|
5
|
|
5461
|
use Bot::ChatBots::Weak; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
151
|
|
9
|
5
|
|
|
5
|
|
1445
|
use Try::Tiny; |
|
5
|
|
|
|
|
3389
|
|
|
5
|
|
|
|
|
246
|
|
10
|
5
|
|
|
5
|
|
101
|
use 5.010; |
|
5
|
|
|
|
|
17
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
22
|
use Moo::Role; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
36
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires 'normalize_record'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has custom_pairs => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
default => sub { return {} }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has processor => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
builder => 'BUILD_processor', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has typename => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
lazy => 1, |
30
|
|
|
|
|
|
|
builder => 'BUILD_typename', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub BUILD_processor { |
34
|
0
|
|
|
0
|
1
|
0
|
ouch 500, 'no processor defined!'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub BUILD_typename { |
38
|
3
|
|
|
3
|
1
|
9435
|
my $self = shift; |
39
|
3
|
|
|
|
|
23
|
my @chunks = split /::/, lc ref $self; |
40
|
|
|
|
|
|
|
return ( |
41
|
3
|
50
|
33
|
|
|
38
|
((@chunks == 1) || ($chunks[-1] ne 'webhook')) |
42
|
|
|
|
|
|
|
? $chunks[-1] |
43
|
|
|
|
|
|
|
: $chunks[-2] |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} ## end sub BUILD_typename |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub pack_source { |
48
|
5
|
|
|
5
|
1
|
58
|
my $self = shift; |
49
|
5
|
100
|
66
|
|
|
34
|
my $args = (@_ && ref($_[0])) ? $_[0] : {@_}; |
50
|
|
|
|
|
|
|
|
51
|
5
|
100
|
|
|
|
44
|
my %class_custom_pairs = |
52
|
|
|
|
|
|
|
$self->can('class_custom_pairs') |
53
|
|
|
|
|
|
|
? $self->class_custom_pairs |
54
|
|
|
|
|
|
|
: (); |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
48
|
my $refs = Bot::ChatBots::Weak->new; |
57
|
5
|
|
|
|
|
18
|
$refs->set(self => $self); |
58
|
5
|
|
100
|
|
|
11
|
while (my ($k, $v) = each %{$args->{refs} // {}}) { |
|
17
|
|
|
|
|
64
|
|
59
|
12
|
|
|
|
|
25
|
$refs->set($k, $v); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $source = { |
63
|
|
|
|
|
|
|
class => ref($self), |
64
|
|
|
|
|
|
|
refs => $refs, |
65
|
|
|
|
|
|
|
type => $self->typename, |
66
|
|
|
|
|
|
|
%class_custom_pairs, |
67
|
5
|
|
|
|
|
48
|
%{$self->custom_pairs}, |
68
|
5
|
|
50
|
|
|
114
|
%{$args->{source_pairs} // {}}, |
|
5
|
|
|
|
|
33
|
|
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
|
|
|
19
|
return $source; |
72
|
|
|
|
|
|
|
} ## end sub pack_source |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub process { |
75
|
5
|
|
|
5
|
1
|
41
|
my $self = shift; |
76
|
5
|
|
|
|
|
111
|
return $self->processor->(@_); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub process_updates { |
80
|
4
|
|
|
4
|
1
|
65
|
my $self = shift; |
81
|
4
|
50
|
33
|
|
|
36
|
my $args = (@_ && ref($_[0])) ? $_[0] : {@_}; |
82
|
|
|
|
|
|
|
|
83
|
4
|
|
50
|
|
|
16
|
my $updates = $args->{updates} // []; |
84
|
4
|
50
|
|
|
|
15
|
ouch 500, 'updates is not an array reference' |
85
|
|
|
|
|
|
|
unless ref($updates) eq 'ARRAY'; |
86
|
4
|
50
|
|
|
|
16
|
my $n_updates = @$updates or return; |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
15
|
my $source = $self->pack_source($args); |
89
|
|
|
|
|
|
|
|
90
|
4
|
|
|
|
|
8
|
my @retval; |
91
|
4
|
|
|
|
|
14
|
for my $i (0 .. ($n_updates - 1)) { |
92
|
4
|
|
|
|
|
8
|
my %call; |
93
|
4
|
50
|
|
|
|
11
|
push @retval, \%call if defined wantarray; # no void context |
94
|
|
|
|
|
|
|
try { |
95
|
4
|
|
|
4
|
|
273
|
$call{update} = $updates->[$i]; |
96
|
|
|
|
|
|
|
$call{record} = $self->normalize_record( |
97
|
|
|
|
|
|
|
{ |
98
|
|
|
|
|
|
|
batch => { |
99
|
|
|
|
|
|
|
count => ($i + 1), |
100
|
|
|
|
|
|
|
total => $n_updates, |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
source => $source, |
103
|
|
|
|
|
|
|
update => $call{update}, |
104
|
4
|
|
50
|
|
|
17
|
%{$args->{record_pairs} // {}}, |
|
4
|
|
|
|
|
35
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
); |
107
|
4
|
|
|
|
|
23
|
$call{outcome} = $self->process($call{record}); |
108
|
|
|
|
|
|
|
} ## end try |
109
|
|
|
|
|
|
|
catch { |
110
|
0
|
|
|
0
|
|
0
|
$log->error(bleep $_); |
111
|
0
|
0
|
|
|
|
0
|
die $_ if $self->should_rethrow($args); |
112
|
4
|
|
|
|
|
41
|
}; |
113
|
|
|
|
|
|
|
} ## end for my $i (0 .. ($n_updates...)) |
114
|
|
|
|
|
|
|
|
115
|
4
|
50
|
|
|
|
141
|
$self->review_outcomes(@retval) if $self->can('review_outcomes'); |
116
|
|
|
|
|
|
|
|
117
|
4
|
50
|
|
|
|
18
|
return unless defined wantarray; # void is void! |
118
|
4
|
50
|
|
|
|
20
|
return @retval if wantarray; |
119
|
0
|
|
|
|
|
|
return \@retval; |
120
|
|
|
|
|
|
|
} ## end sub process_updates |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub should_rethrow { |
123
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
124
|
0
|
0
|
0
|
|
|
|
my $args = (@_ && ref($_[0])) ? $_[0] : {@_}; |
125
|
|
|
|
|
|
|
return |
126
|
|
|
|
|
|
|
exists($args->{rethrow}) ? $args->{rethrow} |
127
|
0
|
0
|
|
|
|
|
: $self->can('rethrow') ? $self->rethrow |
|
|
0
|
|
|
|
|
|
128
|
|
|
|
|
|
|
: 0; |
129
|
|
|
|
|
|
|
} ## end sub should_rethrow |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |