line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::NinjaORM::Schema::Table; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
45761
|
use strict; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
245
|
|
4
|
9
|
|
|
9
|
|
34
|
use warnings; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
223
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
37
|
use Carp; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
551
|
|
7
|
9
|
|
|
9
|
|
3874
|
use DBIx::Inspector; |
|
9
|
|
|
|
|
85684
|
|
|
9
|
|
|
|
|
4306
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
DBIx::NinjaORM::Schema::Table - Store information about a table used by L. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 3.1.0 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '3.1.0'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
L currently uses L to retrieve |
27
|
|
|
|
|
|
|
various information about the tables used. This may however change in the |
28
|
|
|
|
|
|
|
future, so this package encapsulates various functions to make it easier to |
29
|
|
|
|
|
|
|
replace the dependencies and internals later if needed. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use DBIx::NinjaORM::Schema::Table; |
35
|
|
|
|
|
|
|
my $table_schema = DBIx::NinjaORM::Schema::Table->new( |
36
|
|
|
|
|
|
|
dbh => $dbh, |
37
|
|
|
|
|
|
|
name => $name, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $column_names = $table_schema->get_column_names(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 new() |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Create a new DBIx::NinjaORM::Schema::Table object. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $table_schema = DBIx::NinjaORM::Schema::Table->new( |
50
|
|
|
|
|
|
|
dbh => $dbh, |
51
|
|
|
|
|
|
|
name => $name, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Arguments: |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item * dbh (mandatory) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The database handle to use to access the table. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * name (mandatory) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The name of the table. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=back |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new |
71
|
|
|
|
|
|
|
{ |
72
|
10
|
|
|
10
|
1
|
74149
|
my ( $class, %args ) = @_; |
73
|
10
|
|
|
|
|
26
|
my $name = delete( $args{'name'} ); |
74
|
10
|
|
|
|
|
23
|
my $dbh = delete( $args{'dbh'} ); |
75
|
10
|
50
|
|
|
|
50
|
croak 'The following arguments are not valid: ' . join( ', ', keys %args ) |
76
|
|
|
|
|
|
|
if scalar( keys %args ) != 0; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Check for the mandatory parameters. |
79
|
10
|
100
|
|
|
|
48
|
croak 'The argument "name" is mandatory' |
80
|
|
|
|
|
|
|
if !defined( $name ); |
81
|
9
|
100
|
|
|
|
51
|
croak 'The argument "dbh" is mandatory' |
82
|
|
|
|
|
|
|
if !defined( $dbh ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Return a blessed object. |
85
|
8
|
|
|
|
|
72
|
return bless( |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
name => $name, |
88
|
|
|
|
|
|
|
dbh => $dbh, |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
$class, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 get_name() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Return the table name. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $table_name = $table_schema->get_name(); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_name |
104
|
|
|
|
|
|
|
{ |
105
|
5
|
|
|
5
|
1
|
11
|
my ( $self ) = @_; |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
34
|
return $self->{'name'}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 get_dbh() |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Return the database handle associated with the table. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $dbh = $table_schema->get_dbh(); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get_dbh |
120
|
|
|
|
|
|
|
{ |
121
|
6
|
|
|
6
|
1
|
11
|
my ( $self ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
6
|
|
|
|
|
45
|
return $self->{'dbh'}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 get_column_names() |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Return the name of the columns that exist in the underlying table. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $column_names = $table_schema->get_column_names(); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub get_column_names |
136
|
|
|
|
|
|
|
{ |
137
|
1
|
|
|
1
|
1
|
34
|
my ( $self ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
4
|
my $columns = $self->get_columns(); |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
3
|
return [ map { $_->name() } @$columns ]; |
|
6
|
|
|
|
|
16
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Warning: the API for the internal methods may change in the future. Use or |
148
|
|
|
|
|
|
|
subclass with caution. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 get_inspector() |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Return a cached L. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $inspector = $table_schema->get_inspector(); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub get_inspector |
160
|
|
|
|
|
|
|
{ |
161
|
5
|
|
|
5
|
1
|
39
|
my ( $self ) = @_; |
162
|
|
|
|
|
|
|
|
163
|
5
|
50
|
|
|
|
18
|
if ( !defined( $self->{'inspector'} ) ) |
164
|
|
|
|
|
|
|
{ |
165
|
5
|
|
|
|
|
28
|
$self->{'inspector'} = DBIx::Inspector->new( dbh => $self->get_dbh() ); |
166
|
|
|
|
|
|
|
croak 'Failed to create the DBIx::Inspector object' |
167
|
5
|
50
|
|
|
|
12522
|
if !defined( $self->{'inspector'} ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
5
|
|
|
|
|
27
|
return $self->{'inspector'}; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 get_table() |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Return the cached L object associated with the |
177
|
|
|
|
|
|
|
underlying table. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $table = $table_schema->get_table(); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub get_table |
184
|
|
|
|
|
|
|
{ |
185
|
4
|
|
|
4
|
1
|
37
|
my ( $self ) = @_; |
186
|
|
|
|
|
|
|
|
187
|
4
|
50
|
|
|
|
39
|
if ( !defined( $self->{'table'} ) ) |
188
|
|
|
|
|
|
|
{ |
189
|
4
|
|
|
|
|
13
|
my $inspector = $self->get_inspector(); |
190
|
4
|
|
|
|
|
19
|
$self->{'table'} = $inspector->table( |
191
|
|
|
|
|
|
|
$self->get_name() |
192
|
|
|
|
|
|
|
); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
croak 'Failed to retrieve the table object' |
195
|
4
|
50
|
|
|
|
5557
|
if !defined( $self->{'table'} ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
4
|
|
|
|
|
39
|
return $self->{'table'}; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 get_columns() |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Return the cached arrayref of L objects corresponding |
204
|
|
|
|
|
|
|
to the columns of the underlying table. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
my $columns = $table_schema->get_columns(); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub get_columns |
211
|
|
|
|
|
|
|
{ |
212
|
3
|
|
|
3
|
1
|
36
|
my ( $self ) = @_; |
213
|
|
|
|
|
|
|
|
214
|
3
|
50
|
|
|
|
17
|
if ( !defined( $self->{'columns'} ) ) |
215
|
|
|
|
|
|
|
{ |
216
|
3
|
|
|
|
|
11
|
my $table = $self->get_table(); |
217
|
3
|
|
|
|
|
14
|
$self->{'columns'} = [ $table->columns() ]; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
3
|
|
|
|
|
10348
|
return $self->{'columns'}; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 BUGS |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
227
|
|
|
|
|
|
|
L. |
228
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
229
|
|
|
|
|
|
|
your bug as I make changes. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 SUPPORT |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
perldoc DBIx::NinjaORM::Schema::Table |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
You can also look for information at: |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=over 4 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item * GitHub's request tracker |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
L |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
L |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item * CPAN Ratings |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
L |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * MetaCPAN |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
L |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=back |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 AUTHOR |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Guillaume Aubert, C<< >>. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Copyright 2009-2017 Guillaume Aubert. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
272
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
275
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
276
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
1; |