| 1 | package Webqq::Message::Queue; | ||||||||||
| 2 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 3 | 0 | my $class = shift; | |||||||||
| 4 | 0 | my $self = { | |||||||||
| 5 | queue => [], | ||||||||||
| 6 | callback_for_get => undef, | ||||||||||
| 7 | callback_for_get_bak => undef, | ||||||||||
| 8 | }; | ||||||||||
| 9 | 0 | return bless $self,$class; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub put{ | ||||||||
|
Subroutine
put: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 13 | 0 | my $self = shift; | |||||||||
| 14 | die "Webqq::Message::Queue->put()失败,请检查是否已经设置了队列get()回调\n" | ||||||||||
| 15 | 0 | ▶ | unless ref $self->{callback_for_get} eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | push @{ $self->{queue} } ,$_[0]; | |||||||||
| 17 | 0 | $self->_notify_to_get(); | |||||||||
| 18 | } | ||||||||||
| 19 | 0 | ▶ | sub get{ | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 20 | 0 | my $self = shift; | |||||||||
| 21 | 0 | my $cb = shift; | |||||||||
| 22 | 0 | ▶ | die "Webqq::Message::Queue->get()仅接受一个函数引用\n" unless ref $cb eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | $self->{callback_for_get} = $cb; | |||||||||
| 24 | 0 | $self->{callback_for_get_bak} = $cb; | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | ▶ | sub _notify_to_get{ | ||||||||
|
Subroutine
_notify_to_get: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 0 | my $self = shift; | |||||||||
| 28 | 0 | my $msg = shift @{$self->{queue}}; | |||||||||
| 29 | 0 | $self->{callback_for_get}->($msg); | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 1 | 1; | |||||||||