line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Webqq::Plugin; |
2
|
|
|
|
|
|
|
sub load { |
3
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
4
|
0
|
|
|
|
|
|
my @module_name; |
5
|
|
|
|
|
|
|
my %opt; |
6
|
0
|
0
|
|
|
|
|
if(ref $_[0] eq "ARRAY"){ |
7
|
0
|
|
|
|
|
|
@module_name = @{shift @_}; |
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
else{ |
10
|
0
|
|
|
|
|
|
push @module_name,shift; |
11
|
|
|
|
|
|
|
} |
12
|
0
|
|
|
|
|
|
%opt= @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
for my $module_name (@module_name){ |
15
|
0
|
|
|
|
|
|
my $module_function = undef; |
16
|
0
|
|
|
|
|
|
my $module; |
17
|
0
|
0
|
|
|
|
|
if(substr($module_name,0,1) eq '+'){ |
18
|
0
|
|
|
|
|
|
substr($module_name,0,1) = ""; |
19
|
0
|
|
|
|
|
|
$module = $module_name; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else{ |
22
|
0
|
|
|
|
|
|
$module = "Mojo::Webqq::Plugin::" . $module_name; |
23
|
|
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
|
eval "require $module"; |
25
|
0
|
0
|
|
|
|
|
$self->die("加载插件[ $module ]失败: $@\n") if $@; |
26
|
0
|
|
|
|
|
|
$module_function = *{"${module}::call"}{CODE}; |
|
0
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
$self->die("加载插件[ $module ]失败: 未获取到call函数引用\n") if ref $module_function ne 'CODE'; |
28
|
0
|
|
|
|
|
|
$self->debug("加载插件[ $module ]"); |
29
|
0
|
|
|
|
|
|
$self->plugins->{$module}{code} = $module_function; |
30
|
0
|
|
|
|
|
|
$self->plugins->{$module}{name} = $module; |
31
|
0
|
|
|
|
|
|
$self->plugins->{$module}{data} = $opt{data}; |
32
|
0
|
|
0
|
|
|
|
$self->plugins->{$module}{priority} = $opt{priority} || eval "\$${module}::PRIORITY" || 0; |
33
|
0
|
|
0
|
|
|
|
$self->plugins->{$module}{call_on_load} = $opt{call_on_load} || eval "\$${module}::CALL_ON_LOAD" || 0; |
34
|
0
|
0
|
|
|
|
|
if($self->plugins->{$module}{call_on_load}){ |
35
|
0
|
|
|
|
|
|
$self->emit("plugin_load",$module); |
36
|
0
|
|
|
|
|
|
$self->call($module); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else{ |
39
|
0
|
|
0
|
|
|
|
$self->plugins->{$module}{auto_call} = $opt{auto_call} || eval "\$${module}::AUTO_CALL" || 1 ; |
40
|
0
|
|
|
|
|
|
$self->emit("plugin_load",$module); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub call{ |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my @plugins; |
49
|
0
|
0
|
|
|
|
|
if(ref $_[0] eq 'ARRAY'){ |
50
|
0
|
|
|
|
|
|
@plugins = @{$_[0]}; |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
shift; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else{ |
54
|
0
|
|
|
|
|
|
push @plugins,$_[0]; |
55
|
0
|
|
|
|
|
|
shift; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
for(sort {$self->plugins->{$b}{priority} <=> $self->plugins->{$a}{priority}} @plugins){ |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if(exists $self->plugins->{$_}){ |
59
|
0
|
|
|
|
|
|
$self->info("执行插件[ $_ ]"); |
60
|
0
|
|
|
|
|
|
eval { |
61
|
0
|
|
|
|
|
|
&{$self->plugins->{$_}{code}}($self,$self->plugins->{$_}{data},@_); |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
}; |
63
|
0
|
0
|
|
|
|
|
if($@){ |
64
|
0
|
|
|
|
|
|
$self->error("插件[ $_ ]执行错误: $@"); |
65
|
0
|
0
|
|
|
|
|
if($@ =~ /Can't create listen socket: Address already in use/){ |
66
|
0
|
|
|
|
|
|
$self->stop(); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
next; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$self->emit("plugin_call",$_); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else{ |
73
|
0
|
|
|
|
|
|
$self->error("运行插件[ $_ ]失败:找不到该插件"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
return $self; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |