Revision 5f14641b
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
scripts/rose_auto_create_model.pl | ||
---|---|---|
40 | 40 |
$OUTPUT_AUTOFLUSH = 1; |
41 | 41 |
$Data::Dumper::Sortkeys = 1; |
42 | 42 |
|
43 |
our $meta_path = "SL/DB/MetaSetup"; |
|
43 |
our $meta_path = "SL/DB/MetaSetup"; |
|
44 |
our $manager_path = "SL/DB/Manager"; |
|
44 | 45 |
|
45 | 46 |
my %config; |
46 | 47 |
|
... | ... | |
78 | 79 |
usage(); |
79 | 80 |
} |
80 | 81 |
|
81 |
mkdir $meta_path unless -d $meta_path; |
|
82 |
foreach (($meta_path, $manager_path)) { |
|
83 |
mkdir $_ unless -d; |
|
84 |
} |
|
82 | 85 |
} |
83 | 86 |
|
84 | 87 |
sub process_table { |
... | ... | |
89 | 92 |
my $package = ucfirst($spec[1] || $spec[0]); |
90 | 93 |
$package =~ s/_+(.)/uc($1)/ge; |
91 | 94 |
my $meta_file = "${meta_path}/${package}.pm"; |
95 |
my $mngr_file = "${manager_path}/${package}.pm"; |
|
92 | 96 |
my $file = "SL/DB/${package}.pm"; |
93 | 97 |
|
94 | 98 |
my $schema_str = $schema ? <<CODE : ''; |
... | ... | |
166 | 170 |
use strict; |
167 | 171 |
|
168 | 172 |
use SL::DB::MetaSetup::${package}; |
173 |
use SL::DB::Manager::${package}; |
|
169 | 174 |
|
170 | 175 |
__PACKAGE__->meta->initialize; |
171 | 176 |
|
172 |
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. |
|
173 |
__PACKAGE__->meta->make_manager_class; |
|
174 |
|
|
175 | 177 |
1; |
176 | 178 |
CODE |
177 | 179 |
|
... | ... | |
197 | 199 |
|
198 | 200 |
notice("File '$meta_file' " . ($file_exists ? 'updated' : 'created') . " for table '$table'"); |
199 | 201 |
|
200 |
if (! -f $file) { |
|
201 |
if (!$config{nocommit}) { |
|
202 |
open my $out, ">", $file || die; |
|
203 |
print $out $meta_definition; |
|
204 |
} |
|
202 |
return if -f $file; |
|
203 |
|
|
204 |
if (!$config{nocommit}) { |
|
205 |
open my $out, ">", $file || die; |
|
206 |
print $out $meta_definition; |
|
207 |
} |
|
208 |
|
|
209 |
notice("File '$file' created as well."); |
|
210 |
|
|
211 |
return if -f $mngr_file; |
|
212 |
|
|
213 |
if (!$config{nocommit}) { |
|
214 |
open my $out, ">", $mngr_file || die; |
|
215 |
print $out <<EOT; |
|
216 |
# This file has been auto-generated only because it didn't exist. |
|
217 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
218 |
|
|
219 |
package SL::DB::Manager::${package}; |
|
220 |
|
|
221 |
use strict; |
|
205 | 222 |
|
206 |
notice("File '$file' created as well."); |
|
223 |
use SL::DB::Helper::Manager; |
|
224 |
use base qw(SL::DB::Helper::Manager); |
|
225 |
|
|
226 |
sub object_class { 'SL::DB::${package}' } |
|
227 |
|
|
228 |
__PACKAGE__->make_manager_methods; |
|
229 |
|
|
230 |
1; |
|
231 |
EOT |
|
207 | 232 |
} |
233 |
|
|
234 |
notice("File '$mngr_file' created as well."); |
|
208 | 235 |
} |
209 | 236 |
|
210 | 237 |
sub parse_args { |
Auch abrufbar als: Unified diff
rose_auto_create_model: Manager-Datei erstellen
Anstatt in der SL/DB/XYZ.pm mit "make_manager_class" den Manager
erstellen zu lassen, wird nun explizit die Datei SL/DB/Manager/XYZ.pm
erstellt und eingebunden. Macht es einfacher, den Manager später zu
erweitern.
Der Manager wird nur angelegt, wenn weder er noch das DB-File
existieren (weiterhin wird nur MetaSetup immer aktualisiert).