% $m->call_next;
<%once>
  # FIXME: move this to Apache handler?
  use URI;
  use OpenXPKI::Client::HTML::Mason;
  use OpenXPKI::Client::HTML::Mason::Javascript;
  use OpenXPKI::Client::HTML::Mason::Menu;
  use OpenXPKI::i18n qw( i18nGettext set_language get_language set_locale_prefix );
  use OpenXPKI::DN;
  use English;
  use Data::Dumper;

  if (defined $ENV{OPENXPKI_LOCALE_PREFIX}) {
    set_locale_prefix($ENV{OPENXPKI_LOCALE_PREFIX});
  }
  $context->{socket_file} = $ENV{OPENXPKI_SOCKET_FILE};

  if (defined $ENV{OPENXPKI_DEBUG_FILE}) {
    open $context->{debugfh}, ">>", $ENV{OPENXPKI_DEBUG_FILE};
  }
  $context->{debug}       = sub {
    my $arg = shift;
    my $fh = $context->{debugfh};
    if (defined $fh) {
      local $OUTPUT_AUTOFLUSH = 1;
      print $fh $arg . "\n";
    }
  };

  # guard against XSS attacks
  $m->interp->set_escape(
    h => \&HTML::Mason::Escapes::basic_html_escape,
  );
  
  if (exists $ENV{MOD_PERL} and $ENV{MOD_PERL})
  {
    ## script is operated by apache with mod_perl
    eval "use Apache::Util;";
  } else {
    ## script runs without mod_perl
    eval "use HTML::Entities;";
  }
  die $EVAL_ERROR if ($EVAL_ERROR);
</%once>

<%init>
</%init>

<%flags>
  # this is the toplevel handler
  inherit => undef
</%flags>

