spelling fixes in the documaentation, sholud be gud now ;)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat.pm
1 package DBIx::Class::CDBICompat;
2
3 use strict;
4 use warnings;
5 use base qw/DBIx::Class::Core DBIx::Class::DB/;
6 use Carp::Clan qw/^DBIx::Class/;
7
8 # Modules CDBICompat needs that DBIx::Class does not.
9 my @Extra_Modules = qw(
10     Class::Trigger
11     DBIx::ContextualFetch
12     Clone
13 );
14
15 my @didnt_load;
16 for my $module (@Extra_Modules) {
17     push @didnt_load, $module unless eval qq{require $module};
18 }
19 croak("@{[ join ', ', @didnt_load ]} are missing and are required for CDBICompat")
20     if @didnt_load;
21
22
23 __PACKAGE__->load_own_components(qw/
24   Constraints
25   Triggers
26   ReadOnly
27   LiveObjectIndex
28   AttributeAPI
29   Stringify
30   DestroyWarning
31   Constructor
32   AccessorMapping
33   ColumnCase
34   Relationships
35   Copy
36   LazyLoading
37   AutoUpdate
38   TempColumns
39   GetSet
40   Retrieve
41   Pager
42   ColumnGroups
43   ColumnsAsHash
44   AbstractSearch
45   ImaDBI
46   Iterator
47 /);
48
49             #DBIx::Class::ObjIndexStubs
50 1;
51
52 =head1 NAME
53
54 DBIx::Class::CDBICompat - Class::DBI Compatibility layer.
55
56 =head1 SYNOPSIS
57
58   package My::CDBI;
59   use base qw/DBIx::Class::CDBICompat/;
60
61   ...continue as Class::DBI...
62
63 =head1 DESCRIPTION
64
65 DBIx::Class features a fully featured compatibility layer with L<Class::DBI>
66 and some common plugins to ease transition for existing CDBI users. 
67
68 This 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
73 CDBICompat 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
77 C<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
81 C<nocache> is fully emulated.
82
83 =head3 Class::DBI::Sweet
84
85 The 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
89 This 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.
90
91
92 =head2 Choosing Features
93
94 In fact, this class is just a recipe containing all the features emulated.
95 If you like, you can choose which features to emulate by building your 
96 own class and loading it like this:
97
98   package My::DB;
99   __PACKAGE__->load_own_components(qw/CDBICompat/);
100
101 this will automatically load the features included in My::DB::CDBICompat,
102 provided 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
113
114 =head1 LIMITATIONS
115
116 =head2 Unimplemented
117
118 The following methods and classes are not emulated, maybe in the future.
119
120 =over 4
121
122 =item Class::DBI::Query
123
124 Deprecated in Class::DBI.
125
126 =item Class::DBI::Column
127
128 Not documented in Class::DBI.  CDBICompat's columns() returns a plain string, not an object.
129
130 =item data_type()
131
132 Undocumented CDBI method.
133
134 =back
135
136 =head2 Limited Support
137
138 The following elements of Class::DBI have limited support.
139
140 =over 4
141
142 =item Class::DBI::Relationship
143
144 The semi-documented Class::DBI::Relationship objects returned by C<meta_info($type, $col)> are mostly emulated except for their C<args> method.
145
146 =item Relationships
147
148 Relationships 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:
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
167 =back
168
169 =head1 AUTHORS
170
171 Matt S. Trout <mst@shadowcatsystems.co.uk>
172
173 =head1 LICENSE
174
175 You may distribute this code under the same terms as Perl itself.
176
177 =cut
178