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

Re: use parent 'Some::Class' @import_list;

Thread Previous | Thread Next
From:
Tels
Date:
April 29, 2007 17:44
Subject:
Re: use parent 'Some::Class' @import_list;
Message ID:
200704300249.02500@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Moin,

On Monday 30 April 2007 00:16:46 Brandon Black wrote:
> 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).

While I think it's good someone is thinking about these things, I also am 
wondering how often to you have really more than one package in the use 
base qw/.../; statement.

I don't think I ever used more than use base qw/A B C/ which is mostly for 
Exporter and Dynaloader and some extra package.

Is more than a few really common?

Most importantly, what is the overhead of loading "base.pm", compared to the 
normal 

	use Foo;
	@ISA = qw/Foo/; 

way? If you don't use the extra features present in base (fields, etc.), 
would there still be a reason to prefer it over the "manual" way?

All the best,

Tels


- -- 
 Signed on Mon Apr 30 02:43:19 2007 with key 0x93B84C15.
 Get one of my photo posters: http://bloodgate.com/posters
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Those are my principles, and if you don't like them... well, I have
 others."

  -- Groucho Marx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iQEVAwUBRjVZHncLPEOTuEwVAQI4awf+PMj7qVG6ICbzta8UOkUqPINEwulHCaes
TF1woWncvaJUADleICFGB2vxSusp/v5mTvIiuctJUdThot6nLNCxzieJUQpWMO7x
qTn7juTQLDSNM+8x+KVbT3+4XXUG6rbExiW1QO+zyjJ1GCQQvY/tpFIRSV+mzE1y
Rdb1Ukol/hoJD7xZSo/fYMME17vAnucGMC+BSiPYeQ6qCDH5clZjiaLtMu3exKa/
cHC16VcI1vNEx3beDTkOfVrRnTmeGB48Jz3lyh2R089dUB//17wK1nZj6xYd4aIW
FHWgbJ0GPnU2bz72ZPco3L2AV9oqK25DuAa4X5eMVEKNy2w9WIE4dA==
=FY65
-----END PGP SIGNATURE-----

Thread Previous | Thread Next


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