Front page | perl.perl5.porters |
Postings from April 2007
Re: use parent 'Some::Class' @import_list;
Thread Previous
|
Thread Next
From:
Brandon Black
Date:
April 29, 2007 17:17
Subject:
Re: use parent 'Some::Class' @import_list;
Message ID:
84621a60704291716w999f325u150f6eced187970c@mail.gmail.com
On 4/29/07, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> On 4/29/07, Ovid <publiustemp-p5p3@yahoo.com> wrote:
>
> So:
>
> use parent qw( a b );
>
> would be exactly equivalent to:
>
> use base qw( a );
> BEGIN { a->import('b') }
>
> ?
>
> FWIW `parent' as opposed to `base' doesn't make me think "ah, this'll
> call import too" as much as it makes me wonder what (if any) is the
> difference between a base and a parent package.
>
I'm also looking at base.pm right now for a different reason, but it
impacts this as well. I suspect (a few more patches in the future)
that bleadperl will be much more efficient when doing:
@Foo::ISA = qw/ some long list of things /;
than when doing:
push(@Foo::ISA, 'some');
push(@Foo::ISA, 'long');
push(@Foo::ISA, 'list');
....
because of @ISA linearization caching issues and delayed setisa magic
in aassign. To that end, I'm going to see if I can modify base.pm to
play nicer without breaking things. If your "use parent" interface
only allows specifying one base-class per statement, such an
optimization won't be possible.
use base has other subtle (sometimes undocumented) interesting
side-effects, like the fact that it refuses to add a baseclass to @ISA
which the class already ->isa (through deep inheritance possible). I
suspect this was a performance hack, but the mro linearization
functions in blead eliminate this redundancy internally anyways. I'd
like to change the import loop of base.pm to be more like:
foreach my $newbase (@newbases) {
# "require if necessary" magic, which croaks if require fails
}
@Class::ISA = (@Class::ISA, @newbases);
instead of the current loop which is more like:
foreach my $newbase (@newbases) {
next if Class->isa($newbase);
# "require if necessary" magic, which croaks if require fails
push(@Class::ISA, $newbase);
}
What about modifying base.pm syntax in a backwards-compat way, to work
like this:
use base qw/A B C/; # just like before
use base ('A' => \@import_list, 'B', 'C' => \@import_list, 'D', 'E',
'F' => []); # calls import on A, C, and F (empty import list in the
case of F)
By having it look at ref($foo) on the args as it goes to tell what's
what. Of course, when combining that idea with the changes I'm
proposing earlier in this email, there's some definite questions about
when imports should be called (just after the "require if necessary",
which is before the package is actually added to @ISA, or call them
all in order after the big @ISA change - I tend to vote for the
latter).
-- Brandon
Thread Previous
|
Thread Next