DBIx-Class-0.08121_01

NAME

DBIx::Class::Manual::Component - Developing DBIx::Class Components

WHAT IS A COMPONENT

A component is a module that can be added in to your DBIx::Class classes to provide extra functionality. A good example is the PK::Auto component which automatically retrieves primary keys that the database itself creates, after the insert has happened.

USING

Components are loaded using the load_components() method within your DBIx::Class classes.

Generally you do not want to specify the full package name of a component, instead take off the DBIx::Class:: part of it and just include the rest. If you do want to load a component outside of the normal namespace you can do so by prepending the component name with a +.

__PACKAGE__->load_components(qw/ +My::Component /);

Once a component is loaded all of it's methods, or otherwise, that it provides will be available in your class.

The order in which is you load the components may be very important, depending on the component. If you are not sure, then read the docs for the components you are using and see if they mention anything about the order in which you should load them.

CREATING COMPONENTS

When a component is loaded it is included in the calling class' inheritance chain using Class::C3. As well as providing custom utility methods, a component may also override methods provided by other core components, like DBIx::Class::Row and others. For example, you could override the insert and delete methods.

Now, the order that a component is loaded is very important. Components that are loaded first are the first ones in the inheritance stack. So, if you override insert() but the DBIx::Class::Row component is loaded first then your insert() will never be called, since the DBIx::Class::Row insert() will be called first. If you are unsure as to why a given method is not being called try printing out the Class::C3 inheritance stack.