From 5f14641b419c6319d363d775a9ba27e7c3e9837f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 9 Jul 2013 09:19:46 +0200 Subject: [PATCH] rose_auto_create_model: Manager-Datei erstellen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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). --- scripts/rose_auto_create_model.pl | 49 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index 42af25a5b..1f1245378 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -40,7 +40,8 @@ $script =~ s:.*/::; $OUTPUT_AUTOFLUSH = 1; $Data::Dumper::Sortkeys = 1; -our $meta_path = "SL/DB/MetaSetup"; +our $meta_path = "SL/DB/MetaSetup"; +our $manager_path = "SL/DB/Manager"; my %config; @@ -78,7 +79,9 @@ sub setup { usage(); } - mkdir $meta_path unless -d $meta_path; + foreach (($meta_path, $manager_path)) { + mkdir $_ unless -d; + } } sub process_table { @@ -89,6 +92,7 @@ sub process_table { my $package = ucfirst($spec[1] || $spec[0]); $package =~ s/_+(.)/uc($1)/ge; my $meta_file = "${meta_path}/${package}.pm"; + my $mngr_file = "${manager_path}/${package}.pm"; my $file = "SL/DB/${package}.pm"; my $schema_str = $schema ? <meta->initialize; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; - 1; CODE @@ -197,14 +199,39 @@ CODE notice("File '$meta_file' " . ($file_exists ? 'updated' : 'created') . " for table '$table'"); - if (! -f $file) { - if (!$config{nocommit}) { - open my $out, ">", $file || die; - print $out $meta_definition; - } + return if -f $file; + + if (!$config{nocommit}) { + open my $out, ">", $file || die; + print $out $meta_definition; + } + + notice("File '$file' created as well."); + + return if -f $mngr_file; + + if (!$config{nocommit}) { + open my $out, ">", $mngr_file || die; + print $out <make_manager_methods; + +1; +EOT } + + notice("File '$mngr_file' created as well."); } sub parse_args { -- 2.20.1