Commit | Line | Data |
a78e3fed |
1 | package DBIx::Class::Loader; |
2 | |
3 | use strict; |
4 | use UNIVERSAL::require; |
5 | |
6 | our $VERSION = '0.14'; |
7 | |
8 | =head1 NAME |
9 | |
10 | DBIx::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 | |
33 | use with mod_perl |
34 | |
35 | in 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 | |
46 | in 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 | |
56 | DBIx::Class::Loader automate the definition of DBIx::Class sub-classes by |
57 | scanning table schemas and setting up columns and primary keys. |
58 | |
59 | Class names are defined by table names and the namespace option, which is |
60 | required. |
61 | |
62 | +---------+-----------+--------------+ |
63 | | table | namespace | class | |
64 | +---------+-----------+--------------+ |
65 | | foo | Data | Data::Foo | |
66 | | foo_bar | MyDB | MyDB::FooBar | |
67 | +---------+-----------+--------------+ |
68 | |
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. |
72 | |
73 | L<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 | |
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. |
84 | |
85 | =cut |
86 | |
87 | sub 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 | |
100 | Sebastian Riedel, C<sri@oook.de> |
101 | |
102 | Based upon the work of IKEBE Tomohiro |
103 | |
104 | =head1 THANK YOU |
105 | |
106 | Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, |
107 | Randal Schwartz, Simon Flack and all the others who've helped. |
108 | |
109 | =head1 LICENSE |
110 | |
111 | This library is free software; you can redistribute it and/or modify it under |
112 | the same terms as Perl itself. |
113 | |
114 | =head1 SEE ALSO |
115 | |
116 | L<DBIx::Class> |
117 | |
118 | =cut |
119 | |
120 | 1; |