Perl / perl5

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

autouse broken with subs named like AA::BB::func #4082

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

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

Searchable as RT7115$

p5pRT commented 23 years ago

From @bikeNomad

'use autouse' (Perl 5.6.1) works like this​:

  use autouse AA => 'AA​::new';

but not like this​:

  use autouse AA​::BB => 'AA​::BB​::new';

I get a complaint saying​:

  autouse into different package attempted at autouse.pl line 5

This appears to be because of the line in autouse.pm that gets the index of the '​::' in the function name.

My proposed fix for this problem changes the index() call into a rindex() call​:

Inline Patch ```diff --- /usr/lib/perl5/5.6.1/autouse.pm Wed Apr 18 15:20:46 2001 +++ autouse.pm Thu Jun 14 12:47:53 2001 @@ -35,15 +35,15 @@ my $index; for my $f (@_) { my $proto; $proto = $1 if (my $func = $f) =~ s/\((.*)\)$//; my $closure_import_func = $func; # Full name my $closure_func = $func; # Name inside package ```

- my $index = index($func\, '​::'); + my $index = rindex($func\, '​::');   if ($index == -1) {   $closure_import_func = "${callpkg}​::$func";   } else {   $closure_func = substr $func\, $index + 2;   croak "autouse into different package attempted"   unless substr($func\, 0\, $index) eq $module;   }

Perl Info ``` Flags: category=library severity=low This perlbug was built using Perl v5.6.0 - Thu May 11 14:03:42 PDT 2000 It is being executed now by Perl v5.6.1 - Wed May 23 22:45:21 PDT 2001. Site configuration information for perl v5.6.1: Configured by ned at Wed May 23 22:45:21 PDT 2001. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=linux, osvers=2.4.4smp, archname=i686-linux uname='linux ned.bike-nomad.com 2.4.4smp #1 smp fri may 4 14:00:39 pdt 2001 i686 unknown ' config_args='-Dprefix=/usr -de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 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 -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.2.so, 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 v5.6.1: /usr/lib/perl5/5.6.1/i686-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i686-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl/5.005 /usr/lib/perl5/site_perl . Environment for perl v5.6.1: HOME=/home/ned LANG=en_US LANGUAGE (unset) LD_LIBRARY_PATH=/lib:/usr/lib LOGDIR (unset) PATH=/home/ned/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/IBMJava2-13/bin:/opt/introl/i386-linux/bin PERLDB_OPTS=ornaments=0 PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 23 years ago

From @schwern

Already been fixed. :) Next version of perl will have it.