File Coverage

blib/lib/DBIx/Class/CDBICompat.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::CDBICompat;
2              
3 43     43   29668 use strict;
  43         127  
  43         1353  
4 43     43   253 use warnings;
  43         100  
  43         1275  
5 43     43   243 use base qw/DBIx::Class::Core DBIx::Class::DB/;
  43         108  
  43         26732  
6              
7             # Modules CDBICompat needs that DBIx::Class does not.
8             my @Extra_Modules = qw(
9             Class::Trigger
10             DBIx::ContextualFetch
11             Clone
12             );
13              
14             my @didnt_load;
15             for my $module (@Extra_Modules) {
16             push @didnt_load, $module unless eval qq{require $module};
17             }
18             __PACKAGE__->throw_exception("@{[ join ', ', @didnt_load ]} are missing and are required for CDBICompat")
19             if @didnt_load;
20              
21              
22             __PACKAGE__->load_own_components(qw/
23             Constraints
24             Triggers
25             ReadOnly
26             LiveObjectIndex
27             AttributeAPI
28             Stringify
29             DestroyWarning
30             Constructor
31             AccessorMapping
32             ColumnCase
33             Relationships
34             Copy
35             LazyLoading
36             AutoUpdate
37             TempColumns
38             GetSet
39             Retrieve
40             Pager
41             ColumnGroups
42             ColumnsAsHash
43             AbstractSearch
44             ImaDBI
45             Iterator
46             /);
47              
48             1;
49              
50             __END__
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 FURTHER QUESTIONS?
170              
171             Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
172              
173             =head1 COPYRIGHT AND LICENSE
174              
175             This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
176             by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
177             redistribute it and/or modify it under the same terms as the
178             L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.