From 4d0bc1f1469fac58c4b215af2a5f9789a536a908 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 25 Mar 2014 13:47:42 +0100 Subject: [PATCH] cvar_as_hashref mixin, um cvars gut zu serialisieren --- SL/DB/Helper/CustomVariables.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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) = @_; -- 2.20.1