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