在Perl中,如何检查从哪个模块导入了给定的函数? [英] In Perl, how can I check from which module a given function was imported?

查看:77
本文介绍了在Perl中,如何检查从哪个模块导入了给定的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用函数的代码。但我不知道这个功能属于哪个模块。我需要它来修改这个函数。



我该如何检查它?

解决方案

Devel :: Peek 模块非常方便获取有关变量的各种信息。你可以用它做的一件事就是转储一个子例程的引用并获取它来自的glob的名称:

  $ perl -MDevel :: Peek -MList :: Util = first -e'Dump(\& first)'
SV = IV(0x1094e20)在0x1094e28
REFCNT = 1
FLAGS =(TEMP,ROK)
RV = 0x11183b0
0x11183b0
REFCNT = 3
FLAGS =(POK,pPOK)
PROTOTYPE = & @
COMP_STASH = 0x0
XSUB = 0x7f7ecbdc61b0
XSUBANY = 0
GVGV :: GV = 0x11183c8List :: Util::first
FILE =ListUtil.c
DEPTH = 0
FLAGS = 0x800
OUTSIDE_SEQ = 0
PADLIST = 0x0
OUTSIDE = 0x0(空)

GVGV :: GV 。

另一种解决方案是 Sub :: Identify ,它实际上只给出你手上代码引用的名字到它。然而,知道 Devel :: Peek 在许多其他情况下也很方便,所以我首先提到了它。


I have a code which calls the function. But I don't know the module this function belongs to. I need it to modify this function.

How can I check it?

解决方案

The Devel::Peek module is very handy to get all sorts of information about variables. One of the things you can do with it is dump a reference to a subroutine and get the name of the glob it came from:

$  perl -MDevel::Peek -MList::Util=first -e'Dump(\&first)'
SV = IV(0x1094e20) at 0x1094e28
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x11183b0
  SV = PVCV(0x10ff1f0) at 0x11183b0
    REFCNT = 3
    FLAGS = (POK,pPOK)
    PROTOTYPE = "&@"
    COMP_STASH = 0x0
    XSUB = 0x7f7ecbdc61b0
    XSUBANY = 0
    GVGV::GV = 0x11183c8        "List::Util" :: "first"
    FILE = "ListUtil.c"
    DEPTH = 0
    FLAGS = 0x800
    OUTSIDE_SEQ = 0
    PADLIST = 0x0
    OUTSIDE = 0x0 (null)

the GVGV::GV part in there is the important bit.

An alternative solution would be Sub::Identify, which really only gives you names for code references you hand to it. However, knowing about Devel::Peek is handy in many other situations too, so I mentioned that first.

这篇关于在Perl中,如何检查从哪个模块导入了给定的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆