#!/usr/bin/perl -wT
BEGIN {
    # Set default current working directory (needed for mod_perl)
    if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~ /^(.+)\/[^\/]+$/ ) {
        chdir $1;
    }
    # Set library paths in @INC, at compile time
    unshift @INC, '.';
    require 'setlib.cfg';
}

use strict;
use CGI::Carp qw( fatalsToBrowser );
use CGI;

use Benchmark qw(:all :hireswallclock);
use Storable;

my $query;
my $fh;
if( $ENV{'DOCUMENT_ROOT'} ) {
    # script is called by browser
    $query = new CGI;

    Storable::lock_store($query, '/tmp/twiki_bm.cgi') || die "Store failed";
} else {
    $query = Storable::lock_retrieve('/tmp/twiki_bm.cgi') || die "Retrieve failed";
}

my $begin = new Benchmark;

use TWiki::UI::View;

my $thePathInfo = $query->path_info(); 
my $theRemoteUser = $query->remote_user();
my $theTopic = $query->param( 'topic' );
my $theUrl = $query->url;

my( $topic, $webName, $scriptUrlPath, $userName ) = 
  TWiki::initialize( $thePathInfo, $theRemoteUser,
                     $theTopic, $theUrl, $query );

my $middle = new Benchmark;

TWiki::UI::View::view( $webName, $topic, $userName, $query );

my $end = new Benchmark;

print STDERR "Total " . timestr(timediff($end, $begin))."\n";
