forked from ledgersmb/LedgerSMB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ledgersmb#418 from einhverfr/1.3
Plack support now works
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package LedgerSMB::PSGI; | ||
|
||
=head1 NAME | ||
PSGI wrapper functionality for LedgerSMB | ||
=head1 SYNOPSIS | ||
use LedgerSMB::PSGI; | ||
my $app = LedgerSMB::PSGI->get_app(); | ||
=cut | ||
|
||
# Preloads | ||
use LedgerSMB; | ||
use LedgerSMB::Form; | ||
use LedgerSMB::Sysconfig; | ||
use LedgerSMB::Template; | ||
use LedgerSMB::Template::LaTeX; | ||
use LedgerSMB::Template::HTML; | ||
use LedgerSMB::Locale; | ||
use LedgerSMB::DBObject; | ||
use LedgerSMB::File; | ||
use Try::Tiny; | ||
|
||
use CGI::Emulate::PSGI; | ||
|
||
sub app { | ||
return CGI::Emulate::PSGI->handler( | ||
sub { | ||
my $uri = $ENV{REQUEST_URI}; | ||
$ENV{SCRIPT_NAME} = $uri; | ||
my $script = $uri; | ||
$ENV{SCRIPT_NAME} =~ s/\?.*//; | ||
$script =~ s/.*[\\\/]([^\\\/\?=]+\.pl).*/$1/; | ||
|
||
if (-f "scripts/$script"){ | ||
{ | ||
package main; | ||
do 'lsmb-request.pl'; | ||
} | ||
} else { | ||
_run_old($script); | ||
} | ||
} | ||
); | ||
} | ||
|
||
my $pre_dispatch = undef; | ||
sub pre_dispatch { | ||
$pre_dispatch = shift; | ||
} | ||
|
||
my $post_dispatch = undef; | ||
sub post_dispatch { | ||
$pre_dispatch = shift; | ||
} | ||
|
||
sub _run_old { | ||
if (my $cpid = fork()){ | ||
wait; | ||
} else { | ||
&$pre_dispatch() if $pre_dispatch; | ||
{ package main; | ||
do 'old-handler.pl'; | ||
} | ||
&$post_dispatch() if $post_dispatch; | ||
exit; | ||
} | ||
} | ||
|
||
sub _run_new { | ||
my ($script) = @_; | ||
&$pre_dispatch(); | ||
$uri = $ENV{REQUEST_URI}; | ||
$uri =~ s/\?.*//; | ||
|
||
do "./$script"; | ||
&$post_dispatch(); | ||
} | ||
|
||
1; |