[Dbix-class] DBIx::Class::Loader::Generic 0.20 ISA composition problem

Brandon Black blblack at gmail.com
Fri Feb 24 21:02:01 CET 2006


On 2/24/06, Vsevolod (Simon) Ilyushchenko <simonf at cshl.edu> wrote:
> Hi,
>
> In DBIx::Class::Loader::Generic::_load_classes the parameters
> additional_base_classes and left_base_clases are treated equally:
>          $_->require for @{$self->{_additional_base}};
>          $self->inject_base( $class, $_) for @{$self->{_additional_base}};
>          $_->require for @{$self->{_left_base}};
>          $self->inject_base( $class, $_) for @{$self->{_left_base}};
>
> Since I actually care about the order, it broke something in my code.
> Version 0.09 that I still use on the production machine deals with this
> differently.
>
> I'm not sending a patch, as I'm not sure which way the author will want
> to go, but it's definitely a bug.
>

I'm sure it is [a bug].  The whole load-ordering thing has always
confused me.  ->inject_base does the opposite of "use base" in terms
of ordering as well, so the fact that I changed to inject_base from
use base is going to have changed some behavior as well.  The current
set of arguments is really insufficient to map all the possibilities
people might want.

I'll look at it soon and try to get 0.21 to replicate whatever
behavior 0.09 had.

As to the larger issue to be addressed in Schema::Loader, where I have
a bit more latitude in making up new interfaces:

There are three types of classes you might want to load into the
generated source classes: bases, regular "use $class", and components
(which are effectively a lot like bases for Loader purposes, but are
assumed to be in DBIx::Class::, and are stuff into the front of @ISA
rather than the back).  Core and PK::Auto are also components, which
are put in by default.  Someone might want any ordering or combination
of the above, even intermingled, like:

->load_components(qw/Quux/);
use base Foo;
use base Fooz;
use Bar;
use base Baz;
->load_components(qw/PK::Auto Core/);
use Bax;
use base Xyzzy;

I've been trying to imagine an elegant interface to allow all the
possibilities.  The best idea I've had so far is to make it all one
big arrayref to preserve ordering, where a tortuous example like above
would become:

source_classes => [
  { component => 'Quux' },
  { base => 'Foo' },
  { use => 'Bar' },
  { component => [qw/PK::Auto Core/] },
  { use => 'Bax' },
  { base =>'Xyzzy' },
]

And perhaps make component the default, which would at least reduce that to:

source_classes => [
   'Quux',
  { base => 'Foo' },
  { use => 'Bar' },
  [qw/PK::Auto Core/],
  { use => 'Bax' },
  { base =>'Xyzzy' },
]

And handle the magic by checking ref types.  (And stuff PK::Auto and
Core in at the top of the list unless they were manually specified
elsewhere somewhere in the middle).

Still seems messy though.

-- Brandon



More information about the Dbix-class mailing list