develooper Front page | perl.perl5.porters | Postings from March 2007

Re: AutoLoader inheritance patch

Thread Previous
From:
Graham Barr
Date:
March 18, 2007 07:47
Subject:
Re: AutoLoader inheritance patch
Message ID:
44071069-7162-47F0-B06E-2528BD3A9AD6@pobox.com
On Mar 17, 2007, at 10:09 AM, Rafael Garcia-Suarez wrote:
> On 17/03/07, Steffen Mueller <o6hhmk002@sneakemail.com> wrote:
>> I created a patch (including tests!) to make AutoLoader work with
>> class inheritance: so now you can have a base class and a derived
>> class that both use AutoLoader for some of their methods, and calling
>> an auto-loadable method in the base class on an object which isa
>> derived class will no longer result in an error, but the base  
>> class'es
>> method will be loaded and executed. The can() should now work as well
>> correctly.
>
> I haven't really the energy to re-read the patch right now, but the
> question that pops up into my mind is -- does this goes against
> documented behaviour and/or a core regression test ?

I am not sure what the patch is "fixing" AutoLoader already supports  
base and derived classes having autoloaded methods

Create the three files below, running Makefile.PL outputs

perl Makefile.PL
Writing Makefile for Foo
cp lib/Foo.pm blib/lib/Foo.pm
AutoSplitting blib/lib/Foo.pm (blib/lib/auto/Foo)
cp lib/Bar.pm blib/lib/Bar.pm
AutoSplitting blib/lib/Bar.pm (blib/lib/auto/Bar)
Bar
2
1


->can works too because autosplit creates stubs for the methods in  
the classes.

Graham.



lib/Bar.pm:

package Bar;

use base qw(Foo);

use AutoLoader qw(AUTOLOAD);

sub new {
   my $class = shift;
   bless {}, $class;
}

1;

__END__

sub pkg { return __PACKAGE__ }

sub bar { 1 }




lib/Foo.pm:

package Foo;

use AutoLoader qw(AUTOLOAD);

sub new {
   my $class = shift;
   bless {}, $class;
}

1;

__END__

sub pkg { return __PACKAGE__ }

sub foo { 2 }





Makefile.PL:

use ExtUtils::MakeMaker;
WriteMakefile(
   VERSION => '1.1',
   NAME => "Foo",
);
system('make');
use blib;
use Bar;
$x = Bar->new;

print $x->pkg,"\n";
print $x->foo,"\n";
print $x->bar,"\n";





Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About