Commit | Line | Data |
18fca96a |
1 | package DBIx::Class::Schema::Loader; |
a78e3fed |
2 | |
3 | use strict; |
a4a19f3c |
4 | use warnings; |
5 | |
6 | use vars qw($VERSION @ISA); |
a78e3fed |
7 | use UNIVERSAL::require; |
8 | |
a4a19f3c |
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 |
12 | |
13 | $VERSION = '0.01000'; |
a78e3fed |
14 | |
15 | =head1 NAME |
16 | |
18fca96a |
17 | DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema |
a78e3fed |
18 | |
19 | =head1 SYNOPSIS |
20 | |
a4a19f3c |
21 | package My::Schema; |
22 | use base qw/DBIx::Class::Schema::Loader/; |
a78e3fed |
23 | |
a4a19f3c |
24 | __PACKAGE__->load_from_connection( |
a78e3fed |
25 | dsn => "dbi:mysql:dbname", |
26 | user => "root", |
27 | password => "", |
a78e3fed |
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.*', |
32 | relationships => 1, |
33 | options => { AutoCommit => 1 }, |
34 | inflect => { child => 'children' }, |
35 | debug => 1, |
36 | ); |
af6c2665 |
37 | |
a4a19f3c |
38 | # in seperate application code ... |
a78e3fed |
39 | |
a4a19f3c |
40 | use My::Schema; |
a78e3fed |
41 | |
a4a19f3c |
42 | my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs); |
43 | # -or- |
fbd83464 |
44 | my $schema1 = "My::Schema"; |
a4a19f3c |
45 | # ^^ defaults to dsn/user/pass from load_from_connection() |
a78e3fed |
46 | |
47 | =head1 DESCRIPTION |
48 | |
fbd83464 |
49 | DBIx::Class::Schema::Loader automates the definition of a |
18fca96a |
50 | DBIx::Class::Schema by scanning table schemas and setting up |
51 | columns and primary keys. |
a78e3fed |
52 | |
18fca96a |
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. |
a78e3fed |
57 | |
fbd83464 |
58 | This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5 |
59 | and later. |
a78e3fed |
60 | |
61 | =cut |
62 | |
63 | =head1 METHODS |
64 | |
fbd83464 |
65 | =head2 load_from_connection |
a78e3fed |
66 | |
67 | Example in Synopsis above demonstrates the available arguments. For |
68 | detailed information on the arguments, see the |
18fca96a |
69 | L<DBIx::Class::Schema::Loader::Generic> documentation. |
a78e3fed |
70 | |
71 | =cut |
72 | |
a4a19f3c |
73 | sub load_from_connection { |
a78e3fed |
74 | my ( $class, %args ) = @_; |
af6c2665 |
75 | |
fbd83464 |
76 | die qq/dsn argument is required/ if ! $args{dsn}; |
af6c2665 |
77 | |
a78e3fed |
78 | my $dsn = $args{dsn}; |
79 | my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i; |
80 | $driver = 'SQLite' if $driver eq 'SQLite2'; |
18fca96a |
81 | my $impl = "DBIx::Class::Schema::Loader::" . $driver; |
af6c2665 |
82 | |
a78e3fed |
83 | $impl->require or |
fbd83464 |
84 | die qq/Couldn't require loader class "$impl",/ . |
85 | qq/"$UNIVERSAL::require::ERROR"/; |
af6c2665 |
86 | |
a4a19f3c |
87 | push(@ISA, $impl); |
88 | $class->_load_from_connection(%args); |
a78e3fed |
89 | } |
90 | |
91 | =head1 AUTHOR |
92 | |
fbd83464 |
93 | Brandon Black, C<bblack@gmail.com> |
94 | |
95 | Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from) |
a78e3fed |
96 | |
97 | Based upon the work of IKEBE Tomohiro |
98 | |
99 | =head1 THANK YOU |
100 | |
101 | Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, |
102 | Randal Schwartz, Simon Flack and all the others who've helped. |
103 | |
104 | =head1 LICENSE |
105 | |
106 | This library is free software; you can redistribute it and/or modify it under |
107 | the same terms as Perl itself. |
108 | |
109 | =head1 SEE ALSO |
110 | |
111 | L<DBIx::Class> |
112 | |
113 | =cut |
114 | |
115 | 1; |