1 package DBIx::Class::Loader;
4 use UNIVERSAL::require;
10 DBIx::Class::Loader - Dynamic definition of DBIx::Class sub classes.
14 use DBIx::Class::Loader;
16 my $loader = DBIx::Class::Loader->new(
17 dsn => "dbi:mysql:dbname",
21 additional_classes => [qw/DBIx::Class::Foo/],
22 additional_base_classes => [qw/My::Stuff/],
23 left_base_classes => [qw/DBIx::Class::Bar/],
24 constraint => '^foo.*',
26 options => { AutoCommit => 1 },
27 inflect => { child => 'children' },
31 my $conn = $loader->get_connection($dsn, $user, $password); #
32 my $conn = $loader->get_connection(); # uses same dsn as ->new();
39 use DBIx::Class::Loader;
40 my $loader = DBIx::Class::Loader->new(
41 dsn => "dbi:mysql:dbname",
47 in your web application.
51 # you can use Data::Film directly
52 my $film = Data::Film->retrieve($id);
57 DBIx::Class::Loader automate the definition of DBIx::Class sub-classes by
58 scanning table schemas and setting up columns and primary keys.
60 Class names are defined by table names and the namespace option, which is
63 +---------+-----------+--------------+
64 | table | namespace | class |
65 +---------+-----------+--------------+
66 | foo | Data | Data::Foo |
67 | foo_bar | MyDB | MyDB::FooBar |
68 +---------+-----------+--------------+
70 DBIx::Class::Loader supports MySQL, Postgres, SQLite and DB2. See
71 L<DBIx::Class::Loader::Generic> for more, and L<DBIx::Class::Loader::Writing>
72 for notes on writing your own db-specific subclass for an unsupported db.
74 L<Class::DBI::Loader> and L<Class::DBI> are now obsolete, use L<DBIx::Class> and this module instead. ;)
82 Example in Synopsis above demonstrates the available arguments. For
83 detailed information on the arguments, see the
84 L<DBIx::Class::Loader::Generic> documentation.
89 my ( $class, %args ) = @_;
91 foreach (qw/namespace dsn/) {
92 die qq/Argument $_ is required/ if ! $args{$_};
95 $args{namespace} =~ s/(.*)::$/$1/;
98 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
99 $driver = 'SQLite' if $driver eq 'SQLite2';
100 my $impl = "DBIx::Class::Loader::" . $driver;
103 die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
105 return $impl->new(%args);
110 Sebastian Riedel, C<sri@oook.de>
112 Based upon the work of IKEBE Tomohiro
116 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
117 Randal Schwartz, Simon Flack and all the others who've helped.
121 This library is free software; you can redistribute it and/or modify it under
122 the same terms as Perl itself.