Weixin/Message/Queue.pm

filter: Statementstmt 4.3% 1 / 23 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 2.6% 1 / 38 CC 5 SCAR 20.5
CC
5
Cov
3%
get
12.0
new
6.0
put
6.0
CRAP 7.8
« Weixin/Plugin/UploadQRcode.pm ↑ Summary Weixin/Plugin/ImageStore.pm »
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
BranchTrueFalseTotal
if (ref $p{"callback_for_get"} eq "CODE") 0 0 0
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
BranchTrueFalseTotal
unless ref $self->{"callback_for_get"} eq "CODE" 0 0 0
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
BranchTrueFalseTotal
if (defined $cb) 0 0 0
27 0 ▶ die "Mojo::Weixin::Message::Queue->get()仅接受一个函数引用\n" unless ref $cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 0 0
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;
« Weixin/Plugin/UploadQRcode.pm ↑ Summary Weixin/Plugin/ImageStore.pm »