47906ff5ae6c5cb2e729e850d413aaa643b2a3a1
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class.pm
1 package DBIx::Class;
2
3 use strict;
4 use warnings;
5
6 use vars qw($VERSION);
7 use base;
8
9 $VERSION = '0.01';
10
11 sub load_components {
12   my $class = shift;
13   my @comp = map { "DBIx::Class::$_" } grep { $_ !~ /^#/ } @_;
14   $class->_load_components(@comp);
15 }
16
17 sub load_own_components {
18   my $class = shift;
19   my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_;
20   $class->_load_components(@comp);
21 }
22
23 sub _load_components {
24   my ($class, @comp) = @_;
25   foreach my $comp (@comp) {
26     eval "use $comp";
27     die $@ if $@;
28   }
29   no strict 'refs';
30   unshift(@{"${class}::ISA"}, @comp);
31 }
32
33 1;
34
35 =head1 NAME 
36
37 DBIx::Class - Because the brain is a terrible thing to waste.
38
39 =head1 SYNOPSIS
40
41 =head1 DESCRIPTION
42
43 This is a sql to oop mapper, inspired by the L<Class::DBI> framework, 
44 and meant to support compability with it, while restructuring the 
45 insides, and making it possible to support some new features like 
46 self-joins, distinct, group bys and more.
47
48 =head1 QUICKSTART
49
50 If you're using Class::DBI, replacing
51
52 use base qw/Class::DBI/;
53
54 with
55
56 use base qw/DBIx::Class/;
57 __PACKAGE__->load_components(qw/CDBICompat Core DB/);
58
59 will probably get you started.
60
61 If you're using AUTO_INCREMENT for your primary columns, you'll also want
62 yo load the approriate PK::Auto subclass - e.g.
63
64 __PACKAGE__->load_components(qw/CDBICompat PK::Auto::SQLite Core DB/);
65
66 (with is what ::Test::SQLite does to present the Class::DBI::Test::SQLite
67 interface)
68
69 If you fancy playing around with DBIx::Class from scratch, then read the docs
70 for ::Table and ::Relationship,
71
72 use base qw/DBIx::Class/;
73 __PACKAGE__->load_components(qw/Core DB/);
74
75 and have a look at t/lib/DBICTest.pm for a brief example.
76
77 =head1 AUTHORS
78
79 Matt S. Trout <perl-stuff@trout.me.uk>
80
81 =head1 LICENSE
82
83 You may distribute this code under the same terms as Perl itself.
84
85 =cut
86