lemonldap-ng/e2e-tests/llng.psgi
2016-02-18 12:23:53 +00:00

68 lines
1.8 KiB
Perl

#!/usr/bin/env perl
use warnings;
BEGIN {
$pwd = `pwd`;
chomp $pwd;
eval qq{
use lib "$pwd/lemonldap-ng-common/blib/lib";
use lib "$pwd/lemonldap-ng-handler/blib/lib";
use lib "$pwd/lemonldap-ng-portal/blib/lib";
use lib "$pwd/lemonldap-ng-manager/blib/lib";
use Lemonldap::NG::Handler::SharedConf;
};
die $@ if ($@);
}
my %_apps;
my %builder = (
handler => sub {
require Lemonldap::NG::Handler::Nginx;
return Lemonldap::NG::Handler::Nginx->run( {} );
},
status => sub {
require Lemonldap::NG::Handler::Nginx;
return Lemonldap::NG::Handler::Nginx->status();
},
manager => sub {
require Lemonldap::NG::Manager;
return Lemonldap::NG::Manager->run( {} );
},
cgi => sub {
require CGI::Emulate::PSGI;
require CGI::Compile;
return sub {
my $script = $_[0]->{SCRIPT_FILENAME};
return $_apps{$script}->(@_) if ( $_apps{$script} );
eval {
$_apps{$script} =
CGI::Emulate::PSGI->handler( CGI::Compile->compile($script) );
};
if ($@) {
use Data::Dumper;
return [
500,
[ 'Content-Type', 'text/plain' ],
[ "Script: $script\n $@\n" . Dumper( \$_[0] ) ]
];
}
return $_apps{$script}->(@_);
};
},
);
Lemonldap::NG::Handler::SharedConf->init();
sub {
my $type = $_[0]->{LLTYPE} || 'handler';
return $_apps{$type}->(@_) if ( defined $_apps{$type} );
if ( defined $builder{$type} ) {
$_apps{$type} = $builder{$type}->();
return $_apps{$type}->(@_);
}
die "Unknown PSGI type $type";
};