X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/42ca4b6790baf76f507cc3675f4a171223cfde4c..cd3150ed14f13bc1af071dd0f91015dd32360eae:/SL/DB/Helper/CustomVariables.pm diff --git a/SL/DB/Helper/CustomVariables.pm b/SL/DB/Helper/CustomVariables.pm index 373a60cf1..6f470357d 100644 --- a/SL/DB/Helper/CustomVariables.pm +++ b/SL/DB/Helper/CustomVariables.pm @@ -26,6 +26,7 @@ sub import { make_cvar_alias($caller_package, %params) if $params{cvars_alias}; make_cvar_by_configs($caller_package, %params); make_cvar_by_name($caller_package, %params); + make_cvar_as_hashref($caller_package, %params); } sub save_meta_info { @@ -125,14 +126,30 @@ sub make_cvar_by_name { } } +sub make_cvar_as_hashref { + my ($caller_package, %params) = @_; + + no strict 'refs'; + *{ $caller_package . '::cvar_as_hashref' } = sub { + my ($self) = @_; + @_ > 1 and croak "not an accessor"; + + my $cvars_by_config = $self->cvars_by_config; + + my %return = map { + $_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid } + } @$cvars_by_config; + + return \%return; + } +} + 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; + SL::DB::Manager::CustomVariableConfig->get_all_sorted($params{module} ? (query => [ module => $params{module} ]) : ()); } sub _overload_by_module { @@ -248,6 +265,11 @@ Secondary classes may currently not have cvars of their own. This is a Rose::DB::Object::Relationship accessor, generated for cvars. Use it like any other OneToMany relationship. +Note that unlike L this accessor only returns +variables that have already been created for this object. No variables +will be autovivified for configs for which no variable has been +created yet. + =item C Alias to C. Will only be installed if C was @@ -292,6 +314,7 @@ vivified with the same rules as in C. =head1 AUTHOR -Sven Schöling Es.schoeling@linet-services.deE +Sven Schöling Es.schoeling@linet-services.deE, +Moritz Bunkus Em.bunkus@linet-services.deE =cut