File Coverage

blib/lib/Mojo/Weixin/Message/Queue.pm
Criterion Covered Total %
statement 0 22 0.0
branch 0 8 0.0
condition n/a
subroutine 0 4 0.0
pod 0 3 0.0
total 0 37 0.0


line stmt bran cond sub pod time code
1             package Mojo::Weixin::Message::Queue;
2             sub new {
3 0     0 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 0         if(ref $p{callback_for_get} eq "CODE"){
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             sub put {
17 0     0 0   my $self = shift;
18             die "Mojo::Weixin::Message::Queue->put()失败,请检查是否已经设置了队列get()回调\n"
19 0 0         unless ref $self->{callback_for_get} eq 'CODE';
20 0           push @{ $self->{queue} } ,$_[0];
  0            
21 0           $self->_notify_to_get();
22             }
23             sub get {
24 0     0 0   my $self = shift;
25 0           my $cb = shift;
26 0 0         if(defined $cb){
27 0 0         die "Mojo::Weixin::Message::Queue->get()仅接受一个函数引用\n" unless ref $cb eq 'CODE';
28 0           $self->{callback_for_get} = $cb;
29 0           $self->{callback_for_get_bak} = $cb;
30             }
31             }
32             sub _notify_to_get{
33 0     0     my $self = shift;
34 0           my $msg = shift @{$self->{queue}};
  0            
35 0           $self->{callback_for_get}->($msg);
36             }
37             1;