line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bigtop::Backend::Model; |
2
|
1
|
|
|
1
|
|
5
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use Bigtop::Keywords; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
7
|
|
|
|
|
|
|
# Register keywords in the grammar |
8
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
9
|
Bigtop::Parser->add_valid_keywords( |
12
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
13
|
|
|
|
|
|
|
'table', |
14
|
|
|
|
|
|
|
'foreign_display', |
15
|
|
|
|
|
|
|
'model_base_class', |
16
|
|
|
|
|
|
|
) |
17
|
|
|
|
|
|
|
); |
18
|
1
|
|
|
|
|
11
|
Bigtop::Parser->add_valid_keywords( |
19
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
20
|
|
|
|
|
|
|
'field', |
21
|
|
|
|
|
|
|
'non_essential', |
22
|
|
|
|
|
|
|
) |
23
|
|
|
|
|
|
|
); |
24
|
1
|
|
|
|
|
6
|
Bigtop::Parser->add_valid_keywords( |
25
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
26
|
|
|
|
|
|
|
'join_table', |
27
|
|
|
|
|
|
|
'joins', |
28
|
|
|
|
|
|
|
'names', |
29
|
|
|
|
|
|
|
) |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package # table_block |
34
|
|
|
|
|
|
|
table_block; |
35
|
1
|
|
|
1
|
|
5
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
299
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _build_foreign_display_body { |
38
|
0
|
|
|
0
|
|
|
my $foreign_display = shift; |
39
|
0
|
|
|
|
|
|
my @field_names = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $retval; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
foreach my $field ( @field_names ) { |
44
|
0
|
|
|
|
|
|
$retval .= ' ' x 4 . "my \$$field = \$self->$field() || '';\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$retval .= "\n"; |
48
|
0
|
|
|
|
|
|
$foreign_display =~ s{%([\d\w_]+)}{\$$1}g; |
49
|
0
|
|
|
|
|
|
$retval .= " return \"$foreign_display\";\n"; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $retval; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# table_element_block |
55
|
|
|
|
|
|
|
package # table_element_block |
56
|
|
|
|
|
|
|
table_element_block; |
57
|
1
|
|
|
1
|
|
6
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
144
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _not_for_model { |
60
|
0
|
|
|
0
|
|
|
my $field = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( $field->{not_for} ) { |
63
|
0
|
|
|
|
|
|
my $skipped_backends = $field->{not_for}{args}; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
foreach my $skipped_backend ( @{ $skipped_backends } ) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
return 1 if ( $skipped_backend eq 'Model' ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Bigtop::Backend::Model - defines legal keywords in table and field blocks |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
If you are making a Model generating backend: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use Bigtop::Backend::Model; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This specifies the valid keywords for the Model generating backend. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
If you need additional keywords which are generally useful, add them |
88
|
|
|
|
|
|
|
here (and send in a patch). If you need backend specific keywords, register |
89
|
|
|
|
|
|
|
them within your backend module. Note that only keywords affecting |
90
|
|
|
|
|
|
|
the model should be put here. But, fields have other keywords which |
91
|
|
|
|
|
|
|
affect things like what SQL represents them and how they look in html |
92
|
|
|
|
|
|
|
forms. Register those keywords in Bigtop::SQL:: or Bigtop::Control:: modules. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
If you are using a Bigtop backend which generates models, you should |
97
|
|
|
|
|
|
|
read this document to find out what the valid keywords inside table |
98
|
|
|
|
|
|
|
and field blocks are. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If you are writing a Bigtop backend to generate models, you should use |
101
|
|
|
|
|
|
|
this module. That will register the standard table and field keywords |
102
|
|
|
|
|
|
|
with the Bigtop parser. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 BASIC STRUCTURE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
A bigtop app block could look like this: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
app name { |
109
|
|
|
|
|
|
|
table name { |
110
|
|
|
|
|
|
|
field name { |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 TABLE KEYWORDS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Tables can be field blocks. They can also have these simple statements: |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item foreign_display |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Inside the table, you can include a foreign_display statement. The |
124
|
|
|
|
|
|
|
value must be a quoted string like this: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
foreign_display `%last_name, %first_name`; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Any percent and the Perl identifier after it will be replaced with the |
129
|
|
|
|
|
|
|
current row's values for those columns. This is useful when a model |
130
|
|
|
|
|
|
|
needs to deliver a user meaningful value for the current row. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item model_base_class |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This becomes the base class of the model module for this table. |
135
|
|
|
|
|
|
|
Each backend has a default base model, but setting this overrides it. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 FIELD KEYWORDS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item non_essential |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Inside the field you may include non_essential. If it has a true value, |
146
|
|
|
|
|
|
|
the column will not be considered essential. This usually means that it |
147
|
|
|
|
|
|
|
will not be fetched when a row is retrieved from the database, unless |
148
|
|
|
|
|
|
|
its accessor is directly called. By default, all fields are considered |
149
|
|
|
|
|
|
|
essential. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 OTHER KEYWORDS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The main Bigtop::Parser registers not_for simple statements for tables |
156
|
|
|
|
|
|
|
and fields. You can use them like this: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
table something_that_needs_no_model { |
159
|
|
|
|
|
|
|
not_for Model; |
160
|
|
|
|
|
|
|
... |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This will generate the SQL for the table (if you are using an SQL |
164
|
|
|
|
|
|
|
backend), but not the Model. The same goes for this: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
table normal_but_with_strange_field { |
167
|
|
|
|
|
|
|
field confusing_to_CDBI { |
168
|
|
|
|
|
|
|
is int4; |
169
|
|
|
|
|
|
|
not_for Model; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 AUTHOR |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Phil Crow |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENSE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Copyright (C) 2005 by Phil Crow |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
182
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
183
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |