Merge 'sybase' into 'trunk'
[dbsrgits/DBIx-Class-Historic.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 6use Carp::Clan qw/^DBIx::Class/;
7
118edec6 8# Modules CDBICompat needs that DBIx::Class does not.
9my @Extra_Modules = qw(
10 Class::Trigger
11 DBIx::ContextualFetch
12 Clone
13);
14
15my @didnt_load;
16for my $module (@Extra_Modules) {
17 push @didnt_load, $module unless eval qq{require $module};
18}
19croak("@{[ join ', ', @didnt_load ]} are missing and are required for CDBICompat")
20 if @didnt_load;
21
126042ee 22
55e2d745 23__PACKAGE__->load_own_components(qw/
24 Constraints
25 Triggers
26 ReadOnly
55e2d745 27 LiveObjectIndex
28 AttributeAPI
29 Stringify
30 DestroyWarning
31 Constructor
32 AccessorMapping
33 ColumnCase
a9c8094b 34 Relationships
e60dc79f 35 Copy
55e2d745 36 LazyLoading
37 AutoUpdate
38 TempColumns
e60dc79f 39 GetSet
55e2d745 40 Retrieve
2a21de92 41 Pager
55e2d745 42 ColumnGroups
5ef62e9f 43 ColumnsAsHash
e60dc79f 44 AbstractSearch
45 ImaDBI
46 Iterator
47/);
55e2d745 48
49 #DBIx::Class::ObjIndexStubs
ea2e61bf 501;
34d52be2 51
75d07914 52=head1 NAME
34d52be2 53
880a1a0c 54DBIx::Class::CDBICompat - Class::DBI Compatibility layer.
34d52be2 55
15fe6346 56=head1 SYNOPSIS
57
4965b78d 58 package My::CDBI;
59 use base qw/DBIx::Class::CDBICompat/;
60
61 ...continue as Class::DBI...
15fe6346 62
34d52be2 63=head1 DESCRIPTION
64
880a1a0c 65DBIx::Class features a fully featured compatibility layer with L<Class::DBI>
4965b78d 66and some common plugins to ease transition for existing CDBI users.
67
68This 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.
69
70
71=head2 Plugins
72
73CDBICompat is good enough that many CDBI plugins will work with CDBICompat, but many of the plugin features are better done with DBIx::Class methods.
74
75=head3 Class::DBI::AbstractSearch
76
77C<search_where()> is fully emulated using DBIC's search. Aside from emulation there's no reason to use C<search_where()>.
78
79=head3 Class::DBI::Plugin::NoCache
80
81C<nocache> is fully emulated.
82
83=head3 Class::DBI::Sweet
84
85The features of CDBI::Sweet are better done using DBIC methods which are almost exactly the same. It even uses L<Data::Page>.
86
87=head3 Class::DBI::Plugin::DeepAbstractSearch
88
fbee5c55 89This 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 90
91
92=head2 Choosing Features
e7d1440f 93
94In fact, this class is just a receipe containing all the features emulated.
95If you like, you can choose which features to emulate by building your
96own class and loading it like this:
15fe6346 97
4965b78d 98 package My::DB;
15fe6346 99 __PACKAGE__->load_own_components(qw/CDBICompat/);
100
75d07914 101this will automatically load the features included in My::DB::CDBICompat,
15fe6346 102provided it looks something like this:
103
104 package My::DB::CDBICompat;
105 __PACKAGE__->load_components(qw/
106 CDBICompat::ColumnGroups
107 CDBICompat::Retrieve
108 CDBICompat::HasA
109 CDBICompat::HasMany
110 CDBICompat::MightHave
111 /);
112
34d52be2 113
e7d1440f 114=head1 LIMITATIONS
115
af133470 116=head2 Unimplemented
117
e7d1440f 118The following methods and classes are not emulated, maybe in the future.
119
120=over 4
121
122=item Class::DBI::Query
123
124Deprecated in Class::DBI.
125
126=item Class::DBI::Column
127
128Not documented in Class::DBI. CDBICompat's columns() returns a plain string, not an object.
129
130=item data_type()
131
132Undocumented CDBI method.
133
af133470 134=back
135
136=head2 Limited Support
137
138The following elements of Class::DBI have limited support.
139
140=over 4
141
474481a9 142=item Class::DBI::Relationship
e7d1440f 143
474481a9 144The semi-documented Class::DBI::Relationship objects returned by C<meta_info($type, $col)> are mostly emulated except for their C<args> method.
e7d1440f 145
af133470 146=item Relationships
147
148Relationships between tables (has_a, has_many...) must be delcared 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:
149
150 package Foo;
151 use base qw(Class::DBI);
152
153 Foo->table("foo");
154 Foo->columns( All => qw(this that bar) );
155
156 package Bar;
157 use base qw(Class::DBI);
158
159 Bar->table("bar");
160 Bar->columns( All => qw(up down) );
161
162 # Now that Foo and Bar are declared it is safe to declare a
163 # relationship between them
164 Foo->has_a( bar => "Bar" );
165
166
e7d1440f 167=back
168
34d52be2 169=head1 AUTHORS
170
daec44b8 171Matt S. Trout <mst@shadowcatsystems.co.uk>
34d52be2 172
173=head1 LICENSE
174
175You may distribute this code under the same terms as Perl itself.
176
177=cut
178