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' },
30 my $class = $loader->find_class('film'); # $class => Data::Film
31 my $obj = $class->find(1);
38 use DBIx::Class::Loader;
39 my $loader = DBIx::Class::Loader->new(
40 dsn => "dbi:mysql:dbname",
46 in your web application.
50 # you can use Data::Film directly
51 my $film = Data::Film->retrieve($id);
56 DBIx::Class::Loader automate the definition of DBIx::Class sub-classes by
57 scanning table schemas and setting up columns and primary keys.
59 Class names are defined by table names and the namespace option, which is
62 +---------+-----------+--------------+
63 | table | namespace | class |
64 +---------+-----------+--------------+
65 | foo | Data | Data::Foo |
66 | foo_bar | MyDB | MyDB::FooBar |
67 +---------+-----------+--------------+
69 DBIx::Class::Loader supports MySQL, Postgres, SQLite and DB2. See
70 L<DBIx::Class::Loader::Generic> for more, and L<DBIx::Class::Loader::Writing>
71 for notes on writing your own db-specific subclass for an unsupported db.
73 L<Class::DBI::Loader> and L<Class::DBI> are now obsolete, use L<DBIx::Class> and this module instead. ;)
81 Example in Synopsis above demonstrates the available arguments. For
82 detailed information on the arguments, see the
83 L<DBIx::Class::Loader::Generic> documentation.
88 my ( $class, %args ) = @_;
90 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
91 $driver = 'SQLite' if $driver eq 'SQLite2';
92 my $impl = "DBIx::Class::Loader::" . $driver;
94 die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
95 return $impl->new(%args);
100 Sebastian Riedel, C<sri@oook.de>
102 Based upon the work of IKEBE Tomohiro
106 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
107 Randal Schwartz, Simon Flack and all the others who've helped.
111 This library is free software; you can redistribute it and/or modify it under
112 the same terms as Perl itself.