[Dbix-class] compose_namespace & C3

Brandon Black blblack at gmail.com
Tue Jul 11 21:07:51 CEST 2006


On 7/11/06, Christopher H. Laco <claco at chrislaco.com> wrote:
> Matt S Trout wrote:
> > Christopher H. Laco wrote:
> >> I while back, knee deep in Handel-DBIC magicland, I was attempting to
> >> call class->load_components to inject components into a cloned schema.
> >>
> >> It was slow as dirt because C# kept getting reinitialized. I tried
> >> several incantations of $TURN_OFF_C3 and uninitialize, and nothing
> >> helped the problem.
> >>
> >> Then, while surfing through Schema.pm, I noticed this nugget in
> >> compose_namespace:
> >>
> >>
> >> {
> >>    local *Class::C3::reinitialize = sub { };
> >>    ...
> >> }
> >> Class::C3->reinitialize;
> >>
> >>
> >> How curious. I suspect that if I did the same, it would work as
> >> expected, rather than figthing $TURN_OF_C3.
> >>
> >>
> >> Can the creator of this magic shed any light on the matter?
> >
> > I have a feeling I went through the same contortions and then said "sod
> > it" and did that before I hit homicidal. It does, indeed, appear to work.
> >
>
> I figured as much. If it performs, I'd much prefer using load_components
> instead of the symbol table hackery jiggery pokery I'm doing now.
>
> In fact, in theory, I should be able to wrap my calls to
> compose_namespace with C3::reinitialize set to an empty sub, then do my
> load_compoents calls, and then call reinit myself. That should save me
> the hit of compose_namespace doing a reinit too.
>

Check out DBIx::Class::Schema::Loader::Base, which uses the same trick
(although now that I look at it again, I could have been a bit more
efficient about it :o )

-- Brandon



More information about the Dbix-class mailing list