From: Sven Schöling Date: Tue, 25 Mar 2014 12:47:42 +0000 (+0100) Subject: cvar_as_hashref mixin, um cvars gut zu serialisieren X-Git-Tag: release-3.2.0beta~474 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=4d0bc1f1469fac58c4b215af2a5f9789a536a908;p=kivitendo-erp.git cvar_as_hashref mixin, um cvars gut zu serialisieren --- diff --git a/SL/DB/Helper/CustomVariables.pm b/SL/DB/Helper/CustomVariables.pm index 373a60cf1..839c49066 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,6 +126,24 @@ 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) = @_;