开发者

Why perl debugger shows Term::ReadLine::Stub::new when new Term::ReadLine is called?

Term::ReadLine::Stub::new(/usr/lib/perl5/5.8.8/Term/ReadLine.pm:243):

I was 开发者_如何学Cexpecting to see Term::ReadLine::new, which is generally the case when I new a package.

Anyone knows the reason?


It's inheritance. Term::Readline starts out with package Term::ReadLine::Stub at the top, and then later within package Term::ReadLine you will see the following:

our @ISA;
if (defined &Term::ReadLine::Gnu::readline) {
  @ISA = qw(Term::ReadLine::Gnu Term::ReadLine::Stub);
} elsif (defined &Term::ReadLine::Perl::readline) {
  @ISA = qw(Term::ReadLine::Perl Term::ReadLine::Stub);
} elsif (defined $which && defined &{"Term::ReadLine::$which\::readline"}) {
  @ISA = "Term::ReadLine::$which";
} else {
  @ISA = qw(Term::ReadLine::Stub);
}

sub new() is created within Term::ReadLine::Stub and inherited into Term::ReadLine.

The debugger is most helpful if it actually tells you where a sub is being inherited from (as it does). It would not be so helpful if you were directed by the debugger to Term::ReadLine, and then you had to wade through all the @ISA levels until you found one that defined new(). Imagine that quagmire in an object system that allows for multi-tier inheritance (as Perl does), and multiple inheritance (as Perl does).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜