some shuffling/refactoring of the relationship code, and a TODO file added
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader.pm
1 package DBIx::Class::Schema::Loader;
2
3 use strict;
4 use warnings;
5 use Carp;
6
7 use vars qw($VERSION @ISA);
8 use UNIVERSAL::require;
9
10 # Always remember to do all digits for the version even if they're 0
11 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
12 # brain damage and presumably various other packaging systems too
13
14 $VERSION = '0.01000';
15
16 =head1 NAME
17
18 DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
19
20 =head1 SYNOPSIS
21
22   package My::Schema;
23   use base qw/DBIx::Class::Schema::Loader/;
24
25   __PACKAGE__->load_from_connection(
26     dsn                     => "dbi:mysql:dbname",
27     user                    => "root",
28     password                => "",
29     additional_classes      => [qw/DBIx::Class::Foo/],
30     additional_base_classes => [qw/My::Stuff/],
31     left_base_classes       => [qw/DBIx::Class::Bar/],
32     constraint              => '^foo.*',
33     relationships           => 1,
34     options                 => { AutoCommit => 1 }, 
35     inflect                 => { child => 'children' },
36     debug                   => 1,
37   );
38
39   # in seperate application code ...
40
41   use My::Schema;
42
43   my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
44   # -or-
45   my $schema1 = "My::Schema";
46   # ^^ defaults to dsn/user/pass from load_from_connection()
47
48 =head1 DESCRIPTION
49
50 DBIx::Class::Schema::Loader automates the definition of a
51 DBIx::Class::Schema by scanning table schemas and setting up
52 columns and primary keys.
53
54 DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2.  See
55 L<DBIx::Class::Schema::Loader::Generic> for more, and
56 L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
57 db-specific subclass for an unsupported db.
58
59 This module requires DBIx::Class::Loader 0.5 or later, and obsoletes
60 L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5 and later.
61
62 =cut
63
64 =head1 METHODS
65
66 =head2 load_from_connection
67
68 Example in Synopsis above demonstrates the available arguments.  For
69 detailed information on the arguments, see the
70 L<DBIx::Class::Schema::Loader::Generic> documentation.
71
72 =cut
73
74 sub load_from_connection {
75     my ( $class, %args ) = @_;
76
77     croak 'dsn argument is required' if ! $args{dsn};
78
79     my $dsn = $args{dsn};
80     my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
81     $driver = 'SQLite' if $driver eq 'SQLite2';
82     my $impl = "DBIx::Class::Schema::Loader::" . $driver;
83
84     $impl->require or
85       croak qq/Couldn't require loader class "$impl",/ .
86             qq/"$UNIVERSAL::require::ERROR"/;
87
88     push(@ISA, $impl);
89     $class->_load_from_connection(%args);
90 }
91
92 =head1 AUTHOR
93
94 Brandon Black, C<bblack@gmail.com>
95
96 Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
97
98 Based upon the work of IKEBE Tomohiro
99
100 =head1 THANK YOU
101
102 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
103 Randal Schwartz, Simon Flack and all the others who've helped.
104
105 =head1 LICENSE
106
107 This library is free software; you can redistribute it and/or modify it under
108 the same terms as Perl itself.
109
110 =head1 SEE ALSO
111
112 L<DBIx::Class>
113
114 =cut
115
116 1;