ChatBots/Role/UserAgent.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 85.7% 12 / 14 Conditioncond 66.6% 8 / 12 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 83.5% 66 / 79 CC 12 SCAR 16.5
CC
12
Cov
87%
ua_request
7.2
may_start_loop
6.4
BEGIN
1.0
CRAP 5.2
« ChatBots/Auth.pm ↑ Summary ChatBots/Role/WebHook.pm »
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
BranchTrueFalseTotal
@_ && ref $_[0] ? : 0 7 7
Condition66%2/3
@_ and ref $_[0]
!ll&&!rl&&r
250
MC/DC0%0/2
@_ and ref $_[0]
@_ ref $_[0]
Truth table66%2/3
A and B
A= @_B= ref $_[0]
ABresult
0X0
100
111
35 my $start_loop =
36 exists($args{start_loop})
37 ? $args{start_loop}
38 7 ▶ : $self->start_loop;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'start_loop'} ? : 2 5 7
39 7 ▶ Mojo::IOLoop->start if $start_loop && (!Mojo::IOLoop->is_running);
Branch: 1 branch
BranchTrueFalseTotal
if $start_loop and not "Mojo::IOLoop"->is_running 5 2 7
Condition66%2/3
$start_loop and not "Mojo::IOLoop"->is_running
!ll&&!rl&&r
205
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
@_ && ref $_[0] ? : 0 4 4
Condition33%1/3
@_ and ref $_[0]
!ll&&!rl&&r
040
MC/DC0%0/2
@_ and ref $_[0]
@_ ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
ABresult
0X0
100
111
46 4 $method = lc $method;
47  
48 4 my @ua_args = @{$args{ua_args}};
49  
50 4 ▶ my @callback =
Branch: 2 branches
BranchTrueFalseTotal
scalar @ua_args && ref $ua_args[-1] eq 'CODE' ? : 2 2 4
$self->has_callback ? : 1 1 2
Condition100%3/3
scalar @ua_args and ref $ua_args[-1] eq "CODE"
!ll&&!rl&&r
112
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if @callback 3 1 4
58  
59 4 return $res;
60 } ## end sub ua_request
61  
62 2 1;
« ChatBots/Auth.pm ↑ Summary ChatBots/Role/WebHook.pm »