line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::DB::Object::Std::Metadata; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use Carp(); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
973
|
use Rose::DB::Object::Metadata::PrimaryKey; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
2442
|
use Rose::DB::Object::Metadata; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
539
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Rose::DB::Object::Metadata); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init_primary_key |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
0
|
|
Rose::DB::Object::Metadata::PrimaryKey->new(parent => shift, columns => 'id'); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
0
|
1
|
|
sub primary_key_column_names { wantarray ? 'id' : [ 'id' ] } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub add_primary_key_column |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
0
|
0
|
0
|
1
|
|
Carp::croak __PACKAGE__, " objects are required to have a single primary key named 'id'" |
|
|
|
0
|
|
|
|
|
24
|
|
|
|
|
|
|
unless((ref $_[1] && $_[1][0] eq 'id') || $_[1] eq 'id'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# No point in doing this... |
27
|
|
|
|
|
|
|
#shift->SUPER::add_primary_key(@_); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
*add_primary_key_columns = \&add_primary_key_columns; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
0
|
|
sub generate_primary_key_placeholders { shift; shift->generate_primary_key_placeholders(@_) } |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub initialize |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $id_column = $self->column('id'); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
unless($id_column) |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
|
|
|
$self->add_column(id => { primary_key => 1 }); |
43
|
0
|
|
|
|
|
|
$id_column = $self->column('id'); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->SUPER::initialize(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Rose::DB::Object::Std::Metadata - Standardized database object metadata. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use Rose::DB::Object::Std::Metadata; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$meta = Rose::DB::Object::Std::Metadata->new(class => 'Product'); |
62
|
|
|
|
|
|
|
# ...or... |
63
|
|
|
|
|
|
|
# $meta = Rose::DB::Object::Std::Metadata->for_class('Product'); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$meta->table('products'); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$meta->columns |
68
|
|
|
|
|
|
|
( |
69
|
|
|
|
|
|
|
id => { type => 'int', primary_key => 1 }, |
70
|
|
|
|
|
|
|
name => { type => 'varchar', length => 255 }, |
71
|
|
|
|
|
|
|
description => { type => 'text' }, |
72
|
|
|
|
|
|
|
category_id => { type => 'int' }, |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
status => |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
type => 'varchar', |
77
|
|
|
|
|
|
|
check_in => [ 'active', 'inactive' ], |
78
|
|
|
|
|
|
|
default => 'inactive', |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
start_date => { type => 'datetime' }, |
82
|
|
|
|
|
|
|
end_date => { type => 'datetime' }, |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
date_created => { type => 'timestamp', default => 'now' }, |
85
|
|
|
|
|
|
|
last_modified => { type => 'timestamp', default => 'now' }, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$meta->add_unique_key('name'); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$meta->foreign_keys |
91
|
|
|
|
|
|
|
( |
92
|
|
|
|
|
|
|
category => |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
class => 'Category', |
95
|
|
|
|
|
|
|
key_columns => |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
category_id => 'id', |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
}, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
... |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
C<Rose::DB::Object::Std::Metadata> is a subclass of L<Rose::DB::Object::Metadata> that is designed to serve the needs of L<Rose::DB::Object::Std> objects. See the L<Rose::DB::Object::Std> documentations for information on what differentiates it from L<Rose::DB::Object>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Only the methods that are overridden are documented here. See the L<Rose::DB::Object::Metadata> documentation for the rest. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B<add_primary_key_column COLUMN> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This method is an alias for the C<add_primary_key_columns()> method. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<add_primary_key_columns COLUMNS> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Since L<Rose::DB::Object::Std> objects must have a single primary key column named "id", calling this method with a COLUMNS argument of anything other than the column name "id" or a reference to an array containing the column name "id" will cause a fatal error. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
In general, you do not need to use this method at all since the C<primary_key_columns()> method is hard-coded to always return "id". |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item B<initialize [ARGS]> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This method does the same thing as the L<Rose::DB::Object::Metadata> method of the same name, with one exception. If there is no column named "id" in the list of columns, a scalar primary key column named "id" is added to the column list. Then initialization proceeds as usual. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item B<primary_key_columns> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Always returns the column name "id" (in list context) or a reference to an array containing the column name "id" (in scalar context). |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is |
141
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same terms |
142
|
|
|
|
|
|
|
as Perl itself. |