Cinnamon/HandleManager.pm

filter: Statementstmt 37.2% 19 / 51 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 4 totaltotal 32.0% 25 / 78 CC 7 SCAR 18.7
CC
7
Cov
32%
start_async_read
20.0
register_fh
6.0
__ANON__
6.0
CRAP 6.5
« Cinnamon/Local.pm ↑ Summary Cinnamon/Context.pm »
1 package Cinnamon::HandleManager;
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  
5 2 ▶use Cinnamon::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my ($class, %args) = @_;
14 0 bless \%args, $class;
15 }
16  
17 0 ▶sub register_fh {
Subroutine register_fh: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ($self, $name, $fh) = @_;
19 0 ▶ my $handle_container = $self->{handle_container} ||= {};
Condition0%0/2
$self->{"handle_container"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"handle_container"} ||= {}
$self->{"handle_container"}
Truth table0%0/2
A
A= $self->{"handle_container"}
Aresult
11
00
20 0 $handle_container->{$name} = {
21 fh => $fh,
22 output_lines => [],
23 };
24 }
25  
26 0 ▶sub start_async_read {
Subroutine start_async_read: not called CC=4 SCAR=30.0
Pod undocumented
27 0 my ($self) = @_;
28 0 ▶ my $handle_container = $self->{handle_container} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $handle_container = $self->{"handle_container"} or return 0 0 0
29  
30 0 my $cv = AnyEvent->condvar;
31 0 my $handles = [];
32 0 for my $name (keys %$handle_container) {
33 0 my $info = $handle_container->{$name};
34  
35 0 $cv->begin;
36 0 my $handle; $handle = AnyEvent::Handle->new(
37 fh => $info->{fh},
38 0 ▶ on_read => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 ▶ $handle->push_read(line => qr|\r?\n|, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 my $line = $_[1];
41 0 push @{$info->{output_lines}}, $line;
42 log info => sprintf "[%s :: %s] %s",
43 0 $self->{host}, $name, $line;
44 0 });
45 },
46 0 ▶ on_eof => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 $cv->end;
48 },
49 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 my $msg = $_[2];
51 0 ▶ log error => sprintf "[%s :: %s] %s", $self->{host}, $name, $msg
Branch: 1 branch
BranchTrueFalseTotal
unless $! == 32 0 0 0
52 unless $! == POSIX::EPIPE;
53 0 $cv->end;
54 },
55 0 );
56 0 push @$handles, $handle;
57 }
58  
59 0 $cv->recv;
60  
61 0 for my $h (@$handles) {
62 0 $h->destroy;
63 }
64 }
65  
66 0 ▶sub captured_str {
Subroutine captured_str: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my ($self, $name) = @_;
68 0 ▶ my $hinfo = $self->{handle_container}->{$name} or return '';
Branch: 1 branch
BranchTrueFalseTotal
my $hinfo = $self->{"handle_container"}{$name} or return "" 0 0 0
69 0 my $str = join("\n", @{$hinfo->{output_lines}});
70 0 return $str;
71 }
72  
73 2 1;
« Cinnamon/Local.pm ↑ Summary Cinnamon/Context.pm »