blib/lib/IPC/Msg.pm

filter: Statementstmt 78.1% 43 / 55 Branchbran 31.8% 7 / 22 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 83.3% 10 / 12 Podpod 100% 7 / 7 totaltotal 62.6% 72 / 115 CC 16 SCAR 21.7
CC
16
Cov
62%
set
30.0
rcv
7.3
snd
5.0
CRAP 8.7
« blib/lib/IPC/Semaphore.pm ↑ Summary blib/lib/IPC/SharedMem.pm »
1 ################################################################################
2 #
3 # Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz <mhx@cpan.org>.
4 # Version 1.x, Copyright (C) 1997, Graham Barr <gbarr@pobox.com>.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the same terms as Perl itself.
8 #
9 ################################################################################
10  
11 package IPC::Msg;
12  
13 2 ▶use IPC::SysV qw(IPC_STAT IPC_SET IPC_RMID);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 $VERSION = '2.09';
19  
20 # Figure out if we have support for native sized types
21 2 ▶my $N = do { my $foo = eval { pack "L!", 0 }; $@ ? '' : '!' };
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 2 2
22  
23 {
24 2 package IPC::Msg::stat;
25  
26 2 ▶ use Class::Struct qw(struct);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 struct 'IPC::Msg::stat' => [
29 uid => '$',
30 gid => '$',
31 cuid => '$',
32 cgid => '$',
33 mode => '$',
34 qnum => '$',
35 qbytes => '$',
36 lspid => '$',
37 lrpid => '$',
38 stime => '$',
39 rtime => '$',
40 ctime => '$',
41 ];
42 }
43  
44 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
45 1 ▶ @_ == 3 || croak 'IPC::Msg->new( KEY , FLAGS )';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("IPC::Msg->new( KEY , FLAGS )") 1 0 1
46 1 my $class = shift;
47  
48 1 my $id = msgget($_[0],$_[1]);
49  
50 1 ▶ defined($id)
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 1 0 1
51 ? bless \$id, $class
52 : undef;
53 }
54  
55 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
56 0 my $self = shift;
57 0 $$self;
58 }
59  
60 2 ▶sub stat {
Subroutine stat: called CC=2 SCAR=7.0
Pod documented
61 2 my $self = shift;
62 2 my $data = "";
63 2 ▶ msgctl($$self,IPC_STAT,$data) or
Branch: 1 branch
BranchTrueFalseTotal
msgctl $$self, IPC_STAT(), $data or return undef 2 0 2
64 return undef;
65 2 IPC::Msg::stat->new->unpack($data);
66 }
67  
68 0 ▶sub set {
Subroutine set: not called CC=5 SCAR=34.0
Pod documented
69 0 my $self = shift;
70 0 my $ds;
71  
72 0 ▶ if(@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
73 0 $ds = shift;
74 }
75 else {
76 0 ▶ croak 'Bad arg count' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
77 0 my %arg = @_;
78 0 ▶ $ds = $self->stat
Branch: 1 branch
BranchTrueFalseTotal
$ds = $self->stat or return undef 0 0 0
79 or return undef;
80 0 my($key,$val);
81 0 ▶ $ds->$key($val)
Branch: 1 branch
BranchTrueFalseTotal
() = each %arg and do { $ds->$key($val) } 0 0 0
82 while(($key,$val) = each %arg);
83 }
84  
85 0 msgctl($$self,IPC_SET,$ds->pack);
86 }
87  
88 1 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
89 1 my $self = shift;
90 1 (msgctl($$self,IPC_RMID,0), undef $$self)[0];
91 }
92  
93 1 ▶sub rcv {
Subroutine rcv: called CC=6 SCAR=19.9
Pod documented
94 1 ▶ @_ <= 5 && @_ >= 3 or croak '$msg->rcv( BUF, LEN, TYPE, FLAGS )';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 5 and @_ >= 3 or croak("\$msg->rcv( BUF, LEN, TYPE, FLAGS )") 1 0 1
Condition33%1/3
@_ <= 5 and @_ >= 3
!ll&&!rl&&r
001
MC/DC0%0/2
@_ <= 5 and @_ >= 3
@_ <= 5 @_ >= 3
Truth table33%1/3
A and B
A= @_ <= 5B= @_ >= 3
ABresult
0X0
100
111
95 1 my $self = shift;
96 1 my $buf = "";
97 1 ▶ msgrcv($$self,$buf,$_[1],$_[2] || 0, $_[3] || 0) or
Branch: 1 branch
BranchTrueFalseTotal
msgrcv $$self, $buf, $_[1], $_[2] || 0, $_[3] || 0 or return 1 0 1
Condition50%2/4
$_[2] || 0
l!l
01
$_[3] || 0
l!l
10
MC/DC0%0/1
$_[2] || 0
$_[2]
MC/DC0%0/1
$_[3] || 0
$_[3]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
98 return;
99 1 my $type;
100 1 ($type,$_[0]) = unpack("l$N a*",$buf);
101 1 $type;
102 }
103  
104 1 ▶sub snd {
Subroutine snd: called CC=4 SCAR=16.1
Pod documented
105 1 ▶ @_ <= 4 && @_ >= 3 or croak '$msg->snd( TYPE, BUF, FLAGS )';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 4 and @_ >= 3 or croak("\$msg->snd( TYPE, BUF, FLAGS )") 1 0 1
Condition33%1/3
@_ <= 4 and @_ >= 3
!ll&&!rl&&r
001
MC/DC0%0/2
@_ <= 4 and @_ >= 3
@_ <= 4 @_ >= 3
Truth table33%1/3
A and B
A= @_ <= 4B= @_ >= 3
ABresult
0X0
100
111
106 1 my $self = shift;
107 1 ▶ msgsnd($$self,pack("l$N a*",$_[0],$_[1]), $_[2] || 0);
Condition50%1/2
$_[2] || 0
l!l
10
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
108 }
109  
110  
111 2 1;
112  
113 __END__
« blib/lib/IPC/Semaphore.pm ↑ Summary blib/lib/IPC/SharedMem.pm »