| 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
Condition33%1/3
@_ >= 2 and @_ <= 4
MC/DC0%0/2
@_ >= 2 and @_ <= 4
@_ >= 2
@_ <= 4
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 4
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 26 | 24 | ▶ | $args[3] = attr_pack($args[3]) if defined $args[3]; # pack attr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 24 | ▶ | defined(my $mqdes = mq_open(@args)) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 16 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 3 | ▶ | (@_ == 0) or croak 'Usage: $mq->unlink()'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 3 | my $rc = mq_unlink($self->{name}); | |||||||||||||||||||||||||||
| 45 | 3 | ▶ | $self->{name} = undef if defined $rc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 3 | return $rc; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | else | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 19 | ▶ | (@_ == 1) or croak 'Usage: POSIX::RT::MQ->unlink(name)'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@_ >= 0 and @_ <= 1
MC/DC0%0/2
@_ >= 0 and @_ <= 1
@_ >= 0
@_ <= 1
Truth table33%1/3
A and B
A= @_ >= 0B= @_ <= 1
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@_ >= 1 and @_ <= 2
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1
@_ <= 2
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 2
| |||||||||||||||||||||||||||||
| 68 | 44 | ▶ | mq_send( $self->{mqdes}, $_[0], ($_[1] || 0) ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$_[1] || 0
MC/DC100%1/1
$_[1] || 0
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 75 | 44 | my @result = mq_receive($self->{mqdes}, $self->{_saved_attr_}{mq_msgsize}); | |||||||||||||||||||||||||||
| 76 | 44 | ▶ | wantarray ? @result : $result[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $a = $self->attr() or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $old_blocking = ($a->{mq_flags} & O_NONBLOCK) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($_[0]) { $a->{mq_flags} &= (~O_NONBLOCK); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | else { $a->{mq_flags} |= O_NONBLOCK; } | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $self->attr($a) or $old_blocking = undef;; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||