| 1 | package AnyEvent::RabbitMQ::LocalQueue; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '1.22'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | 1 | my $class = shift; | |||||||||
| 10 | 1 | return bless { | |||||||||
| 11 | _message_queue => [], | ||||||||||
| 12 | _drain_code_queue => [], | ||||||||||
| 13 | }, $class; | ||||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 6 | ▶ | sub push { | ||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 6 | my $self = shift; | |||||||||
| 18 | |||||||||||
| 19 | 6 | CORE::push @{$self->{_message_queue}}, @_; | |||||||||
| 20 | 6 | return $self->_drain_queue(); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 6 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 6 | my $self = shift; | |||||||||
| 25 | |||||||||||
| 26 | 6 | CORE::push @{$self->{_drain_code_queue}}, @_; | |||||||||
| 27 | 6 | return $self->_drain_queue(); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 12 | ▶ | sub _drain_queue { | ||||||||
|
Subroutine
_drain_queue: called CC=3 SCAR=11.0
| |||||||||||
| 31 | 12 | my $self = shift; | |||||||||
| 32 | |||||||||||
| 33 | 12 | my $message_count = scalar @{$self->{_message_queue}}; | |||||||||
| 34 | 12 | my $drain_code_count = scalar @{$self->{_drain_code_queue}}; | |||||||||
| 35 | |||||||||||
| 36 | 12 | ▶ | my $count = $message_count < $drain_code_count | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | ? $message_count : $drain_code_count; | ||||||||||
| 38 | |||||||||||
| 39 | 12 | for (1 .. $count) { | |||||||||
| 40 | 10 | &{shift @{$self->{_drain_code_queue}}}( | |||||||||
| 41 | 10 | shift @{$self->{_message_queue}} | |||||||||
| 42 | ); | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 12 | return $self; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub _flush { | ||||||||
|
Subroutine
_flush: not called CC=2 SCAR=17.9
| |||||||||||
| 49 | 0 | my ($self, $frame) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 0 | $self->_drain_queue; | |||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | while (my $cb = shift @{$self->{_drain_code_queue}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | local $@; # Flush frames immediately, throwing away errors for on-close | |||||||||
| 55 | 0 | eval { $cb->($frame) }; | |||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||