| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::DBI::Loader; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
48
|
use strict; |
|
|
3
|
|
|
|
|
43
|
|
|
|
3
|
|
|
|
|
50
|
|
|
4
|
3
|
|
|
3
|
|
45
|
use vars '$VERSION'; |
|
|
3
|
|
|
|
|
29
|
|
|
|
3
|
|
|
|
|
44
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.32'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::DBI::Loader - Dynamic definition of Class::DBI sub classes. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::DBI::Loader; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $loader = Class::DBI::Loader->new( |
|
17
|
|
|
|
|
|
|
dsn => "dbi:mysql:dbname", |
|
18
|
|
|
|
|
|
|
user => "root", |
|
19
|
|
|
|
|
|
|
password => "", |
|
20
|
|
|
|
|
|
|
options => { RaiseError => 1, AutoCommit => 0 }, |
|
21
|
|
|
|
|
|
|
namespace => "Data", |
|
22
|
|
|
|
|
|
|
additional_classes => qw/Class::DBI::AbstractSearch/, # or arrayref |
|
23
|
|
|
|
|
|
|
additional_base_classes => qw/My::Stuff/, # or arrayref |
|
24
|
|
|
|
|
|
|
left_base_classes => qw/Class::DBI::Sweet/, # or arrayref |
|
25
|
|
|
|
|
|
|
constraint => '^foo.*', |
|
26
|
|
|
|
|
|
|
relationships => 1, |
|
27
|
|
|
|
|
|
|
options => { AutoCommit => 1 }, |
|
28
|
|
|
|
|
|
|
inflect => { child => 'children' } |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
my $class = $loader->find_class('film'); # $class => Data::Film |
|
31
|
|
|
|
|
|
|
my $obj = $class->retrieve(1); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use with mod_perl |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
in your startup.pl |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# load all tables |
|
38
|
|
|
|
|
|
|
use Class::DBI::Loader; |
|
39
|
|
|
|
|
|
|
my $loader = Class::DBI::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
|
|
|
|
|
|
|
Class::DBI::Loader automate the definition of Class::DBI sub-classes. |
|
57
|
|
|
|
|
|
|
scan table schemas and setup columns, primary key. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
class names are defined by table names and namespace option. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
62
|
|
|
|
|
|
|
| table | namespace | class | |
|
63
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
64
|
|
|
|
|
|
|
| foo | Data | Data::Foo | |
|
65
|
|
|
|
|
|
|
| foo_bar | | FooBar | |
|
66
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Class::DBI::Loader supports MySQL, Postgres and SQLite. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
See L<Class::DBI::Loader::Generic>. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub new { |
|
75
|
0
|
|
|
0
|
1
|
|
my ( $class, %args ) = @_; |
|
76
|
0
|
|
|
|
|
|
my $dsn = $args{dsn}; |
|
77
|
0
|
|
|
|
|
|
my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i; |
|
78
|
0
|
0
|
|
|
|
|
$driver = 'SQLite' if $driver eq 'SQLite2'; |
|
79
|
0
|
|
|
|
|
|
my $impl = "Class::DBI::Loader::" . $driver; |
|
80
|
0
|
|
|
|
|
|
eval qq/use $impl/; |
|
81
|
0
|
0
|
|
|
|
|
die qq/Couldn't require loader class "$impl", "$@"/ if $@; |
|
82
|
0
|
|
|
|
|
|
return $impl->new(%args); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 new %args |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item additional_base_classes |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
List of additional base classes your table classes will use. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item left_base_classes |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
List of additional base classes, that need to be leftmost, for |
|
98
|
|
|
|
|
|
|
example L<Class::DBI::Sweet> (former L<Catalyst::Model::CDBI::Sweet>). |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item additional_classes |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
List of additional classes which your table classes will use. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item constraint |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Only load tables matching regex. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item exclude |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Exclude tables matching regex. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item debug |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Enable debug messages. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item dsn |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
DBI Data Source Name. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item namespace |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Namespace under which your table classes will be initialized. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item password |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Password. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item options |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Optional hashref to specify DBI connect options |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item relationships |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Try to automatically detect/setup has_a and has_many relationships. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item inflect |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
An hashref, which contains exceptions to Lingua::EN::Inflect::PL(). |
|
139
|
|
|
|
|
|
|
Useful for foreign language column names. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item user |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Username. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Daisuke Maki C<dmaki@cpan.org> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR EMERITUS |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Sebastian Riedel, C<sri@oook.de> |
|
154
|
|
|
|
|
|
|
IKEBE Tomohiro, C<ikebe@edge.co.jp> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 THANK YOU |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, |
|
159
|
|
|
|
|
|
|
Randal Schwartz, Simon Flack and all the others who've helped. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 LICENSE |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
164
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<Class::DBI>, L<Class::DBI::mysql>, L<Class::DBI::Pg>, L<Class::DBI::SQLite>, |
|
169
|
|
|
|
|
|
|
L<Class::DBI::Loader::Generic>, L<Class::DBI::Loader::mysql>, |
|
170
|
|
|
|
|
|
|
L<Class::DBI::Loader::Pg>, L<Class::DBI::Loader::SQLite> |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
|
175
|
|
|
|
|
|
|
|