tests and docs updates
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader.pm
CommitLineData
18fca96a 1package DBIx::Class::Schema::Loader;
a78e3fed 2
3use strict;
a4a19f3c 4use warnings;
5
6use vars qw($VERSION @ISA);
a78e3fed 7use UNIVERSAL::require;
8
a4a19f3c 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';
a78e3fed 14
15=head1 NAME
16
18fca96a 17DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
a78e3fed 18
19=head1 SYNOPSIS
20
a4a19f3c 21 package My::Schema;
22 use base qw/DBIx::Class::Schema::Loader/;
a78e3fed 23
a4a19f3c 24 __PACKAGE__->load_from_connection(
a78e3fed 25 dsn => "dbi:mysql:dbname",
26 user => "root",
27 password => "",
a4a19f3c 28 namespace => "My",
a78e3fed 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 );
af6c2665 38
a4a19f3c 39 # in seperate application code ...
a78e3fed 40
a4a19f3c 41 use My::Schema;
a78e3fed 42
a4a19f3c 43 my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
44 # -or-
fbd83464 45 my $schema1 = "My::Schema";
a4a19f3c 46 # ^^ defaults to dsn/user/pass from load_from_connection()
a78e3fed 47
48=head1 DESCRIPTION
49
fbd83464 50DBIx::Class::Schema::Loader automates the definition of a
18fca96a 51DBIx::Class::Schema by scanning table schemas and setting up
52columns and primary keys.
a78e3fed 53
18fca96a 54DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. See
55L<DBIx::Class::Schema::Loader::Generic> for more, and
56L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
57db-specific subclass for an unsupported db.
a78e3fed 58
fbd83464 59This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
60and later.
a78e3fed 61
62=cut
63
64=head1 METHODS
65
fbd83464 66=head2 load_from_connection
a78e3fed 67
68Example in Synopsis above demonstrates the available arguments. For
69detailed information on the arguments, see the
18fca96a 70L<DBIx::Class::Schema::Loader::Generic> documentation.
a78e3fed 71
72=cut
73
a4a19f3c 74sub load_from_connection {
a78e3fed 75 my ( $class, %args ) = @_;
af6c2665 76
fbd83464 77 die qq/dsn argument is required/ if ! $args{dsn};
af6c2665 78
fbd83464 79 $args{namespace} ||= $class;
af6c2665 80 $args{namespace} =~ s/(.*)::$/$1/;
81
a78e3fed 82 my $dsn = $args{dsn};
83 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
84 $driver = 'SQLite' if $driver eq 'SQLite2';
18fca96a 85 my $impl = "DBIx::Class::Schema::Loader::" . $driver;
af6c2665 86
a78e3fed 87 $impl->require or
fbd83464 88 die qq/Couldn't require loader class "$impl",/ .
89 qq/"$UNIVERSAL::require::ERROR"/;
af6c2665 90
a4a19f3c 91 push(@ISA, $impl);
92 $class->_load_from_connection(%args);
a78e3fed 93}
94
95=head1 AUTHOR
96
fbd83464 97Brandon Black, C<bblack@gmail.com>
98
99Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
a78e3fed 100
101Based upon the work of IKEBE Tomohiro
102
103=head1 THANK YOU
104
105Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
106Randal Schwartz, Simon Flack and all the others who've helped.
107
108=head1 LICENSE
109
110This library is free software; you can redistribute it and/or modify it under
111the same terms as Perl itself.
112
113=head1 SEE ALSO
114
115L<DBIx::Class>
116
117=cut
118
1191;