Docker/EventPool.pm

filter: Statementstmt 23.2% 10 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 3 totaltotal 20.9% 13 / 62 CC 5 SCAR 16.7
CC
5
Cov
20%
create
12.0
new
6.0
__sendEvents
6.0
CRAP 5.3
« Docker/EventRegister.pm ↑ Summary Docker/ContainerException.pm »
1 package Eixo::Docker::EventPool;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub new{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
9
10 0 ▶ return bless({
Condition0%0/2
$_[1] || undef
l!l
00
MC/DC0%0/1
$_[1] || undef
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
11  
12 filter=>$_[1] || undef,
13  
14 api=>$_[2],
15  
16 frequency=>$_[3]
17  
18 }, $_[0]);
19  
20 }
21  
22 0 ▶sub create{
Subroutine create: not called CC=3 SCAR=24.8
Pod undocumented
23 0 my ($self) = @_;
24  
25 0 my ($reader, $writer);
26  
27 0 pipe($reader, $writer);
28  
29 0 $writer->autoflush(1);
30  
31 0 ▶ if(my $pid = fork){
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) { } 0 0 0
32
33 0 close($writer);
34  
35 return {
36
37 0 pid=>$pid,
38  
39 reader=>$reader
40 }
41 }
42 else{
43  
44 0 $self->{writer} = $writer;
45  
46 0 ▶ $SIG{TERM} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 exit 0;
48 0 };
49  
50 0 eval{
51 0 $self->loop;
52 };
53 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
54 0 print "CRASHED : $@\n";
55 0 exit 1;
56 }
57 }
58 }
59  
60 0 ▶sub loop{
Subroutine loop: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($self) = @_;
62  
63 0 $self->{last} = time - 10;
64  
65 0 while(1){
66  
67 0 my $events = $self->__getEvents();
68  
69 0 $self->__sendEvents($events);
70 }
71 }
72  
73 0 ▶sub __getEvents{
Subroutine __getEvents: not called CC=1 SCAR=6.9
74 0 my ($self) = @_;
75  
76 0 my $n_time = time + $self->{frequency};
77  
78 my $events = $_[0]->{api}->events->get(
79  
80 until=>$n_time,
81  
82 since=>$self->{last}
83 0 );
84  
85 0 $self->{last} = $n_time;
86  
87 0 return $events;
88  
89 }
90  
91 0 ▶sub __sendEvents{
Subroutine __sendEvents: not called CC=2 SCAR=17.9
92 0 my ($self, $events) = @_;
93  
94 0 my $w = $self->{writer};
95  
96 0 my $json = JSON->new;
97  
98 0 foreach my $e (@{$events->{Events}}){
99  
100 0 print $w $json->encode($e) . "\n";
101  
102 }
103  
104 0 $events->{Events} = [];
105 }
106  
107 12 1;
« Docker/EventRegister.pm ↑ Summary Docker/ContainerException.pm »