sub _permittedOps() { my ($this) = @_; # Hashes for mapping in order to avoid if-else chaining my (%attr_value, %high_type, %trust_level); # A map associating opcode sets with trust levels. %trust_level = (full => full_opset(), strong => opset(qw/:default :filesys_read :sys_db :filesys_open :filesys_write :ownprocess :subprocess/), normal => opset(qw/:default/), weak => opset(qw/:base_core :base_mem :base_loop :base_io :base_orig/), none => opset(qw/:base_core :base_loop/) ); # A map associating usertype attributes with positive/negative values # affecting the level of trust assigned to the user. %attr_value = (admin => 1, consultant => -1, editor => 0, former => -2, other => -2, programmer => 2, trainee => -1); # Run through all of the assigned usertypes, adjusting the trust level in %high_type # granted the user for each particular usertype. $1, if defined will be # 'former', $2 will be either 'consultant', 'editor', or 'programmer'. # $3, if defined, will be either 'admin' or 'trainee'. foreach my $type (@usertypes) { # @usertypes is defined in the real code, don't worry :) if ($type =~ /^(former)?\s?(consultant|editor|programmer)\s? (admin|trainee)?$/ix) { unless ($1) { # Look up the appropriate usertype and attribute values. $high_type{$2} += $attr_value{$2}; $high_type{$2} += $attr_value{$3} if $3; } else { $high_type{$2} += $attr_value{$1} } } else { $high_type{other} += $attr_value{other}; } } # Take the maximum trust available. my $max = pop(@{[sort values %high_type]}); # Return the appropriate opset. ($max > 1) and return $trust_level{full}; ($max == 1) and return $trust_level{strong}; ($max == 0) and return $trust_level{normal}; ($max == -1) and return $trust_level{weak}; ($max < -1) and return $trust_level{none}; }