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