From 5a7ae14c769710c1de947b115cf2cd0c38d3df7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 21 Jun 2013 18:08:37 +0200 Subject: [PATCH] CustomVariables: modules nicht mehr zur Compilezeit inferieren MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Um module zu inferieren müssen die Zielobjekte bekannt sein, das kann aber zu zirkulären Includes mitten im RDBO initialize führen. Nachlagern geht auch nicht, weil die Daten für relationships benötigt werden. Ohne also die Relationships tief ins RDBO auto_foreign_key Modell zu hacken, ist das Inferieren nicht möglich, deshalb erstmal manuell konfigurieren. --- SL/DB/DeliveryOrderItem.pm | 5 ++++- SL/DB/Helper/CustomVariables.pm | 20 +++++++++++--------- SL/DB/InvoiceItem.pm | 5 ++++- SL/DB/OrderItem.pm | 5 ++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/SL/DB/DeliveryOrderItem.pm b/SL/DB/DeliveryOrderItem.pm index d50a63ff4..3c5eef85c 100644 --- a/SL/DB/DeliveryOrderItem.pm +++ b/SL/DB/DeliveryOrderItem.pm @@ -7,7 +7,10 @@ use SL::DB::Helper::CustomVariables ( sub_module => 'delivery_order_item', cvars_alias => 1, overloads => { - parts_id => 'SL::DB::Part', + parts_id => { + class => 'SL::DB::Part', + module => 'IC', + } }, ); diff --git a/SL/DB/Helper/CustomVariables.pm b/SL/DB/Helper/CustomVariables.pm index c935cbae5..df90aa73b 100644 --- a/SL/DB/Helper/CustomVariables.pm +++ b/SL/DB/Helper/CustomVariables.pm @@ -4,7 +4,6 @@ use strict; use Carp; use Data::Dumper; use List::Util qw(first); -use SL::DB::CustomVariableConfig; use constant META_CVARS => 'cvars_config'; @@ -113,6 +112,9 @@ sub make_cvar_by_name { sub _all_configs { my (%params) = @_; + + require SL::DB::CustomVariableConfig; + $params{module} ? SL::DB::Manager::CustomVariableConfig->get_all(query => [ module => $params{module} ]) : SL::DB::Manager::CustomVariableConfig->get_all; @@ -122,8 +124,8 @@ sub _overload_by_module { my ($module, %params) = @_; keys %{ $params{overloads} }; # reset each iterator - while (my ($fk, $class) = each %{ $params{overloads} }) { - return ($fk, $class) if $class->meta->{META_CVARS()}->{module} eq $module; + while (my ($fk, $def) = each %{ $params{overloads} }) { + return ($fk, $def->{class}) if $def->{module} eq $module; } croak "unknown overload, cannot resolve module $module"; @@ -155,11 +157,8 @@ sub _calc_modules_from_overloads { my (%params) = @_; my %modules; - while (my ($fk, $class) = each %{ $params{overloads} }) { - eval "require $class"; # make sure the class is loaded - my $module = $class->meta->{META_CVARS()}->{module}; - next if ref $module; - $modules{$module} = 1; + for my $def (values %{ $params{overloads} || {} }) { + $modules{$def->{module}} = 1; } return [ keys %modules ]; @@ -200,7 +199,10 @@ SL::DB::Helper::CustomVariables - Mixin to provide custom variables relations sub_module => 'orderitems', cvars_alias => 1, overloads => { - parts_id => 'SL::DB::Part', + parts_id => { + class => 'SL::DB::Part', + module => 'IC', + } } ); diff --git a/SL/DB/InvoiceItem.pm b/SL/DB/InvoiceItem.pm index a4135fc4c..8f9a4dde7 100644 --- a/SL/DB/InvoiceItem.pm +++ b/SL/DB/InvoiceItem.pm @@ -7,7 +7,10 @@ use SL::DB::Helper::CustomVariables ( sub_module => 'invoice', cvars_alias => 1, overloads => { - parts_id => 'SL::DB::Part', + parts_id => { + class => 'SL::DB::Part', + module => 'IC', + }, }, ); diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 67bffd8ce..37520977b 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -10,7 +10,10 @@ use SL::DB::Helper::CustomVariables ( sub_module => 'orderitems', cvars_alias => 1, overloads => { - parts_id => 'SL::DB::Part', + parts_id => { + class => 'SL::DB::Part', + module => 'IC', + } }, ); -- 2.20.1