1DBIx::Class::Manual::CoUmspeorneCnotn(t3r)ibuted Perl DoDcBuImxe:n:tCaltaisosn::Manual::Component(3)
2
3
4
6 DBIx::Class::Manual::Component - Developing DBIx::Class Components
7
9 A component is a module that can be added in to your DBIx::Class
10 classes to provide extra functionality. A good example is the PK::Auto
11 component which automatically retrieves primary keys that the database
12 itself creates, after the insert has happened.
13
15 Components are loaded using the load_components() method within your
16 DBIx::Class classes.
17
18 package My::Thing;
19 use base qw( DBIx::Class::Core );
20 __PACKAGE__->load_components(qw/InflateColumn::DateTime TimeStamp/);
21
22 Generally you do not want to specify the full package name of a
23 component, instead take off the DBIx::Class:: part of it and just
24 include the rest. If you do want to load a component outside of the
25 normal namespace you can do so by prepending the component name with a
26 +.
27
28 __PACKAGE__->load_components(qw/ +My::Component /);
29
30 Once a component is loaded all of its methods, or otherwise, that it
31 provides will be available in your class.
32
33 The order in which is you load the components may be very important,
34 depending on the component. If you are not sure, then read the docs for
35 the components you are using and see if they mention anything about the
36 order in which you should load them.
37
39 Making your own component is very easy.
40
41 package DBIx::Class::MyComp;
42 use base qw(DBIx::Class);
43 # Create methods, accessors, load other components, etc.
44 1;
45
46 When a component is loaded it is included in the calling class'
47 inheritance chain using Class::C3. As well as providing custom utility
48 methods, a component may also override methods provided by other core
49 components, like DBIx::Class::Row and others. For example, you could
50 override the insert and delete methods.
51
52 sub insert {
53 my $self = shift;
54 # Do stuff with $self, like set default values.
55 return $self->next::method( @_ );
56 }
57
58 sub delete {
59 my $self = shift;
60 # Do stuff with $self.
61 return $self->next::method( @_ );
62 }
63
64 Now, the order that a component is loaded is very important.
65 Components that are loaded first are the first ones in the inheritance
66 stack. So, if you override insert() but the DBIx::Class::Row component
67 is loaded first then your insert() will never be called, since the
68 DBIx::Class::Row insert() will be called first. If you are unsure as
69 to why a given method is not being called try printing out the current
70 linearized MRO.
71
72 print join ', ' => mro::get_linear_isa('YourClass::Name');
73
75 Extra
76 These components provide extra functionality beyond basic functionality
77 that you can't live without.
78
79 DBIx::Class::CDBICompat - Class::DBI Compatibility layer.
80
81 DBIx::Class::FormTools - Build forms with multiple interconnected
82 objects.
83
84 DBIx::Class::HTMLWidget - Like FromForm but with DBIx::Class and
85 HTML::Widget.
86
87 DBIx::Class::Ordered - Modify the position of objects in an ordered
88 list.
89
90 DBIx::Class::PK::Auto - Retrieve automatically created primary keys
91 upon insert.
92
93 DBIx::Class::QueriesTime - Display the amount of time it takes to run
94 queries.
95
96 DBIx::Class::RandomStringColumns - Declare virtual columns that return
97 random strings.
98
99 DBIx::Class::UUIDColumns - Implicit UUID columns.
100
101 DBIx::Class::WebForm - CRUD methods.
102
103 Experimental
104 These components are under development, their interfaces may change,
105 they may not work, etc. So, use them if you want, but be warned.
106
107 DBIx::Class::Validation - Validate all data before submitting to your
108 database.
109
110 Core
111 These are the components that all, or nearly all, people will use
112 without even knowing it. These components provide most of DBIx::Class'
113 functionality.
114
115 DBIx::Class::Core - Loads various components that "most people" would
116 want.
117
118 DBIx::Class::AccessorGroup - Lets you build groups of accessors.
119
120 DBIx::Class::DB - Non-recommended classdata schema component.
121
122 DBIx::Class::InflateColumn - Automatically create objects from column
123 data.
124
125 DBIx::Class::PK - This class contains methods for handling primary keys
126 and methods depending on them.
127
128 DBIx::Class::Relationship - Inter-table relationships.
129
130 DBIx::Class::ResultSourceProxy::Table - Provides a classdata table
131 object and method proxies.
132
133 DBIx::Class::Row - Basic row methods.
134
136 DBIx::Class::Manual::Cookbook
137
139 Check the list of additional DBIC resources.
140
142 This module is free software copyright by the DBIx::Class (DBIC)
143 authors. You can redistribute it and/or modify it under the same terms
144 as the DBIx::Class library.
145
146
147
148perl v5.28.0 2017-12-08 DBIx::Class::Manual::Component(3)