| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::DBI::Loader; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
236710
|
use strict; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
194
|
|
|
4
|
4
|
|
|
4
|
|
24
|
use vars '$VERSION'; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
948
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.34'; |
|
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
|
|
|
|
|
|
|
require => 1 |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
my $class = $loader->find_class('film'); # $class => Data::Film |
|
32
|
|
|
|
|
|
|
my $obj = $class->retrieve(1); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use with mod_perl |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
in your startup.pl |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# load all tables |
|
39
|
|
|
|
|
|
|
use Class::DBI::Loader; |
|
40
|
|
|
|
|
|
|
my $loader = Class::DBI::Loader->new( |
|
41
|
|
|
|
|
|
|
dsn => "dbi:mysql:dbname", |
|
42
|
|
|
|
|
|
|
user => "root", |
|
43
|
|
|
|
|
|
|
password => "", |
|
44
|
|
|
|
|
|
|
namespace => "Data", |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
in your web application. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use strict; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# you can use Data::Film directly |
|
52
|
|
|
|
|
|
|
my $film = Data::Film->retrieve($id); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Class::DBI::Loader automate the definition of Class::DBI sub-classes. |
|
58
|
|
|
|
|
|
|
scan table schemas and setup columns, primary key. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
class names are defined by table names and namespace option. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
63
|
|
|
|
|
|
|
| table | namespace | class | |
|
64
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
65
|
|
|
|
|
|
|
| foo | Data | Data::Foo | |
|
66
|
|
|
|
|
|
|
| foo_bar | | FooBar | |
|
67
|
|
|
|
|
|
|
+-----------+-----------+-----------+ |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Class::DBI::Loader supports MySQL, Postgres and SQLite. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
See L. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
|
76
|
1
|
|
|
1
|
1
|
315176
|
my ( $class, %args ) = @_; |
|
77
|
1
|
|
|
|
|
6
|
my $dsn = $args{dsn}; |
|
78
|
1
|
|
|
|
|
90
|
my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i; |
|
79
|
1
|
50
|
|
|
|
10
|
$driver = 'SQLite' if $driver eq 'SQLite2'; |
|
80
|
1
|
|
|
|
|
6
|
my $impl = "Class::DBI::Loader::" . $driver; |
|
81
|
1
|
|
|
1
|
|
142
|
eval qq/use $impl/; |
|
|
1
|
|
|
|
|
1957
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
23
|
|
|
82
|
1
|
50
|
|
|
|
6
|
die qq/Couldn't require loader class "$impl", "$@"/ if $@; |
|
83
|
1
|
|
|
|
|
15
|
return $impl->new(%args); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 new %args |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item additional_base_classes |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
List of additional base classes your table classes will use. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item left_base_classes |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
List of additional base classes, that need to be leftmost, for |
|
99
|
|
|
|
|
|
|
example L (former L). |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item additional_classes |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
List of additional classes which your table classes will use. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item constraint |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Only load tables matching regex. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item exclude |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Exclude tables matching regex. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item debug |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Enable debug messages. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item dsn |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
DBI Data Source Name. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item namespace |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Namespace under which your table classes will be initialized. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item password |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Password. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item options |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Optional hashref to specify DBI connect options |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item relationships |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Try to automatically detect/setup has_a and has_many relationships. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item inflect |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
An hashref, which contains exceptions to Lingua::EN::Inflect::PL(). |
|
140
|
|
|
|
|
|
|
Useful for foreign language column names. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item user |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Username. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item require |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Attempt to require the dynamically defined module, so that extensions |
|
149
|
|
|
|
|
|
|
defined in files. By default errors from imported modules are suppressed. |
|
150
|
|
|
|
|
|
|
When you want to debug, use require_warn. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item require_warn |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Warn of import errors when requiring modules. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Daisuke Maki C |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR EMERITUS |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Sebastian Riedel, C |
|
165
|
|
|
|
|
|
|
IKEBE Tomohiro, C |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 THANK YOU |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, |
|
170
|
|
|
|
|
|
|
Randal Schwartz, Simon Flack and all the others who've helped. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 LICENSE |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
175
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L, L, L, L, |
|
180
|
|
|
|
|
|
|
L, L, |
|
181
|
|
|
|
|
|
|
L, L |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |