试了下Perl Dancer,一个类Sinatra框架。感觉太刻意去模仿Ruby,反而失去了Perl自己的东西。上手很简单,几分钟就可以写好一个module,用来写webservice非常不错。用到了JSON模块的to_json函数,发现编译时会触发告警:
Prototype mismatch: sub DNSValidate::from_json: none vs ($@) at DNSValidate.pm line 4
Prototype mismatch: sub DNSValidate::to_json: none vs ($@) at DNSValidate.pm line 4
Google了一番,还是AnyEvent的作者,超级大牛Marc Lehmann给出了答案:
You are probably importing multiple from_json/to_json functions, either
because you use multiple json-like modules, or you define those functions
yourself.try: use JSON::XS ();
also with other modules (the “()”) – this will kepe these form exporting
anything.
原因是多处import了这个函数。解决方法是注释掉自己模块里的use JSON,或者改成use JSON (),后面加多一对括号,禁止从JSON里import函数,因为Dancer的其他模块里已经import了。