| 1 | package Bot::ChatBots::Role::UserAgent; | ||||||||||||||||||||||||||||||||
| 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 Moo::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 2 | has callback => ( | |||||||||||||||||||||||||||||||
| 9 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 10 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 11 | predicate => 1, | ||||||||||||||||||||||||||||||||
| 12 | clearer => 1, | ||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | has start_loop => ( | ||||||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | default => sub { return 0 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | has ua => ( | |||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 22 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 23 | builder => 'BUILD_ua', | ||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub BUILD_ua { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD_ua: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 27 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 28 | 1 | require Mojo::UserAgent; | |||||||||||||||||||||||||||||||
| 29 | 1 | return Mojo::UserAgent->new; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | sub may_start_loop { | ||||||||||||||||||||||||||||||
|
Subroutine
may_start_loop: called CC=6 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 33 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my %args = (@_ && ref($_[0])) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table66%2/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||||||
| 35 | my $start_loop = | ||||||||||||||||||||||||||||||||
| 36 | exists($args{start_loop}) | ||||||||||||||||||||||||||||||||
| 37 | ? $args{start_loop} | ||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | : $self->start_loop; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 7 | ▶ | Mojo::IOLoop->start if $start_loop && (!Mojo::IOLoop->is_running); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$start_loop and not "Mojo::IOLoop"->is_running
MC/DC50%1/2
$start_loop and not "Mojo::IOLoop"->is_running
$start_loop
not "Mojo::IOLoop"->is_running
Truth table66%2/3
A and not(B)
A= $start_loopB= not "Mojo::IOLoop"->is_running
| |||||||||||||||||||||||||||||||||
| 40 | 7 | return $self; | |||||||||||||||||||||||||||||||
| 41 | } ## end sub may_start_loop | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | sub ua_request { | ||||||||||||||||||||||||||||||
|
Subroutine
ua_request: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 44 | 4 | my ($self, $method) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my %args = (@_ && ref($_[0])) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||||||
| 46 | 4 | $method = lc $method; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 4 | my @ua_args = @{$args{ua_args}}; | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | my @callback = | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
scalar @ua_args and ref $ua_args[-1] eq "CODE"
MC/DC100%2/2
scalar @ua_args and ref $ua_args[-1] eq "CODE"
scalar @ua_args
ref $ua_args[-1] eq "CODE"
Truth table100%3/3
A and B
A= scalar @ua_argsB= ref $ua_args[-1] eq "CODE"
| |||||||||||||||||||||||||||||||||
| 51 | (scalar(@ua_args) && (ref($ua_args[-1]) eq 'CODE')) ? (pop @ua_args) | ||||||||||||||||||||||||||||||||
| 52 | : $self->has_callback ? ($self->callback) | ||||||||||||||||||||||||||||||||
| 53 | : (); | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 4 | my $res = $self->ua->$method(@ua_args, @callback); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | $self->may_start_loop(%args) if @callback; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 4 | return $res; | |||||||||||||||||||||||||||||||
| 60 | } ## end sub ua_request | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 2 | 1; | |||||||||||||||||||||||||||||||