[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
[perl #60220] mro::method_changed_in(..) ignores AUTOLOAD
# New Ticket Created by laurent dami
# Please include the string: [perl #60220]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60220 >
This is a bug report for perl from dami@cpan.org,
generated with the help of perlbug 1.36 running under perl 5.10.0.
-----------------------------------------------------------------
When creating a subclass dynamically, and when adding
AUTOLOAD dynamically into the parent class, then that
AUTOLOAD is not seen in the method cache, even after
a call to "mro::method_changed_in('Parent')".
It only appears in the method cache after a call
to mro::invalidate_all_method_caches().
The attached test file demonstrates the problem.
This was detected while trying to solve bug 40159 in DBIx::DataModel.
-----------------------------------------------------------------
---
Flags:
category=library
severity=medium
---
Site configuration information for perl 5.10.0:
Configured by SYSTEM at Tue May 13 16:52:25 2008.
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO
-DPERL_MSVCRT_READFIX -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields',
optimize='-O2',
cppflags='-DWIN32'
ccversion='', gccversion='3.4.2 (mingw-special)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-L"D:\Perl\lib\CORE"'
libpth=\lib
libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm
-lversion -lodbc32 -lodbccp32 -lmsvcrt
perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm -lversion -lodbc32 -lodbccp32 -lmsvcrt
libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -L"D:\Perl\lib\CORE"'
Locally applied patches:
ACTIVEPERL_LOCAL_PATCHES_ENTRY
33741 avoids segfaults invoking S_raise_signal() (on Linux)
33763 Win32 process ids can have more than 16 bits
32809 Load 'loadable object' with non-default file extension
32728 64-bit fix for Time::Local
---
@INC for perl 5.10.0:
d:/Perl/site/lib
d:/Perl/lib
.
---
Environment for perl 5.10.0:
HOME=D:\dami
LANG=fr
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C:\Program Files\Fichiers
communs\GTK\2.0\bin;d:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\FRANCAIS;c:\Program
Files\Novell\ZENworks\;C:\Program Files\ATI Technologies\ATI Control
Panel;C:\Program
Files\Novell\ZENworks\;D:\ProgFiles\MinGW\bin;D:\ProgFiles\MSys\1.0\bin;C:\BASISclient\cs\bin;C:\BASISclient\www\bin;C:\Program
Files\Novell\SecureLogin;D:\ProgFiles\GTK\2.0\bin;d:\ProgFiles\TortoiseSVN\bin;D:\Progfiles\Subversion\bin;D:\ProgFiles\Berkeley_DB_4.6.21\bin;D:\ProgFiles\Berkeley_DB_4.6.21\bin\debug;Z:.;
PERL_BADLANG (unset)
SHELL=D:/ProgFiles/emacs-22.2/bin/cmdproxy.exe
# laurent.dami AT justice.ge.ch, Oct 2008
# testing Perl5.9.5 method cache, mro::method_changed_in(..)
# doesn't seem to work when dynamic subclasses + dynamic Autoload
#----------------------------------------------------------------------
package Parent;
#----------------------------------------------------------------------
sub new {
my ($class, $name) = @_;
my $self = {name => $name};
bless $self, $class;
}
sub name {
my ($self) = @_;
return $self->{name};
}
sub hello {
my ($self) = @_;
return "hello, I'm " . $self->name . " in class Parent";
}
#----------------------------------------------------------------------
package Child;
#----------------------------------------------------------------------
our @ISA = qw/Parent/;
sub hello {
my ($self) = @_;
return "hello, I'm " . $self->name . " in class Child";
}
#----------------------------------------------------------------------
package Child2;
#----------------------------------------------------------------------
our @ISA = qw/Parent/;
sub hello {
my ($self) = @_;
return "hello, I'm " . $self->name . " in class Child2";
}
#----------------------------------------------------------------------
package main;
#----------------------------------------------------------------------
use strict;
use warnings;
use Test::More tests => 11;
# dynamically create a subclass
*{GrandChild::ISA} = [qw/Child Child2/];
# instanciate
my $child = Child->new('child');
my $grandchild = GrandChild->new('grandchild');
my ($result, $expected);
isa_ok($grandchild, 'Child');
isa_ok($grandchild, 'Parent');
can_ok($grandchild, qw/name hello/);
# dynamically add a new method in Parent class
*{Parent::shout} = sub {
my ($self) = @_;
return "HELLO, I'M " . $self->name . " IN CLASS PARENT";
};
# is the new method seen ?
can_ok($grandchild, qw/shout/);
$result = eval {$grandchild->shout};
is($result, "HELLO, I'M grandchild IN CLASS PARENT", "shout method");
# dynamically add autoload
*{Parent::AUTOLOAD} = sub {
my $self = shift;
my $class = ref($self) || $self;
my $method = our $AUTOLOAD;
$method =~ s/^.*:://;
return if $method eq 'DESTROY'; # won't overload that one!
return "[$method] for " . $self->name . " in class Parent";
};
# is AUTOLOAD seen ?
$result = eval {$grandchild->bark};
$expected = "[bark] for grandchild in class Parent",
is($result, $expected, $expected);
$result = eval {$child->bark};
$expected = "[bark] for child in class Parent",
is($result, $expected, $expected);
# is it seen after a "methods_changed_in" ?
mro::method_changed_in('Parent');
diag("mro::method_changed_in('Parent')");
$result = eval {$grandchild->bark};
$expected = "[bark] for grandchild in class Parent",
is($result, $expected, $expected);
$result = eval {$child->bark};
$expected = "[bark] for child in class Parent",
is($result, $expected, $expected);
# is it seen after a "invalidate_all_method_caches" ?
mro::invalidate_all_method_caches();
diag("mro::invalidate_all_method_caches()");
$result = eval {$grandchild->bark};
$expected = "[bark] for grandchild in class Parent",
is($result, $expected, $expected);
$result = eval {$child->bark};
$expected = "[bark] for child in class Parent",
is($result, $expected, $expected);
- Follow-Ups from:
-
Tony Cook <tony@develop-help.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]