| 1 | #+############################################################################## | ||||||||||||||||||||||||||||
| 2 | # # | ||||||||||||||||||||||||||||
| 3 | # File: Net/STOMP/Client/Receipt.pm # | ||||||||||||||||||||||||||||
| 4 | # # | ||||||||||||||||||||||||||||
| 5 | # Description: Receipt support for Net::STOMP::Client # | ||||||||||||||||||||||||||||
| 6 | # # | ||||||||||||||||||||||||||||
| 7 | #-############################################################################## | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # module definition | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package Net::STOMP::Client::Receipt; | ||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | our $VERSION = "2.4"; | |||||||||||||||||||||||||||
| 17 | 2 | our $REVISION = sprintf("%d.%02d", q$Revision: 2.2 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # used modules | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use No::Worries::Die qw(dief); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use No::Worries::Export qw(export_control); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # return the list of not-yet-received receipts | ||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub receipts : method { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
receipts: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my(@list); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | @list = keys(%{ $self->{"receipts"} }) if $self->{"receipts"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | return(@list); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | # wait for all receipts to be received | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub wait_for_receipts : method { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my($self, %option) = @_; | ||||||||||||||||||||||||||
|
Subroutine
wait_for_receipts: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return(0) unless $self->receipts(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $option{callback} = sub { return($self->receipts() == 0) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | 0 | return($self->wait_for_frames(%option)); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # hook for all client frames | ||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub _client_hook ($$) { | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my($self, $frame) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_client_hook: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 56 | 0 | my($value); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $value = $frame->header("receipt"); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | return unless defined($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | dief("duplicate receipt: %s", $value) if $self->{"receipts"}{$value}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | # hook for the RECEIPT frame | ||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub _receipt_hook ($$) { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my($self, $frame) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_receipt_hook: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 69 | 0 | my($value); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | $value = $frame->header("receipt-id"); | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | dief("missing receipt-id in RECEIPT frame") unless defined($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | dief("unexpected receipt: %s", $value) | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | unless $self->{"receipts"} and $self->{"receipts"}{$value}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"receipts"} and $self->{"receipts"}{$value}
MC/DC0%0/2
$self->{"receipts"} and $self->{"receipts"}{$value}
$self->{"receipts"}
$self->{"receipts"}{$value}
Truth table0%0/3
A and B
A= $self->{"receipts"}B= $self->{"receipts"}{$value}
| |||||||||||||||||||||||||||||
| 75 | 0 | delete($self->{"receipts"}{$value}); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | # register the hooks | ||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | foreach my $frame (qw(ABORT ACK BEGIN COMMIT DISCONNECT NACK | |||||||||||||||||||||||||||
| 83 | SEND SUBSCRIBE UNSUBSCRIBE)) { | ||||||||||||||||||||||||||||
| 84 | 18 | $Net::STOMP::Client::Hook{$frame}{"receipt"} = \&_client_hook; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 2 | $Net::STOMP::Client::Hook{"RECEIPT"}{"receipt"} = \&_receipt_hook; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||
| 89 | # export control | ||||||||||||||||||||||||||||
| 90 | # | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub import : method { | ||||||||||||||||||||||||||||
| 93 | 2 | ▶ | my($pkg, %exported); | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 2 | $pkg = shift(@_); | |||||||||||||||||||||||||||
| 96 | 2 | grep($exported{$_}++, qw(receipts wait_for_receipts)); | |||||||||||||||||||||||||||
| 97 | 2 | export_control(scalar(caller()), $pkg, \%exported, @_); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||