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

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

Thread Previous | Thread Next
April 29, 2007 17:44
Re: use parent 'Some::Class' @import_list;
Message ID:
Hash: SHA1


On Monday 30 April 2007 00:16:46 Brandon Black wrote:
> On 4/29/07, Ævar Arnfjörð Bjarmason <> wrote:
> > On 4/29/07, Ovid <> 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 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 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 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 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 "", compared to the 

	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,


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

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

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


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About