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

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

Thread Previous | Thread Next
Brandon Black
April 29, 2007 18:12
Re: use parent 'Some::Class' @import_list;
Message ID:
On 4/29/07, Tels <> wrote:
> 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.

Well, the arguments against MI are all good ones, but the fact remains
that there are lots of people out there doing MI, and lots of software
out there written in MI fashion, and perl supports MI, so it should
support it as well as it can.  There are some big packages out there
that currently use MI, like DBIx::Class and Catalyst.

In any case, even in the case of "use base qw/Exporter Dynaloader
Foo/", the efficiency improvements I'm talking about will be real, and
will add up over the course of the tons of packages a complex piece of
software uses.

> Most importantly, what is the overhead of loading "", 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?

Personally, I think most people are better off without "use base".
For MI, it's just:

use Foo;
require Bar;
our @ISA = qw/Foo Bar/;

You can choose require vs use to decide whether you want import called
or not, and since it is assignment rather than pushes, it's not an
efficiency issue like the individual push statements of

However, "use base qw/Foo Bar/" has become a somewhat standard
shorthand idiom to replace the above, even though it doesn't at all
mean the same thing, and has nowhere near the same flexibility.  I
really don't know if it's possible to retrofit the "assign it all once
at the end" thing onto without breaking other packages'
assumptions anyways, but I'm going to see if it's possible.

-- Brandon

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