Component manual.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Manual / Component.pod
CommitLineData
3d18a9c1 1
2=head1 NAME
3
4DBIx::Class::Manula::Component - Existing components and how to develop new ones.
5
6=head1 USING
7
8Components are loaded using the load_components() method within your
9DBIx::Class classes.
10
11 package My::Thing;
12 use base qw( DBIx::Class );
13 __PACKAGE__->load_components(qw( PK::Auto Core ));
14
15Generally you do not want to specify the full package name
16of a component, instead take off the DBIx::Class:: part of
17it and just include the rest. If you do want to load a
18component outside of the normal namespace you can do so
19by prepending the component name with a +.
20
21 __PACKAGE__->load_components(qw( +My::Component ));
22
23Once a component is loaded all of it's methods, or otherwise,
24that it provides will be available in your class.
25
26The order in which is you load the components may be
27very imporant, depending on the component. The general
28rule of thumb is to first load extra components and then
29load core ones last. If you are not sure, then read the
30docs for the components you are using and see if they
31mention anything about the order in which you should load
32them.
33
34=head1 EXISTING
35
36=head2 Extra
37
38These components provide extra functionality above
39and beyond what any normal user would need out of the
40box.
41
42L<DBIx::Class::CDBICompat> - Class::DBI Compatability layer.
43
44L<DBIx::Class::PK::Auto> - Retrieve automatically created primary keys upon insert.
45
46L<DBIx::Class::FormTools> - Build forms with multiple interconnected objects.
47
48L<DBIx::Class::HTMLWidget> - Like FromForm but with DBIx::Class and HTML::Widget.
49
50L<DBIx::Class::QueriesTime> - Display the amount of time it takes to run queries.
51
52L<DBIx::Class::RandomStringColumns> - Declare virtual columns that return random strings.
53
54L<DBIx::Class::UTF8Columns> - Force UTF8 (Unicode) flag on columns.
55
56L<DBIx::Class::UUIDColumns> - Implicit UUID columns.
57
58L<DBIx::Class::WebForm> - CRUD methods.
59
60=head2 Experimental
61
62These components are under development, there interfaces may
63change, they may not work, etc. So, use them if you want, but
64be warned.
65
66L<DBIx::Class::Serialize> - Hooks for Storable freeze/thaw.
67
68L<DBIx::Class::Serialize::Storable> - Hooks for Storable freeze/thaw.
69
70L<DBIx::Class::Validation> - Validate all data before submitting to your database.
71
72=head2 Core
73
74These are the components that all, or nearly all, people will use
75without even knowing it. These components provide most of
76DBIx::Class' functionality.
77
78L<DBIx::Class::Core> - Loads various components that "most people" would want.
79
80L<DBIx::Class::DB> - Non-recommended classdata schema component.
81
82L<DBIx::Class::InflateColumn> - Automatically create objects from column data.
83
84L<DBIx::Class::Relationship> - Inter-table relationships.
85
86L<DBIx::Class::PK> - This class contains methods for handling primary keys and methods depending on them.
87
88L<DBIx::Class::Row> - Basic row methods.
89
90L<DBIx::Class::ResultSourceProxy::Table> - Provides a classdata table object and method proxies.
91
92L<DBIx::Class::AccessorGroup> - Lets you build groups of accessors.
93
94=head1 CREATEING
95
96Making your own component is very easy.
97
98 package DBIx::Class::MyComp;
99 use base qw(DBIx::Class);
100 # Create methods, accessors, load other components, etc.
101 1;
102
103When a component is loaded it is included in the calling
104classes inheritance chain using L<Class::C3>. As well as
105providing custom utility methods, a component may also
106override methods provided by other core components, like
107L<DBIx::Class::Row> and others. For example, you
108could override the insert and delete methods.
109
110 sub insert {
111 my $self = shift;
112 # Do stuff with $self, like set default values.
113 return $self->nest::method( @_ );
114 }
115
116 sub delete {
117 my $self = shift;
118 # Do stuff with $self.
119 return $self->nest::method( @_ );
120 }
121
122Now, the order that a component is loaded is very important. Components
123that are loaded first are the first ones in the inheritance stack. So, if
124you override insert() but the DBIx::Class::Row component is loaded first
125then your insert() will never be called, since the DBIx::Class::Row insert()
126will be called first. If you are unsure as to why a given method is not
127being called try printing out the Class::C3 inheritance stack.
128
129 print join ', ' => Class::C3::calculateMRO('YourClass::Name');
130
131Check out the L<Class::C3> docs for more information.
132
133=head1 SEE ALSO
134
135L<DBIx::Class::Manual::Cookbook>
136
137L<DBIx::Class::Manual::FAQ>
138
139=head1 AUTHOR
140
141Aran Clary Deltac <bluefeet@cpan.org>
142