加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl获取每个对象的函数

发布时间:2020-12-16 06:18:03 所属栏目:大数据 来源:网络整理
导读:我是Perl的新手,所以我不知道它是否可行. 我有兴趣创建一个可以捕获所有调用的模块. 它的用法如下: $object = new Foo;$object-blah; 函数名称(所以在这种情况下“blah”会被Foo咳嗽并作为字符串返回到屏幕). 我不知道怎么做的是将被调用的函数名称作为字符
我是Perl的新手,所以我不知道它是否可行.
我有兴趣创建一个可以捕获所有调用的模块.

它的用法如下:

$object = new Foo;
$object->blah;

函数名称(所以在这种情况下“blah”会被Foo咳嗽并作为字符串返回到屏幕).

我不知道怎么做的是将被调用的函数名称作为字符串.

解决方法

您可能想要检查 AUTOLOADING

If you call a subroutine that is undefined,you would ordinarily get an immediate,fatal error complaining that the subroutine doesn’t exist. (Likewise for subroutines being used as methods,when the method doesn’t exist in any base class of the class’s package.) However,if an AUTOLOAD subroutine is defined in the package or packages used to locate the original subroutine,then that AUTOLOAD subroutine is called with the arguments that would have been passed to the original subroutine

my $object = new Foo;
print $object->blah,"n";

package Foo;
sub new { return bless {},shift }

# catch-all function
sub AUTOLOAD {
  return $AUTOLOAD;

}

输出Foo :: blah

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读