If I understand your question correctly, then I am seeing a big problem with your design.

If you have an instance of a DBIx::Class::Row subclass stored in your attribute, which can potentially be from different resultsets, then you should not alter your *class* based on a value which is specific to the *instance*. The value of that attribute, and therefore the methods you can to delegate too, can change from instance to instance. You do not want to be altering the set of delegated methods at the class level.

What you want to do is to create different classes for each possible DBIx::Class::Row subclass, they can share behavior through a common base class or roles, but you should have a specific class for each possible type of row object. This could even be done with anon-classes if you want.

- Stevan




On Dec 28, 2009, at 11:43 AM, Rolf Schaufelberger wrote:

Hi,

I have some classes, that have a DBIx::Class::Row object a one of it's attributes. What is the best way to delegate all methods (acessing columns an relations ) to this object ? In my current, non Moose implementation I'm doing this with AUTOLOAD, there I'm testing if the object can the required method and call it.

The docs mention that either a role or a subref can be specified as the value for the delegates param. Now, since my row objects are from different resultsets, the methods aren't always the same, so I cannot see, how a role could help but, but in a sub I could introspect the row object. How will that subref be called ? Or is there better solution ?


Rolf Schaufelberger






Reply via email to