[- package Kwiki::Embperl ; use Kwiki -base; use Data::Dumper ; sub get_new_hub { my $self = shift ; my $path = shift; chdir $path; my $hub = $self->new->debug->load_hub( "config.yaml", -plugins => "plugins", ); return $hub; } sub run { my $epreq = shift ; my $self = __PACKAGE__ ; my $path = $epreq -> {config}{root} . '/eg/kwiki' ; # set path for source of Kwiki's redirect url $ENV{SCRIPT_NAME} .= $ENV{PATH_INFO} ; $ENV{PATH_INFO} = '' ; if (my $user = $epreq -> {user_name} || $epreq -> {user_email}) { $user =~ s/(?:^|\s+|\W)(.)/uc($1)/ge ; $user =~ s/[^a-zA-Z0-9]//g ; $ENV{REMOTE_USER} = $user ; } require CGI ; foreach my $k (keys %Embperl::fdat) { CGI::param($k, $Embperl::fdat{$k}) ; } my $hub = $self->get_new_hub($path); $hub->registry->load; $hub->add_hooks; eval { $hub->pre_process } or return $self->print_error($@,$r,$hub,'Pre-Process Error'); my $html = eval { $hub->process }; return $self->print_error($@,$r,$hub,'Process Error') if $@; if (defined $html) { unless($Embperl::req_rec->header_only) { $self->utf8_encode($html); } } eval { $hub->post_process } or return $self->print_error($@,$r,$hub,'Post-Process Error'); if (my $redir = $hub->headers->redirect) { print STDERR "redir to $redir" ; $Embperl::http_headers_out{'Location'} = $redir ; } return $html ; } sub print_error { my $self = shift ; my $error = $self->html_escape(shift); my ($r,$hub,$msg) = @_; #$hub->headers->content_type('text/html'); #$hub->headers->charset('UTF-8'); #$hub->headers->expires('now'); #$hub->headers->pragma('no-cache'); #$hub->headers->cache_control('no-cache'); #$hub->headers->redirect(''); #$hub->headers->print; print STDERR "

Software Error:

$msg

\n$error
" ; return "

Software Error:

$msg

\n$error
"; } -] [+ do { local $escmode = 0 ; my $html = Kwiki::Embperl::run ($epreq) ; $html =~ m#(.*)#s ; $1 || $html ; } +] [# #]