+    } elsif (($token eq "|") || ($token eq "&")) {
+      push @{$cur_ary}, $token;
+
+    } else {
+      push @{$cur_ary}, $auth->check_right($::myconfig{login}, $token, 1);
+    }
+  }
+
+  if ($access) {
+    $form->error("Error in menu.ini for entry ${key}: unrecognized token at the start of '$access'\n");
+  }
+
+  if (1 < scalar @stack) {
+    $main::form->error("Error in menu.ini for entry ${key}: Missing ')'\n");
+  }
+
+  return SL::Auth::evaluate_rights_ary($stack[0]);
+}
+
+sub parse_instance_conf_string {
+  my ($self, $setting) = @_;
+  return $::instance_conf->data->{$setting};
+}
+
+sub set_access {
+  my $self = shift;
+
+  my $key;
+
+  foreach $key (@{ $self->{ORDER} }) {
+    my $entry = $self->{$key};
+
+    $entry->{GRANTED}              = $entry->{ACCESS} ? $self->parse_access_string($key, $entry->{ACCESS}) : 1;
+    $entry->{GRANTED}            &&= $self->parse_instance_conf_string($entry->{INSTANCE_CONF}) if $entry->{INSTANCE_CONF};
+    $entry->{IS_MENU}              = $entry->{submenu} || ($key !~ m/--/);
+    $entry->{NUM_VISIBLE_CHILDREN} = 0;
+
+    if ($key =~ m/--/) {
+      my $parent = $key;
+      substr($parent, rindex($parent, '--')) = '';
+      $entry->{GRANTED} &&= $self->{$parent}->{GRANTED};
+    }
+
+    $entry->{VISIBLE} = $entry->{GRANTED};
+  }
+
+  foreach $key (reverse @{ $self->{ORDER} }) {
+    my $entry = $self->{$key};
+
+    if ($entry->{IS_MENU}) {
+      $entry->{VISIBLE} &&= $entry->{NUM_VISIBLE_CHILDREN} > 0;
+    }
+
+    next if (($key !~ m/--/) || !$entry->{VISIBLE});
+
+    my $parent = $key;
+    substr($parent, rindex($parent, '--')) = '';
+    $self->{$parent}->{NUM_VISIBLE_CHILDREN}++;
+  }
+
+#   $self->dump_visible();
+
+  $self->{ORDER} = [ grep { $self->{$_}->{VISIBLE} } @{ $self->{ORDER} } ];
+
+  { no strict 'refs';
+  # ToDO: fix this. nuke and pave algorithm without type checking screams for problems.
+  map { delete @{$self->{$_}}{qw(GRANTED IS_MENU NUM_VISIBLE_CHILDREN VISIBLE ACCESS)} if ($_ ne 'ORDER') } keys %{ $self };
+  }