Skip Menu |

This queue is for tickets about the Object-InsideOut CPAN distribution.

Report information
The Basics
Id: 20672
Status: resolved
Priority: 0/
Queue: Object-InsideOut

People
Owner: Nobody in particular
Requestors: leandro [...] keandro.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.45
Fixed in: 1.46



Subject: Sub-class inheritance doesn't seem to work properly
Hello, It seems that sub-class inheritance in Object::InsideOut doesn't seem to work properly when compared to the "use base" pragma. A simple example: # Base Class # located in lib/DB.pm package DB; { use Object::InsideOut; my @drivers :Field('Standard' => 'driver'); } 1; # Sub Class # located in lib/My/DB.pm package My::DB; { use Object::InsideOut qw(DB); my @names :Field('Standard' => 'name'); } 1; # application code, test.pl # located just above lib directory #!/usr/bin/perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use My::DB; my $db = My::DB->new(); $db->set_driver('MySQL'); ################ Now when I run the program: [user@server ~]$ ./test.pl OIO::Method error: Can't locate object method "set_driver" via package "My::DB" Package: Object::InsideOut File: /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm Line: 153 Trace begun at /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm line 153 Object::InsideOut::__ANON__('My::DB=SCALAR(0x70bf00)', 'MySQL') called at test.pl line 11 Why doesn't this work? I think I have the reason. There happens to be another completely unrelated package of the same name DB.pm in my @INC located at /usr/lib/perl5/5.8.5/DB.pm and Object::InsideOut is for some reason using this as the parent class of My::DB. Object::InsideOut's replacement for "use base" doesn't seem to be working properly because it is not paying attention to the specific @INC order I have specified by doing "use lib" in my application code. The "use base" pragma does locate the correct DB.pm parent class at lib/DB.pm.
From: leandro [...] keandro.com
On Tue Jul 25 05:53:08 2006, lhermida wrote: Show quoted text
> Hello, > > It seems that sub-class inheritance in Object::InsideOut doesn't
seem Show quoted text
> to work properly when compared to the "use base" pragma. A simple > example: > > > # Base Class > # located in lib/DB.pm > > package DB; { > use Object::InsideOut; > > my @drivers :Field('Standard' => 'driver'); > } > > 1; > > # Sub Class > # located in lib/My/DB.pm > > package My::DB; { > use Object::InsideOut qw(DB); > > my @names :Field('Standard' => 'name'); > } > > 1; > > # application code, test.pl > # located just above lib directory > > #!/usr/bin/perl > > use strict; > use warnings; > use FindBin; > use lib "$FindBin::Bin/lib"; > use My::DB; > > my $db = My::DB->new(); > > $db->set_driver('MySQL'); > > ################ > > Now when I run the program: > > [user@server ~]$ ./test.pl > OIO::Method error: Can't locate object method "set_driver" via > package "My::DB" > Package: Object::InsideOut > File: /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm > Line: 153 > > > Trace begun > at /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm line
153 Show quoted text
> Object::InsideOut::__ANON__('My::DB=SCALAR(0x70bf00)', 'MySQL')
called Show quoted text
> at test.pl line 11 > > > Why doesn't this work? I think I have the reason. There happens to > be another completely unrelated package of the same name DB.pm in my > @INC located at /usr/lib/perl5/5.8.5/DB.pm and Object::InsideOut is > for some reason using this as the parent class of My::DB. > Object::InsideOut's replacement for "use base" doesn't seem to be > working properly because it is not paying attention to the specific > @INC order I have specified by doing "use lib" in my application > code. The "use base" pragma does locate the correct DB.pm parent > class at lib/DB.pm. > >
Sorry I forgot to mention that the way I found out that Object::InsideOut wasn't searching the @INC correctly to get the right parent class when doing "use Object::InsideOut qw(DB);" in the sub- class is that I changed the name of the package and file name from DB to BaseDB and then everything worked fine (because there is no other BaseDB.pm in my @INC).
From: leandro.hermida [...] fmi.ch
On Tue Jul 25 05:53:08 2006, lhermida wrote: Show quoted text
> Hello, > > It seems that sub-class inheritance in Object::InsideOut doesn't
seem Show quoted text
> to work properly when compared to the "use base" pragma. A simple > example: > > > # Base Class > # located in lib/DB.pm > > package DB; { > use Object::InsideOut; > > my @drivers :Field('Standard' => 'driver'); > } > > 1; > > # Sub Class > # located in lib/My/DB.pm > > package My::DB; { > use Object::InsideOut qw(DB); > > my @names :Field('Standard' => 'name'); > } > > 1; > > # application code, test.pl > # located just above lib directory > > #!/usr/bin/perl > > use strict; > use warnings; > use FindBin; > use lib "$FindBin::Bin/lib"; > use My::DB; > > my $db = My::DB->new(); > > $db->set_driver('MySQL'); > > ################ > > Now when I run the program: > > [user@server ~]$ ./test.pl > OIO::Method error: Can't locate object method "set_driver" via > package "My::DB" > Package: Object::InsideOut > File: /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm > Line: 153 > > > Trace begun > at /usr/lib/perl5/site_perl/5.8.5/Object/InsideOut/Autoload.pm line
153 Show quoted text
> Object::InsideOut::__ANON__('My::DB=SCALAR(0x70bf00)', 'MySQL')
called Show quoted text
> at test.pl line 11 > > > Why doesn't this work? I think I have the reason. There happens to > be another completely unrelated package of the same name DB.pm in my > @INC located at /usr/lib/perl5/5.8.5/DB.pm and Object::InsideOut is > for some reason using this as the parent class of My::DB. > Object::InsideOut's replacement for "use base" doesn't seem to be > working properly because it is not paying attention to the specific > @INC order I have specified by doing "use lib" in my application > code. The "use base" pragma does locate the correct DB.pm parent > class at lib/DB.pm. > >
Sorry I forgot to mention that the way I found out that Object::InsideOut wasn't searching the @INC correctly to get the right parent class when doing "use Object::InsideOut qw(DB);" in the sub- class is that I changed the name of the package and file name from DB to BaseDB and then everything worked fine (because there is no other BaseDB.pm in my @INC).
Show quoted text
> package My::DB; { > use Object::InsideOut qw(DB); > > my @names :Field('Standard' => 'name'); > } > > 1;
It seems that Devel::StackTrack (used by Exception::Class) makes use of the DB namespace. As a consequence, Object::InsideOut thinks that package DB is already loaded. Therefore, if you create a class called DB that is sub-classed by other packages, you may need to 'require' it as follows: package DB::Sub; { require DB; use Object::InsideOut qw(DB); ... } I will document this under 'BUGS AND LIMITATIONS' in the next release.