1 package DBIx::Class::Schema::Loader;
6 use vars qw($VERSION @ISA);
7 use UNIVERSAL::require;
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
17 DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
22 use base qw/DBIx::Class::Schema::Loader/;
24 __PACKAGE__->load_from_connection(
25 dsn => "dbi:mysql:dbname",
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.*',
34 options => { AutoCommit => 1 },
35 inflect => { child => 'children' },
39 # in seperate application code ...
43 my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
45 my $schema1 = "My::Schema";
46 # ^^ defaults to dsn/user/pass from load_from_connection()
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.
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.
59 This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
66 =head2 load_from_connection
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.
74 sub load_from_connection {
75 my ( $class, %args ) = @_;
77 die qq/dsn argument is required/ if ! $args{dsn};
79 $args{namespace} ||= $class;
80 $args{namespace} =~ s/(.*)::$/$1/;
83 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
84 $driver = 'SQLite' if $driver eq 'SQLite2';
85 my $impl = "DBIx::Class::Schema::Loader::" . $driver;
88 die qq/Couldn't require loader class "$impl",/ .
89 qq/"$UNIVERSAL::require::ERROR"/;
92 $class->_load_from_connection(%args);
97 Brandon Black, C<bblack@gmail.com>
99 Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
101 Based upon the work of IKEBE Tomohiro
105 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
106 Randal Schwartz, Simon Flack and all the others who've helped.
110 This library is free software; you can redistribute it and/or modify it under
111 the same terms as Perl itself.