DBIx::C...mponent(3)
π DBIx::Class::Manual::Component π
Okay bestie, this is the User Contributed Perl Documentation page for DBIx::Class::Manual::Component β literally the glow-up guide to developing DBIx::Class components. Every detail is staying in here, no cap. π«Άβ¨
β¨ NAME β¨
DBIx::Class::Manual::Component β Developing DBIx::Class Components. Iconic, concise, no notes. π
π¦ 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. It's giving βdatabase did it, but make it automatic.β π₯
π» USING π»
Components are loaded using the load_components() method within your DBIx::Class classes. Like this, bestie:
package My::Thing;
use base qw( DBIx::Class::Core );
__PACKAGE__->load_components(qw/InflateColumn::DateTime TimeStamp/);
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, everything it provides β methods or otherwise β will be available in your class. Slay. π
The order in which 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. Order matters, bestie β do not skip the docs. πΈ
π οΈ CREATING COMPONENTS π οΈ
Making your own component is very easy.
package DBIx::Class::MyComp;
use base qw(DBIx::Class);
# Create methods, accessors, load other components, etc.
1;
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.
sub insert {
my $self = shift;
# Do stuff with $self, like set default values.
return $self->next::method( @_ );
}
sub delete {
my $self = shift;
# Do stuff with $self.
return $self->next::method( @_ );
}
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 current linearized MRO.
print join ', ' => mro::get_linear_isa('YourClass::Name');
π EXISTING COMPONENTS π
π Extra
These components provide extra functionality beyond basic functionality that you can't live without. Obsessed. π
DBIx::Class::CDBICompatβ Class::DBI Compatibility layer.DBIx::Class::FormToolsβ Build forms with multiple interconnected objects.DBIx::Class::HTMLWidgetβ Like FromForm but with DBIx::Class and HTML::Widget.DBIx::Class::Orderedβ Modify the position of objects in an ordered list.DBIx::Class::PK::Autoβ Retrieve automatically created primary keys upon insert.DBIx::Class::QueriesTimeβ Display the amount of time it takes to run queries.DBIx::Class::RandomStringColumnsβ Declare virtual columns that return random strings.DBIx::Class::UUIDColumnsβ Implicit UUID columns.DBIx::Class::WebFormβ CRUD methods.
π§ͺ Experimental
These components are under development, their interfaces may change, they may not work, etc. So, use them if you want, but be warned. This is the βproceed with cautionβ shelf, bestie. β οΈ
DBIx::Class::Validationβ Validate all data before submitting to your database.
π Core
These are the components that all, or nearly all, people will use without even knowing it. These components provide most of DBIx::Class' functionality. Main character energy, honestly. π
DBIx::Class::Coreβ Loads various components that "most people" would want.DBIx::Class::AccessorGroupβ Lets you build groups of accessors.DBIx::Class::DBβ Non-recommended classdata schema component.DBIx::Class::InflateColumnβ Automatically create objects from column data.DBIx::Class::PKβ This class contains methods for handling primary keys and methods depending on them.DBIx::Class::Relationshipβ Inter-table relationships.DBIx::Class::ResultSourceProxy::Tableβ Provides a classdata table object and method proxies.DBIx::Class::Rowβ Basic row methods.
π SEE ALSO π
DBIx::Class::Manual::Cookbookβ go read it, bestie. π
π€ FURTHER QUESTIONS? π€
Check the list of additional DBIC resources. That's it. That's the tea. π«Ά
π COPYRIGHT AND LICENSE π
This module is free software copyright by the DBIx::Class (DBIC) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library.
Okurrr, that's the whole manual page. Big kisses from the User Contributed Perl Documentation π β source/version perl v5.42.0, dated 2025-01-22, and the page itself is DBIx::C...mponent(3). Byeee π
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBIx-Class 0.082844-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms