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",
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.*',
33 options => { AutoCommit => 1 },
34 inflect => { child => 'children' },
38 # in seperate application code ...
42 my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
44 my $schema1 = "My::Schema";
45 # ^^ defaults to dsn/user/pass from load_from_connection()
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.
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.
58 This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
65 =head2 load_from_connection
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.
73 sub load_from_connection {
74 my ( $class, %args ) = @_;
76 die qq/dsn argument is required/ if ! $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;
84 die qq/Couldn't require loader class "$impl",/ .
85 qq/"$UNIVERSAL::require::ERROR"/;
88 $class->_load_from_connection(%args);
93 Brandon Black, C<bblack@gmail.com>
95 Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
97 Based upon the work of IKEBE Tomohiro
101 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
102 Randal Schwartz, Simon Flack and all the others who've helped.
106 This library is free software; you can redistribute it and/or modify it under
107 the same terms as Perl itself.