blib/lib/POSIX/RT/MQ.pm

filter: Statementstmt 98.6% 73 / 74 Branchbran 72.9% 35 / 48 Conditioncond 42.8% 6 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 94.1% 16 / 17 Podpod 72.7% 8 / 11 totaltotal 80.3% 139 / 173 CC 30 SCAR 16.0
CC
30
Cov
84%
open
9.7
blocking
7.1
unlink
5.0
CRAP 5.0
↑ Summary MQ.xs »
1 package POSIX::RT::MQ;
2  
3 # $Id: MQ.pm,v 1.12 2003/01/28 07:10:03 ilja Exp $
4  
5 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Fcntl 'O_NONBLOCK';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 require DynaLoader;
12  
13 5 our @ISA = qw(DynaLoader);
14 5 our $VERSION = '0.04';
15  
16 5 bootstrap POSIX::RT::MQ $VERSION;
17  
18 sub open
19 {
20 29 ▶ my $proto = shift;
Subroutine open: called CC=9 SCAR=22.7
Pod documented
21 29 ▶ (@_ >= 2 && @_ <= 4)
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 and @_ <= 4 or croak("Usage: POSIX::RT::MQ->open(name, oflag [, mode [, attr]])") 0 29 29
Condition33%1/3
@_ >= 2 and @_ <= 4
!ll&&!rl&&r
0029
MC/DC0%0/2
@_ >= 2 and @_ <= 4
@_ >= 2 @_ <= 4
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 4
ABresult
0X0
100
111
22 or croak 'Usage: POSIX::RT::MQ->open(name, oflag [, mode [, attr]])';
23  
24 29 my @args = @_;
25 29 ▶ $args[2] = 0666 unless defined $args[2];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args[2] 11 18 29
26 # work around 'using undefined value' warnings
27 # todo: fix XS?
28 29 ▶ delete $args[3] unless defined $args[3];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args[3] 11 18 29
29 29 ▶ $args[3] = attr_pack($args[3]) if defined $args[3]; # pack attr
Branch: 1 branch
BranchTrueFalseTotal
if defined $args[3] 18 11 29
30
31 29 ▶ defined(my $mqdes = mq_open(@args)) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $mqdes = &mq_open(@args)) or return undef 2 27 29
32 27 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0270
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
33 27 my $self = bless { name=>$args[0], mqdes=>$mqdes }, $class;
34  
35 # get attributes and save for future references (in receive())
36 27 ▶ $self->{_saved_attr_} = $self->attr or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_saved_attr_"} = $self->attr or return undef 0 27 27
37
38 27 return $self;
39 }
40  
41 sub unlink
42 {
43 26 ▶ my $self = shift;
Subroutine unlink: called CC=5 SCAR=16.2
Pod documented
44 26 ▶ if (ref $self)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 23 26
45 {
46 3 ▶ (@_ == 0) or croak 'Usage: $mq->unlink()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or croak("Usage: \$mq->unlink()") 0 3 3
47 3 my $rc = mq_unlink($self->{name});
48 3 ▶ $self->{name} = undef if defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rc 2 1 3
49 3 return $rc;
50 }
51 else
52 {
53 23 ▶ (@_ == 1) or croak 'Usage: POSIX::RT::MQ->unlink(name)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("Usage: POSIX::RT::MQ->unlink(name)") 0 23 23
54 23 return mq_unlink($_[0]);
55 }
56 }
57  
58 sub attr
59 {
60 42 ▶ my $self = shift;
Subroutine attr: called CC=4 SCAR=15.2
Pod documented
61 42 ▶ (@_ >= 0 && @_ <= 1) or croak 'Usage: $mq->attr( [new_attr] )';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 0 and @_ <= 1 or croak("Usage: \$mq->attr( [new_attr] )") 0 42 42
Condition33%1/3
@_ >= 0 and @_ <= 1
!ll&&!rl&&r
0042
MC/DC0%0/2
@_ >= 0 and @_ <= 1
@_ >= 0 @_ <= 1
Truth table33%1/3
A and B
A= @_ >= 0B= @_ <= 1
ABresult
0X0
100
111
62 42 my $attr_packed = mq_attr( $self->{mqdes}, map {attr_pack($_)} @_ );
63  
64 42 ▶ defined $attr_packed ? attr_unpack($attr_packed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr_packed ? : 42 0 42
65 }
66  
67 sub send
68 {
69 87 ▶ my $self = shift;
Subroutine send: called CC=4 SCAR=14.9
Pod documented
70 87 ▶ (@_ >= 1 && @_ <= 2) or croak 'Usage: $mq->send($msg ,[ $prio ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 2 or croak("Usage: \$mq->send(\$msg ,[ \$prio ])") 0 87 87
Condition33%1/3
@_ >= 1 and @_ <= 2
!ll&&!rl&&r
0087
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1 @_ <= 2
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 2
ABresult
0X0
100
111
71 87 ▶ return mq_send( $self->{mqdes}, $_[0], ($_[1] || 0) );
Condition100%2/2
$_[1] || 0
l!l
4938
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
72 }
73  
74 sub receive
75 {
76 67 ▶ my $self = shift;
Subroutine receive: called CC=3 SCAR=11.0
Pod documented
77 67 ▶ (@_ == 0) or croak 'Usage: $mq->receive()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or croak("Usage: \$mq->receive()") 0 67 67
78 67 my @result = mq_receive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize});
79 67 ▶ wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 65 2 67
80 }
81  
82 sub notify
83 {
84 5 ▶ my $self = shift;
Subroutine notify: called CC=2 SCAR=7.1
Pod documented
85 5 ▶ (@_ <= 1) or croak 'Usage: $mq->notify([ $signo ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 1 or croak("Usage: \$mq->notify([ \$signo ])") 0 5 5
86 5 mq_notify( $self->{mqdes}, @_ );
87 }
88  
89 sub blocking
90 {
91 6 ▶ my $self = shift;
Subroutine blocking: called CC=7 SCAR=19.6
Pod documented
92 6 ▶ (@_ <= 1) or croak 'Usage: $mq->blocking([ BOOL ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 1 or croak("Usage: \$mq->blocking([ BOOL ])") 0 6 6
93  
94 6 ▶ my $a = $self->attr() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $a = $self->attr or return undef 0 6 6
95 6 ▶ my $old_blocking = ($a->{mq_flags} & O_NONBLOCK) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$a->{'mq_flags'} & 2048 ? : 2 4 6
96 6 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 3 6
97 {
98 3 ▶ if ($_[0]) { $a->{mq_flags} &= (~O_NONBLOCK); }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 1 2 3
99 2 else { $a->{mq_flags} |= O_NONBLOCK; }
100  
101 3 ▶ $self->attr($a) or $old_blocking = undef;;
Branch: 1 branch
BranchTrueFalseTotal
$self->attr($a) or $old_blocking = undef 0 3 3
102 }
103  
104 6 $old_blocking;
105 }
106  
107 2 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
108  
109 # expose mqdes
110 0 ▶sub mqdes { $_[0]->{mqdes} }
Subroutine mqdes: not called CC=1 SCAR=6.9
Pod undocumented
111  
112 sub DESTROY
113 {
114 27 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=7.1
115 #print "destrsroying $self\n";
116 27 ▶ defined($self->{mqdes}) and mq_close($self->{mqdes});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"mqdes"} and &mq_close($self->{"mqdes"}) 27 0 27
117 27 $self->{mqdes} = undef;
118 }
119  
120 # allow explicit close
121 5 *close = \&DESTROY;
122  
123 sub attr_pack
124 {
125 22 ▶ my $as_hash = shift;
Subroutine attr_pack: called CC=2 SCAR=6.9
Pod undocumented
126 22 ▶ mq_attr_pack( map {defined $as_hash->{$_} ? $as_hash->{$_} : 0}
Branch: 1 branch
BranchTrueFalseTotal
defined $as_hash->{$_} ? : 51 37 88
127 qw/mq_flags mq_maxmsg mq_msgsize mq_curmsgs/ );
128 }
129  
130  
131 sub attr_unpack
132 {
133 42 ▶ my @attr = mq_attr_unpack(shift);
Subroutine attr_unpack: called CC=1 SCAR=0.0
Pod undocumented
134 42 { mq_flags=>$attr[0], mq_maxmsg=>$attr[1], mq_msgsize=>$attr[2], mq_curmsgs=>$attr[3] };
135 }
136  
137 5 1;
138  
139 __END__
↑ Summary MQ.xs »