1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
4 package SL::DB::CustomVariableConfig;
8 use List::MoreUtils qw(any);
10 use SL::DB::MetaSetup::CustomVariableConfig;
11 use SL::DB::Manager::CustomVariableConfig;
12 use SL::DB::Helper::ActsAsList;
14 __PACKAGE__->meta->initialize;
16 __PACKAGE__->configure_acts_as_list(group_by => [qw(module)]);
22 push @errors, $::locale->text('The name is missing.') if !$self->name;
23 push @errors, $::locale->text('The description is missing.') if !$self->description;
24 push @errors, $::locale->text('The type is missing.') if !$self->type;
25 push @errors, $::locale->text('The option field is empty.') if (($self->type || '') eq 'select') && !$self->options;
30 use constant OPTION_DEFAULTS =>
37 sub processed_options {
40 if( exists($self->{processed_options_cache}) ) {
41 return $self->{processed_options_cache};
44 my $ops = $self->options;
47 if ( $self->type eq 'select' ) {
48 my @op_array = split('##', $ops);
52 $ret = {%{$self->OPTION_DEFAULTS}};
53 while ( $ops =~ /\s*([^=\s]+)\s*=\s*([^\s]*)(?:\s*|$)/g ) {
58 $self->{processed_options_cache} = $ret;
66 if( exists($self->{processed_flags_cache}) ) {
67 return $self->{processed_flags_cache};
70 my $flags = $self->flags;
73 foreach my $flag (split m/:/, $flags) {
74 if ( $flag =~ m/(.*?)=(.*)/ ) {
81 $self->{processed_flags_cache} = $ret;
87 my ($self, $flag) = @_;
89 return $self->processed_flags()->{$flag};
92 sub type_dependent_default_value {
95 return $self->default_value if $self->type ne 'select';
96 return (any { $_ eq $self->default_value } @{ $self->processed_options }) ? $self->default_value : $self->processed_options->[0];