[Dbix-class] Molesting Schemas

Matt S Trout dbix-class at trout.me.uk
Mon Jun 5 19:19:12 CEST 2006


Christopher H. Laco wrote:
> Matt S Trout wrote:
>   
>> Christopher H. Laco wrote:
>>     
>>> Matt S Trout wrote:
>>>  
>>>       
>>>> Christopher H. Laco wrote:
>>>>    
>>>>         
>>>>> As part of the new Handel stuff, I'm trying to provide as much ability
>>>>> as possible of using an existing schema instead of just relying on the
>>>>> default Handel schema.
>>>>>
>>>>> As part of this process, I'm 'injecting' custom component classes into
>>>>> the specified schema using load_components. Currently, this operates on
>>>>> the classes themselves using $schema_class->class($cart_class).
>>>>>
>>>>> The evil in this is that fact that once I inject Handel components into
>>>>> the schema classes, they will effect the use of the schema outside of
>>>>> Handel. This is somewhat of a Bad Thing.
>>>>>
>>>>> So, my question is two fold: First, is it possible to load_component a
>>>>> new component into a source instance only, not its class, in a way that
>>>>> it will only effect the current source/schema instance, and not all
>>>>> usages of the source class?
>>>>>
>>>>> $schema_instance->source($cart_source)->load_components(qw/Foo/)
>>>>>
>>>>> where
>>>>>
>>>>> $schema_instance->class($cart_class) does not have "Foo" loaded?
>>>>>       
>>>>>           
>>>> No, because this happens at the class level.
>>>>
>>>> OTOH you *could* quite happily take the user schema, compose_namespace
>>>> it to somewhere else (like e.g. Catalyst::Model::DBIC::Schema does) and
>>>> then inject stuff into the classes in the composed version, which will
>>>> have no effect whatsoever on the originals.
>>>>
>>>>
>>>>     
>>>>         
>>> Very true, although that only solves the problem for people who specify
>>> a schema_class, and I create the schema_instance. For people who
>>> actually pass in their existing schema_instance, my only choice is to
>>> work in its original classes.
>>>   
>>>       
>> Why? Doing a compose_namespace clones the schema so the connection will
>> come with it.Works fine as an object method as well as a class method too.
>>
>>
>>     
>
> Ooh... I have no idea it worked on an instance and stole the existing
> connection. Kewl!
>
>   
Stop assuming things won't work without trying them first. <bitchy> This 
isn't Class::DBI, remember? </bitchy>



More information about the Dbix-class mailing list