Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

base.pm fails to load parent modules in some situations #1171

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#2139 (status was 'resolved')

Searchable as RT2139$

p5pRT commented 24 years ago

From joey@kitenet.net

Created by joey@kitenet.net

base.pm contains this code​:

  foreach my $base (@​_) {   unless (defined %{"$base\​::"}) {
  eval "require $base";

This normally handles loading the modules of the parents that you are making a child class inherit from. However\, my class naming looks like this​:

FrontEnd FrontEnd​::Tty etc

Here FrontEnd​::Tty is a child of FrontEnd. If I just put "use base qw(FrontEnd)" in FrontEnd​::Tty\, the parent class is not properly loaded\, and things like FrontEnd​::Tty->new fail​:

perl -e 'use FrontEnd​::Tty; FrontEnd​::Tty->new' Can't locate object method "new" via package "FrontEnd​::Tty" at -e line 1.

I think it's failing like this because the code quoted earlier tries to be too smart\, and tests to see if FrontEnd is defined in perl's namespace. But it is already defined\, since "package FrontEnd​::Tty" has been run. So the require line is skipped\, and things go south.

Perl Info ``` Site configuration information for perl 5.00503: Configured by randolph at Sat Jan 22 10:22:49 MST 2000. Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=linux, osvers=2.3.39, archname=i386-linux uname='linux samwise.tausq.org 2.3.39 #1 smp wed jan 12 05:59:50 mst 2000 i686 unknown ' hint=recommended, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O2 ', gccversion=2.95.2 19991109 (Debian GNU/Linux) cppflags='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include' ccflags ='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include' stdchar='char', d_stdstdio=undef, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt libc=, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl 5.00503: /usr/lib/perl5/5.005/i386-linux /usr/lib/perl5/5.005 /usr/local/lib/site_perl/i386-linux /usr/local/lib/site_perl /usr/lib/perl5 . Environment for perl 5.00503: HOME=/home/joey LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/joey/bin:~:~/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/usr/sbin:/sbin:.:/sbin:/usr/sbin:/usr/X11R6/bin:. PERL_BADLANG (unset) SHELL=/usr/bin/zsh ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

\joey@​kitenet\.net writes​:

This is a bug report for perl from joey@​kitenet.net\, generated with the help of perlbug 1.26 running under perl 5.00503.

----------------------------------------------------------------- [Please enter your report here]

base.pm contains this code​:

foreach my $base (@​_) { unless (defined %{"$base\​::"}) {
eval "require $base";

This normally handles loading the modules of the parents that you are making a child class inherit from. However\, my class naming looks like this​:

FrontEnd FrontEnd​::Tty etc

Here FrontEnd​::Tty is a child of FrontEnd. If I just put "use base qw(FrontEnd)" in FrontEnd​::Tty\, the parent class is not properly loaded\, and things like FrontEnd​::Tty->new fail​:

perl -e 'use FrontEnd​::Tty; FrontEnd​::Tty->new' Can't locate object method "new" via package "FrontEnd​::Tty" at -e line 1.

I think it's failing like this because the code quoted earlier tries to be too smart\, and tests to see if FrontEnd is defined in perl's namespace. But it is already defined\, since "package FrontEnd​::Tty" has been run. So the require line is skipped\, and things go south.

I just re-discovered this again at work today :-( The work-round is just to do the use yourself​:

package FrontEnd​::Tty; use FrontEnd; use base qw(FrontEnd);

But I would like to see it fixed too.

-- Nick Ing-Simmons

p5pRT commented 24 years ago

From @gsar

On Thu\, 17 Feb 2000 21​:15​:24 GMT\, Nick Ing-Simmons wrote​:

generated with the help of perlbug 1.26 running under perl 5.00503. [...] base.pm contains this code​:

foreach my $base (@​_) { unless (defined %{"$base\​::"}) {
eval "require $base";

This normally handles loading the modules of the parents that you are making a child class inherit from. However\, my class naming looks like this​:

FrontEnd FrontEnd​::Tty etc

Here FrontEnd​::Tty is a child of FrontEnd. If I just put "use base qw(FrontEnd)" in FrontEnd​::Tty\, the parent class is not properly loaded\, and things like FrontEnd​::Tty->new fail​: [...] I just re-discovered this again at work today :-( The work-round is just to do the use yourself​:

package FrontEnd​::Tty; use FrontEnd; use base qw(FrontEnd);

But I would like to see it fixed too.

This should be fixed in the development versions.

Sarathy gsar@​ActiveState.com