1Class::DBI::Loader(3) User Contributed Perl DocumentationClass::DBI::Loader(3)
2
3
4
6 Class::DBI::Loader - Dynamic definition of Class::DBI sub classes.
7
9 use Class::DBI::Loader;
10
11 my $loader = Class::DBI::Loader->new(
12 dsn => "dbi:mysql:dbname",
13 user => "root",
14 password => "",
15 options => { RaiseError => 1, AutoCommit => 0 },
16 namespace => "Data",
17 additional_classes => qw/Class::DBI::AbstractSearch/, # or arrayref
18 additional_base_classes => qw/My::Stuff/, # or arrayref
19 left_base_classes => qw/Class::DBI::Sweet/, # or arrayref
20 constraint => '^foo.*',
21 relationships => 1,
22 options => { AutoCommit => 1 },
23 inflect => { child => 'children' },
24 require => 1
25 );
26 my $class = $loader->find_class('film'); # $class => Data::Film
27 my $obj = $class->retrieve(1);
28
29 use with mod_perl
30
31 in your startup.pl
32
33 # load all tables
34 use Class::DBI::Loader;
35 my $loader = Class::DBI::Loader->new(
36 dsn => "dbi:mysql:dbname",
37 user => "root",
38 password => "",
39 namespace => "Data",
40 );
41
42 in your web application.
43
44 use strict;
45
46 # you can use Data::Film directly
47 my $film = Data::Film->retrieve($id);
48
50 Class::DBI::Loader automate the definition of Class::DBI sub-classes.
51 scan table schemas and setup columns, primary key.
52
53 class names are defined by table names and namespace option.
54
55 +-----------+-----------+-----------+
56 ⎪ table ⎪ namespace ⎪ class ⎪
57 +-----------+-----------+-----------+
58 ⎪ foo ⎪ Data ⎪ Data::Foo ⎪
59 ⎪ foo_bar ⎪ ⎪ FooBar ⎪
60 +-----------+-----------+-----------+
61
62 Class::DBI::Loader supports MySQL, Postgres and SQLite.
63
64 See Class::DBI::Loader::Generic.
65
67 new %args
68
69 additional_base_classes
70 List of additional base classes your table classes will use.
71
72 left_base_classes
73 List of additional base classes, that need to be leftmost, for
74 example Class::DBI::Sweet (former Catalyst::Model::CDBI::Sweet).
75
76 additional_classes
77 List of additional classes which your table classes will use.
78
79 constraint
80 Only load tables matching regex.
81
82 exclude
83 Exclude tables matching regex.
84
85 debug
86 Enable debug messages.
87
88 dsn DBI Data Source Name.
89
90 namespace
91 Namespace under which your table classes will be initialized.
92
93 password
94 Password.
95
96 options
97 Optional hashref to specify DBI connect options
98
99 relationships
100 Try to automatically detect/setup has_a and has_many relationships.
101
102 inflect
103 An hashref, which contains exceptions to Lingua::EN::Inflect::PL().
104 Useful for foreign language column names.
105
106 user
107 Username.
108
109 require
110 Attempt to require the dynamically defined module, so that exten‐
111 sions defined in files. By default errors from imported modules are
112 suppressed. When you want to debug, use require_warn.
113
114 require_warn
115 Warn of import errors when requiring modules.
116
118 Daisuke Maki "dmaki@cpan.org"
119
121 Sebastian Riedel, "sri@oook.de" IKEBE Tomohiro, "ikebe@edge.co.jp"
122
124 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
125 Randal Schwartz, Simon Flack and all the others who've helped.
126
128 This library is free software; you can redistribute it and/or modify it
129 under the same terms as Perl itself.
130
132 Class::DBI, Class::DBI::mysql, Class::DBI::Pg, Class::DBI::SQLite,
133 Class::DBI::Loader::Generic, Class::DBI::Loader::mysql,
134 Class::DBI::Loader::Pg, Class::DBI::Loader::SQLite
135
136
137
138perl v5.8.8 2006-05-25 Class::DBI::Loader(3)