Docker/EventRegister.pm

filter: Statementstmt 28.0% 16 / 57 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 33.3% 5 / 15 Podpod 0.0% 0 / 4 totaltotal 21.4% 21 / 98 CC 12 SCAR 19.1
CC
12
Cov
21%
registerEvent
12.0
__getEvents
12.0
__runEvents
12.0
CRAP 6.8
« Docker/Container.pm ↑ Summary Docker/EventPool.pm »
1 package Eixo::Docker::EventRegister;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Eixo::Docker::EventPool;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Eixo::Docker::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 0 return bless({
13  
14 api=>$_[1],
15  
16 frequency=>$_[2],
17  
18 pid_pool=>undef,
19  
20 r_pool=>undef,
21  
22 s_pool=>undef,
23  
24 events=>{},
25  
26 pool=>[],
27  
28 }, $_[0]);
29 }
30  
31 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
32  
33 0 ▶ return unless($_[0]->{pid_pool});
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"pid_pool"} 0 0 0
34  
35 0 kill('TERM', $_[0]->{pid_pool});
36  
37 0 waitpid($_[0]->{pid_pool}, 0);
38 }
39  
40 #
41 # It will block forever
42 #
43 0 ▶sub condvar{
Subroutine condvar: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($self) = @_;
45  
46 0 my $s = IO::Select->new;
47  
48 0 $s->add($self->{r_pool});
49  
50 0 ▶ while($s->can_read){
Branch: 1 branch
BranchTrueFalseTotal
if ($s->can_read) 0 0 0
51 0 $self->run;
52 }
53 }
54  
55 0 ▶sub run{
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my ($self) = @_;
57  
58 0 ▶ return unless($self->{pid_pool});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pid_pool"} 0 0 0
59  
60 0 $self->__getEvents;
61  
62 0 $self->__runEvents;
63 }
64  
65 0 ▶sub registerEvent{
Subroutine registerEvent: not called CC=3 SCAR=24.8
Pod undocumented
66 0 my ($self, %args) = @_;
67  
68 0 ▶ if(!$self->{pid_pool}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"pid_pool"}) 0 0 0
69  
70 0 $self->__launchPool;
71 }
72  
73 0 my $signature = join('-', $args{id}, $args{status});
74  
75 $self->{events}->{$signature} = Eixo::Docker::Event->new(
76  
77 $args{id},
78  
79 $args{status},
80  
81 0 ▶ $args{code} || sub {}
Subroutine __ANON__: not called CC=1 SCAR=0.0
82 0 ▶ );
Condition0%0/3
$args{'code'} || sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'code'} || sub { }
$args{'code'} sub { }
Truth table0%0/3
A || B
A= $args{'code'}B= sub { }
ABresult
1X1
011
000
83 }
84  
85 0 ▶sub __getEvents{
Subroutine __getEvents: not called CC=3 SCAR=24.8
86 0 my ($self) = @_;
87  
88 0 my @lines;
89  
90 0 my $r = $self->{r_pool};
91  
92 0 ▶ while(my $l = $r->getline){
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $r->getline) 0 0 0
93 0 push @lines, $l;
94 }
95  
96 0 foreach(grep { $_ =~ /\w/ } @lines){
97 0 push @{$self->{pool}}, JSON->new->decode($_);
98 }
99 }
100  
101 0 ▶sub __runEvents{
Subroutine __runEvents: not called CC=3 SCAR=24.8
102 0 my ($self) = @_;
103  
104 0 foreach my $e (@{$self->{pool}}){
105  
106 0 ▶ if(my $event = $self->__isRegistered($e)){
Branch: 1 branch
BranchTrueFalseTotal
if (my $event = $self->__isRegistered($e)) 0 0 0
107  
108 0 $event->run($e);
109  
110 }
111 }
112  
113 0 $self->{pool} = [];
114 }
115  
116 0 ▶sub __isRegistered{
Subroutine __isRegistered: not called CC=2 SCAR=17.9
117 0 my ($self, $e) = @_;
118  
119 0 my $signature = join('-', $e->{id}, $e->{status});
120  
121 0 ▶ $self->{events}->{$signature} || undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"events"}{$signature} or undef 0 0 0
122 }
123  
124 0 ▶sub __launchPool{
Subroutine __launchPool: not called CC=2 SCAR=17.9
125 0 my ($self) = @_;
126  
127 my $pool = Eixo::Docker::EventPool->new(
128  
129 0,
130  
131 $self->{api},
132  
133 0 ▶ $self->{frequency} || 1
Condition0%0/2
$self->{'frequency'} || 1
l!l
00
MC/DC0%0/1
$self->{'frequency'} || 1
$self->{'frequency'}
Truth table0%0/2
A
A= $self->{'frequency'}
Aresult
11
00
134
135 )->create;
136  
137 0 $self->{pid_pool} = $pool->{pid};
138  
139 0 $self->{r_pool} = $pool->{reader};
140
141 0 $self->{r_pool}->blocking(0);
142  
143 #$self->{s_pool} = IO::Select->new;
144  
145 #$self->{s_pool}->add($self->{r_pool});
146 }
147  
148  
149  
150 12 1;
« Docker/Container.pm ↑ Summary Docker/EventPool.pm »