removing accidental DBIx-Class-Loader subdir
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Loader.pm
CommitLineData
a78e3fed 1package DBIx::Class::Loader;
2
3use strict;
4use UNIVERSAL::require;
5
6our $VERSION = '0.14';
7
8=head1 NAME
9
10DBIx::Class::Loader - Dynamic definition of DBIx::Class sub classes.
11
12=head1 SYNOPSIS
13
14 use DBIx::Class::Loader;
15
16 my $loader = DBIx::Class::Loader->new(
17 dsn => "dbi:mysql:dbname",
18 user => "root",
19 password => "",
20 namespace => "Data",
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.*',
25 relationships => 1,
26 options => { AutoCommit => 1 },
27 inflect => { child => 'children' },
28 debug => 1,
29 );
30 my $class = $loader->find_class('film'); # $class => Data::Film
31 my $obj = $class->find(1);
32
33use with mod_perl
34
35in your startup.pl
36
37 # load all tables
38 use DBIx::Class::Loader;
39 my $loader = DBIx::Class::Loader->new(
40 dsn => "dbi:mysql:dbname",
41 user => "root",
42 password => "",
43 namespace => "Data",
44 );
45
46in your web application.
47
48 use strict;
49
50 # you can use Data::Film directly
51 my $film = Data::Film->retrieve($id);
52
53
54=head1 DESCRIPTION
55
56DBIx::Class::Loader automate the definition of DBIx::Class sub-classes by
57scanning table schemas and setting up columns and primary keys.
58
59Class names are defined by table names and the namespace option, which is
60required.
61
62 +---------+-----------+--------------+
63 | table | namespace | class |
64 +---------+-----------+--------------+
65 | foo | Data | Data::Foo |
66 | foo_bar | MyDB | MyDB::FooBar |
67 +---------+-----------+--------------+
68
69DBIx::Class::Loader supports MySQL, Postgres, SQLite and DB2. See
70L<DBIx::Class::Loader::Generic> for more, and L<DBIx::Class::Loader::Writing>
71for notes on writing your own db-specific subclass for an unsupported db.
72
73L<Class::DBI::Loader> and L<Class::DBI> are now obsolete, use L<DBIx::Class> and this module instead. ;)
74
75=cut
76
77=head1 METHODS
78
79=head2 new
80
81Example in Synopsis above demonstrates the available arguments. For
82detailed information on the arguments, see the
83L<DBIx::Class::Loader::Generic> documentation.
84
85=cut
86
87sub new {
88 my ( $class, %args ) = @_;
89 my $dsn = $args{dsn};
90 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
91 $driver = 'SQLite' if $driver eq 'SQLite2';
92 my $impl = "DBIx::Class::Loader::" . $driver;
93 $impl->require or
94 die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
95 return $impl->new(%args);
96}
97
98=head1 AUTHOR
99
100Sebastian Riedel, C<sri@oook.de>
101
102Based upon the work of IKEBE Tomohiro
103
104=head1 THANK YOU
105
106Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
107Randal Schwartz, Simon Flack and all the others who've helped.
108
109=head1 LICENSE
110
111This library is free software; you can redistribute it and/or modify it under
112the same terms as Perl itself.
113
114=head1 SEE ALSO
115
116L<DBIx::Class>
117
118=cut
119
1201;