Use Optional::Dependencies for CDBICompat and its tests
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat.pm
CommitLineData
ea2e61bf 1package DBIx::Class::CDBICompat;
2
3use strict;
4use warnings;
75a23b3e 5use base qw/DBIx::Class::Core DBIx::Class::DB/;
289ba852 6
c8dc7d33 7unless (DBIx::Class::Optional::Dependencies->req_ok_for('cdbicompat')) {
8 __PACKAGE__->throw_exception(Class::Optional::Dependencies->req_missing_for('cdbicompat') . ' are missing and are required for CDBICompat');
118edec6 9}
126042ee 10
55e2d745 11__PACKAGE__->load_own_components(qw/
12 Constraints
13 Triggers
14 ReadOnly
55e2d745 15 LiveObjectIndex
16 AttributeAPI
17 Stringify
18 DestroyWarning
19 Constructor
20 AccessorMapping
21 ColumnCase
a9c8094b 22 Relationships
e60dc79f 23 Copy
55e2d745 24 LazyLoading
25 AutoUpdate
26 TempColumns
e60dc79f 27 GetSet
55e2d745 28 Retrieve
2a21de92 29 Pager
55e2d745 30 ColumnGroups
5ef62e9f 31 ColumnsAsHash
e60dc79f 32 AbstractSearch
33 ImaDBI
34 Iterator
35/);
55e2d745 36
ea2e61bf 371;
34d52be2 38
a2bd3796 39__END__
40
75d07914 41=head1 NAME
34d52be2 42
880a1a0c 43DBIx::Class::CDBICompat - Class::DBI Compatibility layer.
34d52be2 44
15fe6346 45=head1 SYNOPSIS
46
4965b78d 47 package My::CDBI;
48 use base qw/DBIx::Class::CDBICompat/;
49
50 ...continue as Class::DBI...
15fe6346 51
34d52be2 52=head1 DESCRIPTION
53
880a1a0c 54DBIx::Class features a fully featured compatibility layer with L<Class::DBI>
8273e845 55and some common plugins to ease transition for existing CDBI users.
4965b78d 56
57This is not a wrapper or subclass of DBIx::Class but rather a series of plugins. The result being that even though you're using the Class::DBI emulation layer you are still getting DBIx::Class objects. You can use all DBIx::Class features and methods via CDBICompat. This allows you to take advantage of DBIx::Class features without having to rewrite your CDBI code.
58
59
60=head2 Plugins
61
62CDBICompat is good enough that many CDBI plugins will work with CDBICompat, but many of the plugin features are better done with DBIx::Class methods.
63
64=head3 Class::DBI::AbstractSearch
65
66C<search_where()> is fully emulated using DBIC's search. Aside from emulation there's no reason to use C<search_where()>.
67
68=head3 Class::DBI::Plugin::NoCache
69
70C<nocache> is fully emulated.
71
72=head3 Class::DBI::Sweet
73
74The features of CDBI::Sweet are better done using DBIC methods which are almost exactly the same. It even uses L<Data::Page>.
75
76=head3 Class::DBI::Plugin::DeepAbstractSearch
77
fbee5c55 78This plugin will work, but it is more efficiently done using DBIC's native search facilities. The major difference is that DBIC will not infer the join for you, you have to tell it the join tables.
4965b78d 79
80
81=head2 Choosing Features
e7d1440f 82
48580715 83In fact, this class is just a recipe containing all the features emulated.
8273e845 84If you like, you can choose which features to emulate by building your
e7d1440f 85own class and loading it like this:
15fe6346 86
4965b78d 87 package My::DB;
15fe6346 88 __PACKAGE__->load_own_components(qw/CDBICompat/);
89
75d07914 90this will automatically load the features included in My::DB::CDBICompat,
15fe6346 91provided it looks something like this:
92
93 package My::DB::CDBICompat;
94 __PACKAGE__->load_components(qw/
95 CDBICompat::ColumnGroups
96 CDBICompat::Retrieve
97 CDBICompat::HasA
98 CDBICompat::HasMany
99 CDBICompat::MightHave
100 /);
101
34d52be2 102
e7d1440f 103=head1 LIMITATIONS
104
af133470 105=head2 Unimplemented
106
e7d1440f 107The following methods and classes are not emulated, maybe in the future.
108
109=over 4
110
111=item Class::DBI::Query
112
113Deprecated in Class::DBI.
114
115=item Class::DBI::Column
116
117Not documented in Class::DBI. CDBICompat's columns() returns a plain string, not an object.
118
119=item data_type()
120
121Undocumented CDBI method.
122
af133470 123=back
124
125=head2 Limited Support
126
127The following elements of Class::DBI have limited support.
128
129=over 4
130
474481a9 131=item Class::DBI::Relationship
e7d1440f 132
474481a9 133The semi-documented Class::DBI::Relationship objects returned by C<meta_info($type, $col)> are mostly emulated except for their C<args> method.
e7d1440f 134
af133470 135=item Relationships
136
48580715 137Relationships between tables (has_a, has_many...) must be declared after all tables in the relationship have been declared. Thus the usual CDBI idiom of declaring columns and relationships for each class together will not work. They must instead be done like so:
af133470 138
139 package Foo;
140 use base qw(Class::DBI);
d4daee7b 141
af133470 142 Foo->table("foo");
143 Foo->columns( All => qw(this that bar) );
144
145 package Bar;
146 use base qw(Class::DBI);
d4daee7b 147
af133470 148 Bar->table("bar");
149 Bar->columns( All => qw(up down) );
150
151 # Now that Foo and Bar are declared it is safe to declare a
152 # relationship between them
153 Foo->has_a( bar => "Bar" );
154
155
e7d1440f 156=back
157
a2bd3796 158=head1 FURTHER QUESTIONS?
34d52be2 159
a2bd3796 160Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
34d52be2 161
a2bd3796 162=head1 COPYRIGHT AND LICENSE
34d52be2 163
a2bd3796 164This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
165by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
166redistribute it and/or modify it under the same terms as the
167L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.