#!/usr/bin/perl
use Plack::Builder;
use Plack::App::CGIBin;
#use Plack::Middleware::Debug;
use Plack::App::Directory;
use lib("/usr/share/koha/lib");
use C4::Context;
use C4::Languages;
use C4::Members;
use C4::Dates;
use C4::Boolean;
use C4::Letters;
use C4::Koha;
use C4::XSLT;
use C4::Branch;
use C4::Category;

my $app=Plack::App::CGIBin->new(root => "/usr/share/koha/opac/cgi-bin/opac");
my $newbooks=Plack::App::WrapCGI->new(script => "/usr/bin/php /usr/share/koha/opac/htdocs/newbooks.php", execute => 1)->to_app;
my $docroot=Plack::App::File->new(root => "/usr/share/koha/opac/htdocs");
builder {
	enable "Rewrite", rules => sub {
		s{^/$}{/cgi-bin/koha/opac-main.pl};
	};
        enable "Plack::Middleware::Static",
                path => qr{^/opac-tmpl/}, root => '/usr/share/koha/opac/htdocs/';
        enable 'StackTrace';
        mount "/cgi-bin/koha" => $app;
	mount "/newbooks.php" => $newbooks;
	mount "/" => $docroot;
};
