line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::ChatBots::Role::UserAgent; |
2
|
2
|
|
|
2
|
|
113799
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
52
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.009'; } |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use Moo::Role; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has callback => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
lazy => 1, |
11
|
|
|
|
|
|
|
predicate => 1, |
12
|
|
|
|
|
|
|
clearer => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has start_loop => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
default => sub { return 0 }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has ua => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
lazy => 1, |
23
|
|
|
|
|
|
|
builder => 'BUILD_ua', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub BUILD_ua { |
27
|
1
|
|
|
1
|
1
|
11
|
my $self = shift; |
28
|
1
|
|
|
|
|
4
|
require Mojo::UserAgent; |
29
|
1
|
|
|
|
|
5
|
return Mojo::UserAgent->new; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub may_start_loop { |
33
|
7
|
|
|
7
|
1
|
2659
|
my $self = shift; |
34
|
7
|
50
|
66
|
|
|
35
|
my %args = (@_ && ref($_[0])) ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
my $start_loop = |
36
|
|
|
|
|
|
|
exists($args{start_loop}) |
37
|
|
|
|
|
|
|
? $args{start_loop} |
38
|
7
|
100
|
|
|
|
20
|
: $self->start_loop; |
39
|
7
|
100
|
66
|
|
|
24
|
Mojo::IOLoop->start if $start_loop && (!Mojo::IOLoop->is_running); |
40
|
7
|
|
|
|
|
69
|
return $self; |
41
|
|
|
|
|
|
|
} ## end sub may_start_loop |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub ua_request { |
44
|
4
|
|
|
4
|
1
|
5541
|
my ($self, $method) = splice @_, 0, 2; |
45
|
4
|
50
|
33
|
|
|
32
|
my %args = (@_ && ref($_[0])) ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
46
|
4
|
|
|
|
|
11
|
$method = lc $method; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
7
|
my @ua_args = @{$args{ua_args}}; |
|
4
|
|
|
|
|
9
|
|
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
100
|
|
|
22
|
my @callback = |
|
|
100
|
|
|
|
|
|
51
|
|
|
|
|
|
|
(scalar(@ua_args) && (ref($ua_args[-1]) eq 'CODE')) ? (pop @ua_args) |
52
|
|
|
|
|
|
|
: $self->has_callback ? ($self->callback) |
53
|
|
|
|
|
|
|
: (); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
84
|
my $res = $self->ua->$method(@ua_args, @callback); |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
71
|
$self->may_start_loop(%args) if @callback; |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
15
|
return $res; |
60
|
|
|
|
|
|
|
} ## end sub ua_request |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |