new_perl
new_perl

Reputation: 7735

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 expecting to see Term::ReadLine::new, which is generally the case when I new a package.

Anyone knows the reason?

Upvotes: 2

Views: 274

Answers (1)

DavidO
DavidO

Reputation: 13942

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).

Upvotes: 3

Related Questions