From 5b1e6c5a823825f0de7e002113f7663bc6188205 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Fri, 3 May 2013 15:54:30 +0200 Subject: [PATCH] =?utf8?q?CVar-Accessor=20f=C3=BCr=20Optionen=20und=20Flag?= =?utf8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/CustomVariableConfig.pm | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/SL/DB/CustomVariableConfig.pm b/SL/DB/CustomVariableConfig.pm index fd247d827..203f83a90 100644 --- a/SL/DB/CustomVariableConfig.pm +++ b/SL/DB/CustomVariableConfig.pm @@ -25,4 +25,66 @@ sub validate { return @errors; } +use constant OPTION_DEFAULTS => + { + MAXLENGTH => 75, + WIDTH => 30, + HEIGHT => 5, + }; + +sub processed_options { + my ($self) = @_; + + if( exists($self->{processed_options_cache}) ) { + return $self->{processed_options_cache}; + } + + my $ops = $self->options; + my $ret; + + if ( $self->type eq 'select' ) { + my @op_array = split('##', $ops); + $ret = \@op_array; + } + else { + $ret = {%{$self->OPTION_DEFAULTS}}; + while ( $ops =~ /\s*([^=\s]+)\s*=\s*([^\s]*)(?:\s*|$)/g ) { + $ret->{$1} = $2; + } + } + + $self->{processed_options_cache} = $ret; + + return $ret; +} + +sub processed_flags { + my ($self) = @_; + + if( exists($self->{processed_flags_cache}) ) { + return $self->{processed_flags_cache}; + } + + my $flags = $self->flags; + my $ret; + + foreach my $flag (split m/:/, $flags) { + if ( $flag =~ m/(.*?)=(.*)/ ) { + $ret->{$1} = $2; + } else { + $ret->{$flag} = 1; + } + } + + $self->{processed_flags_cache} = $ret; + + return $ret; +} + +sub has_flag { + my ($self, $flag) = @_; + + return $self->processed_flags()->{$flag}; +} + 1; -- 2.20.1