aboutsummaryrefslogtreecommitdiffstats
path: root/core/plugin.rb
diff options
context:
space:
mode:
authortoshi <toshi@03aab468-d3d2-4883-8b12-f661bbf03fa8>2012-06-13 16:16:39 +0000
committertoshi <toshi@03aab468-d3d2-4883-8b12-f661bbf03fa8>2012-06-13 16:16:39 +0000
commit64971c172104f9938cf680df7f16c8feb571a109 (patch)
tree2974e643ba0393a7c574a4500880da17cf550543 /core/plugin.rb
parentc736966bee2f1ac5f1315a48fe8153481df7f247 (diff)
downloadmikutter-64971c172104f9938cf680df7f16c8feb571a109.tar.gz
Delayerの処理中にで捕捉されない例外が発生した場合、into_debug_modeメソッドが呼ばれない closes #473
git-svn-id: svn://toshia.dip.jp/mikutter/trunk@802 03aab468-d3d2-4883-8b12-f661bbf03fa8
Diffstat (limited to 'core/plugin.rb')
-rw-r--r--core/plugin.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/core/plugin.rb b/core/plugin.rb
index e2158282..fa24ece7 100644
--- a/core/plugin.rb
+++ b/core/plugin.rb
@@ -211,15 +211,34 @@ class Plugin
proc.call end
}
+ def event_wrap(&callback)
+ lambda{ |*args|
+ begin
+ callback.call(*args, &@plugin_exit)
+ rescue Exception => e
+ into_debug_mode(e, binding)
+ raise e end } end
+
+ def filter_wrap(&callback)
+ lambda{ |*args|
+ begin
+ callback.call(*args, &@filter_exit)
+ rescue Exception => e
+ into_debug_mode(e, binding)
+ raise e end } end
+
def self.gen_event_ring
Hash.new{ |hash, key| hash[key] = [] }
end
@@event = gen_event_ring # { event_name => [[plugintag, proc]] }
@@add_event_hook = gen_event_ring
@@event_filter = gen_event_ring
+ @plugin_exit = lambda{ throw(:plugin_exit) }
+ @filter_exit = lambda{ |result| throw(:filter_exit, result) }
# イベントリスナーを追加する。
def add_event(event_name, tag, &callback)
+ callback = event_wrap(&callback)
@@event[event_name.to_sym] << [tag, callback]
call_add_event_hook(event_name, callback)
callback end
@@ -228,6 +247,7 @@ class Plugin
# フィルタは、イベントリスナーと同じ引数で呼ばれるし、引数の数と同じ数の値を
# 返さなければいけない。
def add_event_filter(event_name, tag, &callback)
+ callback = filter_wrap(&callback)
@@event_filter[event_name.to_sym] << [tag, callback]
callback end
@@ -271,7 +291,7 @@ class Plugin
result = store
plugintag, proc = *plugin
boot_plugin(plugintag, event_name, :filter, false){
- result = proc.call(*store){ |result| throw(:filter_exit, result) }
+ result = proc.call(*store)
if length != result.size
raise "filter changes arguments length (#{length} to #{result.size})" end
result } } } end
@@ -293,7 +313,7 @@ class Plugin
plugin_loop(ary, event_name, kind){ |tag, proc|
if Mopt.debug
r_start = Process.times.utime
- result = proc.call(*args){ throw(:plugin_exit) }
+ result = proc.call(*args)
if (r_end = Process.times.utime - r_start) > 0.1
Plugin.call(:processtime, :plugin, "#{"%.2f" % r_end},#{tag.name},#{event_name},#{kind}") end
result