Skip Menu |

This queue is for tickets about the Class-Autouse CPAN distribution.

Report information
The Basics
Id: 13638
Status: open
Worked: 35 min
Priority: 0/
Queue: Class-Autouse

People
Owner: adamk [...] cpan.org
Requestors: Marek.Rouchal [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.17
Fixed in: (no value)



Subject: interaction with fields and base
When you have use Class::Autouse qw(Apack Bpack); and these two classes "use fields" and in Bpack there is interitance: use base qw(Apack); then you run into a problem since Apack is not loaded by the "use base" and therefore Bpack misses the fields of Apack. Unpack the attaches tgz to /tmp and run "ttt" - it works because of this hack which might become part of Class::Autouse: BEGIN { *base::require = sub ($) { my $mod = shift; warn "base::require: $mod"; $mod =~ s/\.pmc?$//; $mod =~ s,/,::,g; Class::Autouse->load($mod); }; } We hijack the "require" in "base" - in principle a clean thing, but unfortunately the "require Apack" becomes a "Apack.pm" argument in the sub, so we need to revert the file name to a class name; don't know who translates the bareword into the string, and how. What do you think? Offer that on demand with e.g. use Class::Autouse qw(:base); ??? Cheers, Marek
Download CA.tgz
application/x-gzip-compressed 831b

Message body not shown because it is not plain text.

[MAREKR - Mon Jul 11 08:20:58 2005]: Show quoted text
> When you have > use Class::Autouse qw(Apack Bpack); > and these two classes "use fields" and in Bpack there is interitance: > use base qw(Apack); > then you run into a problem since Apack is not loaded by the "use > base" > and therefore Bpack misses the fields of Apack. > > Unpack the attaches tgz to /tmp and run "ttt" - it works because of > this hack which might become part of Class::Autouse: > > BEGIN { > *base::require = sub ($) { > my $mod = shift; > warn "base::require: $mod"; > $mod =~ s/\.pmc?$//; > $mod =~ s,/,::,g; > Class::Autouse->load($mod); > }; > } > > We hijack the "require" in "base" - in principle a clean thing, but > unfortunately the "require Apack" becomes a "Apack.pm" argument in the > sub, so we need to revert the file name to a class name; don't know > who > translates the bareword into the string, and how. > > What do you think? Offer that on demand with e.g. > use Class::Autouse qw(:base); > ??? > > Cheers, > > Marek
Decided to leave it for another month to ponder. I'm leaning towards making sure base it loaded and hooking it immediately. Doing this may actually mean I improve another part of the algorithm, but I need to be careful about changing it.
From: marekr [...] cpan.org
[ADAMK - Tue Jul 26 04:28:23 2005]: Show quoted text
> Decided to leave it for another month to ponder. I'm leaning towards > making sure base it loaded and hooking it immediately.
Hmmm... this could be difficult: The application is always: use base qw(...); and not use base; ... use Class::Autouse; ... base->import(...); In other words: I am not sure how you want to trap the "use base ..." from Class::Autouse (other than my proposal). Hmmm... you could of course do "use base" in C::A and hijack &base::import with an own implementation, but that would require always a follow-up release of C::A whenever there is a new "base". Anyway, I am sure you will find an appropriate solution. Let me know if you would like to reflect any thoughts. Show quoted text
> Doing this may actually mean I improve another part of the algorithm, > but I need to be careful about changing it.
Of course. Take your time, and make it safe. Cheers, Marek
Tried to have another shot at your problem, but the tarball attached was corrupt and I could not extract it. As a starting point, I've added 05_base.t to try and catch the case. While not testing fields, I did validate that the normal base cases work just fine (although looking at the way it runs internally it's a little suboptimal and mainly a fluke that it works). If you could either a) Resend the file b) Provide a patch against the test script, I'll have another look. Leaving the fluke as is until I absolutely have to hook base.pm. BTW, the problem with Class::Autouse loading after base won't be a problem I think.
On Fri Jan 13 01:06:24 2006, ADAMK wrote: Show quoted text
> If you could either a) Resend the file b) Provide a patch against the > test script, I'll have another look.
I cannot recover the file, but I attach a diff against C::A 1.24 that shows the error in 05_base.t - in fact, there is no problem with "base" itself (as long as you are only concerned about inheritance of subs), but rather with base and fields; an auto-used class that has fields won't show those to derived classes (as of now). See my initial posting for a possible solution by putting a custom "require" sub in base.pm to force the loading of the base class. Hope this helps (and the attachment works this time), Marek
diff -ruN Class-Autouse-1.24/t/05_base.t Class-Autouse-1.24p1/t/05_base.t --- Class-Autouse-1.24/t/05_base.t 2006-01-13 07:30:10.000000000 +0100 +++ Class-Autouse-1.24p1/t/05_base.t 2006-01-16 13:52:22.539678000 +0100 @@ -16,7 +16,7 @@ } } -use Test::More tests => 4; +use Test::More tests => 5; use Class::Autouse (); @@ -36,7 +36,12 @@ ##################################################################### # Autoloading BOTH of them may fail (nope...) +# uncomment the following line to make the test pass +# require baseD; + use_ok( 'Class::Autouse' => 'baseC', 'baseD' ); is( baseD->dummy, 3, 'Calling method in baseD interacts with baseC correctly' ); +is( baseD->new->getC1, undef, 'Accessing fields of base class' ); + 1; diff -ruN Class-Autouse-1.24/t/modules/baseC.pm Class-Autouse-1.24p1/t/modules/baseC.pm --- Class-Autouse-1.24/t/modules/baseC.pm 2006-01-13 07:30:10.000000000 +0100 +++ Class-Autouse-1.24p1/t/modules/baseC.pm 2006-01-16 13:47:11.938775000 +0100 @@ -1,5 +1,7 @@ package baseC; +use fields qw(C1 C2); + sub dummy { 3 }; 1; diff -ruN Class-Autouse-1.24/t/modules/baseD.pm Class-Autouse-1.24p1/t/modules/baseD.pm --- Class-Autouse-1.24/t/modules/baseD.pm 2006-01-13 07:30:10.000000000 +0100 +++ Class-Autouse-1.24p1/t/modules/baseD.pm 2006-01-16 13:43:44.698114000 +0100 @@ -2,4 +2,16 @@ use base 'baseC'; +use fields qw(D1 D2); + +sub new +{ + return fields::new(shift); +} + +sub getC1 +{ + shift->{C1}; +} + 1;