Clarify licensing, ensure footers are consistent throughout the project
[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
118edec6 7# Modules CDBICompat needs that DBIx::Class does not.
8my @Extra_Modules = qw(
9 Class::Trigger
10 DBIx::ContextualFetch
11 Clone
12);
d4daee7b 13
118edec6 14my @didnt_load;
15for my $module (@Extra_Modules) {
16 push @didnt_load, $module unless eval qq{require $module};
17}
70c28808 18__PACKAGE__->throw_exception("@{[ join ', ', @didnt_load ]} are missing and are required for CDBICompat")
118edec6 19 if @didnt_load;
20
126042ee 21
55e2d745 22__PACKAGE__->load_own_components(qw/
23 Constraints
24 Triggers
25 ReadOnly
55e2d745 26 LiveObjectIndex
27 AttributeAPI
28 Stringify
29 DestroyWarning
30 Constructor
31 AccessorMapping
32 ColumnCase
a9c8094b 33 Relationships
e60dc79f 34 Copy
55e2d745 35 LazyLoading
36 AutoUpdate
37 TempColumns
e60dc79f 38 GetSet
55e2d745 39 Retrieve
2a21de92 40 Pager
55e2d745 41 ColumnGroups
5ef62e9f 42 ColumnsAsHash
e60dc79f 43 AbstractSearch
44 ImaDBI
45 Iterator
46/);
55e2d745 47
ea2e61bf 481;
34d52be2 49
a2bd3796 50__END__
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>
8273e845 66and some common plugins to ease transition for existing CDBI users.
4965b78d 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
48580715 94In fact, this class is just a recipe containing all the features emulated.
8273e845 95If you like, you can choose which features to emulate by building your
e7d1440f 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
48580715 148Relationships 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 149
150 package Foo;
151 use base qw(Class::DBI);
d4daee7b 152
af133470 153 Foo->table("foo");
154 Foo->columns( All => qw(this that bar) );
155
156 package Bar;
157 use base qw(Class::DBI);
d4daee7b 158
af133470 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
a2bd3796 169=head1 FURTHER QUESTIONS?
34d52be2 170
a2bd3796 171Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
34d52be2 172
a2bd3796 173=head1 COPYRIGHT AND LICENSE
34d52be2 174
a2bd3796 175This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
176by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
177redistribute it and/or modify it under the same terms as the
178L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.