Webqq/Client/Plugin.pm

filter: Statementstmt 2.2% 1 / 45 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 6 totaltotal 1.4% 1 / 71 CC 11 SCAR 30.2
CC
11
Cov
2%
load
30.0
call
30.0
call_all
6.0
CRAP 20.5
« Webqq/Client/Util.pm ↑ Summary Webqq/Client/Plugin/SmartReply2.pm »
1 package Webqq::Client::Plugin;
2 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
3 0 bless {
4 plugin_num => 0,
5 plugins => {},
6 };
7 }
8  
9 0 ▶sub load {
Subroutine load: not called CC=5 SCAR=34.0
Pod undocumented
10 0 my $self = shift;
11 0 my @module_name = @_;
12 0 for my $module_name (@module_name){
13 0 my $module_function = undef;
14 0 ▶ if(substr($module_name,0,1) eq '+'){
Branch: 1 branch
BranchTrueFalseTotal
if (substr($module_name, 0, 1) eq '+') { } 0 0 0
15 0 substr($module_name,0,1) = "";
16 0 $module = $module_name;
17 }
18 else{
19 0 $module = "Webqq::Client::Plugin::" . $module_name;
20 }
21 0 eval "require $module";
22 0 ▶ die "加载插件[ $module ]失败: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
23 0 $module_function = *{"${module}::call"}{CODE};
24 0 ▶ die "加载插件[ $module ]失败: 未获取到call函数引用\n" if ref $module_function ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $module_function ne "CODE" 0 0 0
25 0 $self->{plugin_num}++;
26 $self->{plugins}{$module_name} = {
27 id=>$self->{plugin_num},
28 0 code=>$module_function,
29 };
30 }
31 }
32  
33 0 ▶sub call_all{
Subroutine call_all: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my $self = shift;
35 0 for(sort {$self->{plugins}{$a}{id}<=>$self->{plugins}{$b}{id}} keys %{$self->{plugins}}){
36 0 &{$self->{plugins}{$_}{code}}($self,@_);
37 }
38 }
39  
40 0 ▶sub call{
Subroutine call: not called CC=5 SCAR=34.0
Pod undocumented
41 0 my $self = shift;
42 0 my @plugins;
43 0 ▶ if(ref $_[0] eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
44 0 @plugins = @{$_[0]};
45 0 shift;
46 }
47 else{
48 0 push @plugins,$_[0];
49 0 shift;
50 }
51  
52 0 for(@plugins){
53 0 ▶ if(exists $self->{plugins}{$_}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'plugins'}{$_}) { } 0 0 0
54 0 eval {
55 0 &{$self->{plugins}{$_}{code}}($self,@_);
56 };
57 0 ▶ print $@,"\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
58 }
59 else{
60 0 die "运行插件[ $_ ]失败:找不到该插件\n";
61 }
62 }
63 }
64  
65 0 ▶sub plugin{
Subroutine plugin: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my $self = shift;
67 0 my $plugin = shift;
68 0 ▶ if(exists $self->{plugins}{$plugin}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'plugins'}{$plugin}) { } 0 0 0
69 0 return $self->{plugins}{$plugin}{code};
70 }
71 else{
72 0 die "查找插件[ $_ ]失败:找不到该插件\n";
73 }
74 }
75  
76 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my $self = shift;
78 0 $self->{plugins} = [];
79 }
80 1 1;
« Webqq/Client/Util.pm ↑ Summary Webqq/Client/Plugin/SmartReply2.pm »