DBus/WriteMsg.pm

filter: Statementstmt 81.5% 31 / 38 Branchbran 33.3% 4 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 70.7% 46 / 65 CC 8 SCAR 14.9
CC
8
Cov
70%
WRITE
12.2
enqueue_message
3.1
__ANON__
2.0
CRAP 4.4
« DBus/Socket.pm ↑ Summary DBus/Peer.pm »
1 package Protocol::DBus::WriteMsg;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use Protocol::DBus::Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use parent qw( IO::Framed::Write );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 my %fh_fds;
13  
14 5 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
15 5 my ($self) = @_;
16  
17 5 my $fh = delete $fh_fds{ $self->get_write_fh() };
18  
19 5 ▶ $self->SUPER::DESTROY() if IO::Framed::Write->can('DESTROY');
Branch: 1 branch
BranchTrueFalseTotal
if "IO::Framed::Write"->can("DESTROY") 0 5 5
20  
21 5 return;
22 }
23  
24 6 ▶sub enqueue_message {
Subroutine enqueue_message: called CC=3 SCAR=11.2
Pod undocumented
25 6 my ($self, $buf_sr, $fds_ar, $on_send) = @_;
26  
27 6 ▶ push @{ $fh_fds{$self->get_write_fh()} }, ($fds_ar && @$fds_ar) ? $fds_ar : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fds_ar && @$fds_ar ? : 0 6 6
Condition66%2/3
$fds_ar and @$fds_ar
!ll&&!rl&&r
240
MC/DC0%0/2
$fds_ar and @$fds_ar
$fds_ar @$fds_ar
Truth table66%2/3
A and B
A= $fds_arB= @$fds_ar
ABresult
0X0
100
111
28  
29 $self->write(
30 $$buf_sr,
31 6 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
32  
33 # We’re done with the message, so we remove the FDs entry,
34 # which by here should be undef.
35 6 shift @{ $fh_fds{$self->get_write_fh()} };
36  
37 6 ▶ $on_send->() if $on_send;
Branch: 1 branch
BranchTrueFalseTotal
if $on_send 6 0 6
38 },
39 6 );
40  
41 6 return $self;
42 }
43  
44 # Receives ($fh, $buf)
45 6 ▶sub WRITE {
Subroutine WRITE: called CC=4 SCAR=25.0
46  
47 # Only use sendmsg if we actually need to.
48 6 ▶ if (my $fds_ar = $fh_fds{ $_[0] }[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fds_ar = $fh_fds{$_[0]}[0]) 0 6 6
49 0 ▶ die 'Socket::MsgHdr is not loaded!' if !Socket::MsgHdr->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless "Socket::MsgHdr"->can("new") 0 0 0
50  
51 0 my $msg = Socket::MsgHdr->new( buf => $_[1] );
52  
53 0 $msg->cmsghdr(
54 Socket::SOL_SOCKET(), Socket::SCM_RIGHTS(),
55 pack( 'I!*', @$fds_ar ),
56 );
57  
58 0 my $bytes = Protocol::DBus::Socket::sendmsg_nosignal( $_[0], $msg, 0 );
59  
60 # NOTE: This assumes that, on an incomplete write, the ancillary
61 # data (i.e., the FDs) will have been sent, and there is no need
62 # to resend. That appears to be the case on Linux and MacOS, but
63 # I can’t find any actual documentation to that effect. <shrug>
64 0 ▶ if ($bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) 0 0 0
65 0 undef $fh_fds{ $_[0] }[0];
66 }
67  
68 0 return $bytes;
69 }
70  
71 6 return Protocol::DBus::Socket::send_nosignal( $_[0], $_[1], 0 );
72 }
73  
74 6 1;
« DBus/Socket.pm ↑ Summary DBus/Peer.pm »