想为一些外来的perl模块写一个简单的包装器.简化示例:
use 5.014; use warnings; #foreign package package Some { sub func { my($x,$y) = @_; return $x.$y; } }; #my own packages package My { #use Some (); sub func { Some::func(@_); } } package main { #use My; say My::func("res","ult"); }
这工作正常并打印result
.
但现在我遇到了一个使用原型的模块,例如上面的内容如下:
package Some { sub func($$) { # <-- prototype check my($x,$y) = @_; return $x.$y; } };
当试图使用My
包装器包时 - 它说:
Not enough arguments for Some::func at ppp line 16, near "@_)"
可能在原型检查中"作弊",或者我必须写我的包装器吗?
sub func { Some::func($_[0],$_[1]); }
甚至
sub func($$) { Some::func($_[0],$_[1]); }
ikegami.. 7
&Some::func(@_); # Bypass prototype check.
还有其他选择.
(\&Some::func)->(@_); # Call via a reference. &Some::func; # Don't create a new @_. goto &Some::func; # Don't create a new @_, and remove current call frame from stack.
方法调用总是忽略原型.
&Some::func(@_); # Bypass prototype check.
还有其他选择.
(\&Some::func)->(@_); # Call via a reference. &Some::func; # Don't create a new @_. goto &Some::func; # Don't create a new @_, and remove current call frame from stack.
方法调用总是忽略原型.