blib/lib/POSIX/RT/MQ.pm

filter: Statementstmt 80.2% 57 / 71 Branchbran 47.8% 22 / 46 Conditioncond 42.8% 6 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 87.5% 14 / 16 Podpod 80.0% 8 / 10 totaltotal 65.0% 108 / 166 CC 29 SCAR 25.5
CC
29
Cov
65%
blocking
56.0
open
8.8
notify
6.0
CRAP 12.8
↑ 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 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Fcntl 'O_NONBLOCK';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 require DynaLoader;
12  
13 4 our @ISA = qw(DynaLoader);
14 4 our $VERSION = '0.03';
15  
16 4 bootstrap POSIX::RT::MQ $VERSION;
17  
18 sub open
19 {
20 24 ▶ my $proto = shift;
Subroutine open: called CC=8 SCAR=21.7
Pod documented
21 24 ▶ (@_ >= 2 && @_ <= 4)
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 and @_ <= 4 or croak("Usage: POSIX::RT::MQ->open(name, oflag [, mode [, attr]])") 0 24 24
Condition33%1/3
@_ >= 2 and @_ <= 4
!ll&&!rl&&r
0024
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 24 my @args = @_;
25 24 ▶ $args[2] = 0666 unless defined $args[2];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args[2] 10 14 24
26 24 ▶ $args[3] = attr_pack($args[3]) if defined $args[3]; # pack attr
Branch: 1 branch
BranchTrueFalseTotal
if defined $args[3] 14 10 24
27
28 24 ▶ defined(my $mqdes = mq_open(@args)) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $mqdes = &mq_open(@args)) or return undef 8 16 24
29 16 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0160
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
30 16 my $self = bless { name=>$args[0], mqdes=>$mqdes }, $class;
31  
32 # get attributes and save for future references (in receive())
33 16 ▶ $self->{_saved_attr_} = $self->attr or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_saved_attr_"} = $self->attr or return undef 0 16 16
34
35 16 $self;
36 }
37  
38 sub unlink
39 {
40 22 ▶ my $self = shift;
Subroutine unlink: called CC=5 SCAR=16.2
Pod documented
41 22 ▶ if (ref $self)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 19 22
42 {
43 3 ▶ (@_ == 0) or croak 'Usage: $mq->unlink()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or croak("Usage: \$mq->unlink()") 0 3 3
44 3 my $rc = mq_unlink($self->{name});
45 3 ▶ $self->{name} = undef if defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rc 2 1 3
46 3 return $rc;
47 }
48 else
49 {
50 19 ▶ (@_ == 1) or croak 'Usage: POSIX::RT::MQ->unlink(name)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("Usage: POSIX::RT::MQ->unlink(name)") 0 19 19
51 19 return mq_unlink($_[0]);
52 }
53 }
54  
55 sub attr
56 {
57 16 ▶ my $self = shift;
Subroutine attr: called CC=4 SCAR=16.4
Pod documented
58 16 ▶ (@_ >= 0 && @_ <= 1) or croak 'Usage: $mq->attr( [new_attr] )';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 0 and @_ <= 1 or croak("Usage: \$mq->attr( [new_attr] )") 0 16 16
Condition33%1/3
@_ >= 0 and @_ <= 1
!ll&&!rl&&r
0016
MC/DC0%0/2
@_ >= 0 and @_ <= 1
@_ >= 0 @_ <= 1
Truth table33%1/3
A and B
A= @_ >= 0B= @_ <= 1
ABresult
0X0
100
111
59 16 my $attr_packed = mq_attr( $self->{mqdes}, map {attr_pack($_)} @_ );
60  
61 16 ▶ defined $attr_packed ? attr_unpack($attr_packed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr_packed ? : 16 0 16
62 }
63  
64 sub send
65 {
66 44 ▶ my $self = shift;
Subroutine send: called CC=4 SCAR=14.9
Pod documented
67 44 ▶ (@_ >= 1 && @_ <= 2) or croak 'Usage: $mq->send($msg ,[ $prio ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 2 or croak("Usage: \$mq->send(\$msg ,[ \$prio ])") 0 44 44
Condition33%1/3
@_ >= 1 and @_ <= 2
!ll&&!rl&&r
0044
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1 @_ <= 2
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 2
ABresult
0X0
100
111
68 44 ▶ mq_send( $self->{mqdes}, $_[0], ($_[1] || 0) );
Condition100%2/2
$_[1] || 0
l!l
3212
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
69 }
70  
71 sub receive
72 {
73 44 ▶ my $self = shift;
Subroutine receive: called CC=3 SCAR=11.4
Pod documented
74 44 ▶ (@_ == 0) or croak 'Usage: $mq->receive()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or croak("Usage: \$mq->receive()") 0 44 44
75 44 my @result = mq_receive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize});
76 44 ▶ wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 44 0 44
77 }
78  
79 sub notify
80 {
81 0 ▶ my $self = shift;
Subroutine notify: not called CC=2 SCAR=17.9
Pod documented
82 0 ▶ (@_ <= 1) or croak 'Usage: $mq->notify([ $signo ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 1 or croak("Usage: \$mq->notify([ \$signo ])") 0 0 0
83 0 mq_notify( $self->{mqdes}, @_ );
84 }
85  
86 sub blocking
87 {
88 0 ▶ my $self = shift;
Subroutine blocking: not called CC=7 SCAR=40.3
Pod documented
89 0 ▶ (@_ <= 1) or croak 'Usage: $mq->blocking([ BOOL ])';
Branch: 1 branch
BranchTrueFalseTotal
@_ <= 1 or croak("Usage: \$mq->blocking([ BOOL ])") 0 0 0
90  
91 0 ▶ my $a = $self->attr() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $a = $self->attr or return undef 0 0 0
92 0 ▶ my $old_blocking = ($a->{mq_flags} & O_NONBLOCK) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$a->{'mq_flags'} & 2048 ? : 0 0 0
93 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
94 {
95 0 ▶ if ($_[0]) { $a->{mq_flags} &= (~O_NONBLOCK); }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 0 0 0
96 0 else { $a->{mq_flags} |= O_NONBLOCK; }
97  
98 0 ▶ $self->attr($a) or $old_blocking = undef;;
Branch: 1 branch
BranchTrueFalseTotal
$self->attr($a) or $old_blocking = undef 0 0 0
99 }
100  
101 0 $old_blocking;
102 }
103  
104 2 ▶sub name { $_[0]->{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
105  
106 sub DESTROY
107 {
108 16 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=7.1
109 16 ▶ defined($self->{mqdes}) and mq_close($self->{mqdes});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"mqdes"} and &mq_close($self->{"mqdes"}) 16 0 16
110 16 $self->{mqdes} = undef;
111 }
112  
113  
114 sub attr_pack
115 {
116 14 ▶ my $as_hash = shift;
Subroutine attr_pack: called CC=2 SCAR=6.9
Pod undocumented
117 14 ▶ mq_attr_pack( map {defined $as_hash->{$_} ? $as_hash->{$_} : 0}
Branch: 1 branch
BranchTrueFalseTotal
defined $as_hash->{$_} ? : 28 28 56
118 qw/mq_flags mq_maxmsg mq_msgsize mq_curmsgs/ );
119 }
120  
121  
122 sub attr_unpack
123 {
124 16 ▶ my @attr = mq_attr_unpack(shift);
Subroutine attr_unpack: called CC=1 SCAR=0.0
Pod undocumented
125 16 { mq_flags=>$attr[0], mq_maxmsg=>$attr[1], mq_msgsize=>$attr[2], mq_curmsgs=>$attr[3] };
126 }
127  
128 4 1;
129  
130 __END__
↑ Summary MQ.xs »