DBus/WriteMsg.pm

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