Queued/Queue.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 95.0% 58 / 61 CC 5 SCAR 9.8
CC
5
Cov
100%
process
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
↑ Summary Queued.pm »
1 package Mojo::UserAgent::Role::Queued::Queue;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Mojo::Base 'Mojo::EventEmitter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶has jobs => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
9 4 has active => 0;
10 4 has max_active => 4;
11 4 has callback => undef;
12  
13  
14 30 ▶sub process {
Subroutine process: called CC=5 SCAR=16.1
Pod undocumented
15 30 my ($self) = @_;
16 # we have jobs and can run them:
17 30 ▶ while ($self->active < $self->max_active
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active < $self->max_active and my $job = shift @{$self->jobs;}) 15 30 45
Condition100%3/3
$self->active < $self->max_active and my $job = shift @{$self->jobs;}
!ll&&!rl&&r
92115
MC/DC100%2/2
$self->active < $self->max_active and my $job = shift @{$self->jobs;}
$self->active < $self->max_active my $job = shift @{$self->jobs;}
Truth table100%3/3
A and B
A= $self->active < $self->max_activeB= my $job = shift @{$self->jobs;}
ABresult
0X0
100
111
18 36 and my $job = shift @{$self->jobs})
19 {
20 15 $self->active($self->active + 1);
21 15 my $tx = shift @$job;
22 15 my $cb = shift @$job;
23 15 weaken $self;
24 15 ▶ $tx->on(finish => sub { $self->tx_finish(); });
Subroutine __ANON__: called CC=1 SCAR=0.0
25 15 $self->callback->( $tx, $cb );
26 }
27 30 ▶ if (scalar @{$self->jobs} == 0 && $self->active == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->jobs;} == 0 and $self->active == 0) 6 24 30
Condition100%3/3
scalar @{$self->jobs;} == 0 and $self->active == 0
!ll&&!rl&&r
7176
MC/DC100%2/2
scalar @{$self->jobs;} == 0 and $self->active == 0
scalar @{$self->jobs;} == 0 $self->active == 0
Truth table100%3/3
A and B
A= scalar @{$self->jobs;} == 0B= $self->active == 0
ABresult
0X0
100
111
28 6 $self->emit('queue_empty');
29 }
30 }
31  
32 15 ▶sub tx_finish {
Subroutine tx_finish: called CC=1 SCAR=0.0
Pod undocumented
33 15 my ($self) = @_;
34 15 $self->active($self->active - 1);
35 15 $self->process();
36 }
37  
38 15 ▶sub enqueue {
Subroutine enqueue: called CC=1 SCAR=0.0
Pod undocumented
39 15 my ($self, $tx, $cb) = @_;
40 15 my $job = [$tx, $cb];
41 15 push @{$self->jobs}, $job;
42 15 $self->process();
43 }
44  
45 4 1;
↑ Summary Queued.pm »