[pm-h] Looking for PSGI web server Daemon
Mark Allen
mrallen1 at yahoo.com
Tue Jun 9 06:02:14 PDT 2015
I just found out about Gazelle this morning - looks reeeeeally cool for PSGI apps.
Gazelle - Preforked Plack Handler for performance freaks - metacpan.org
| |
| | | | | |
| Gazelle - Preforked Plack Handler for performance freaks - metacpan.orgPreforked Plack Handler for performance freaks |
| |
| View on metacpan.org | Preview by Yahoo |
| |
| |
On Monday, June 8, 2015 10:32 PM, Michael R. Davis <mrdvt92 at yahoo.com> wrote:
Perl Folks,
>>> hoping that someone had already packaged up an RPM/PKG like Apache where I could just drop my PSGI script in the /etc/starman/pgsi/ folder and be off and running. Here's a cool URL mapper for Plack apps. It works great for Plack apps but it fails to pull in more than the first Mojo app. I have no idea why but load_psgi (`do "$filename"`) must work differently after the first Mojo app is loaded. Error: "Can't use string ("Mojolicious::Commands") as a subroutine ref while "strict refs" in use at /usr/share/perl5/vendor_perl/Plack/Middleware/Auth/Basic.pm line 30."
$ cat plack-builder-mount-deamon-folder.pl
#!/usr/bin/perl
use strict;
use warnings;
use Plack::App::URLMap qw{};
use Plack::Util qw{};my %filenames = (
'/p0' => 'plack.psgi', #works
'/p1' => 'plack.psgi', #works
'/p2' => 'plack.psgi', #works
'/p3' => 'plack.psgi', #works
'/p4' => 'plack.psgi', #works
'/p5' => 'plack.psgi', #works
'/m1' => 'mojo-lite-1.psgi', #works
'/m2' => 'mojo-lite-2.psgi', #fails
'/m3' => 'mojo-lite-3.psgi', #fails
'/m4' => 'mojo-lite-4.psgi', #fails
'/m5' => 'mojo-lite-5.psgi', #fails
);my $mapper = Plack::App::URLMap->new;foreach my $mount (sort keys %filenames) {
my $filename = $filenames{$mount};
my $app = Plack::Util::load_psgi($filename) or die($@);
die($@) unless ref($app) eq "CODE";
$mapper->map($mount => $app);
print "Mapped: $mount to $filename ($app)\n";
}my $system = $mapper->to_app;
--- $ cat plack.psgi#!/usr/bin/perl
use Plack::Builder;my $app = sub {
my $env = shift;
return [
200,
[ "Content-Type" => "text/plain", "Content-Length" => 11 ],
[ "Hello World" ],
];
};builder {
enable "Auth::Basic", authenticator => \&authen_cb;
$app;
};sub authen_cb {
my($username, $password, $env) = @_;
return $username eq 'user' && $password eq 'pass';
}
--- $ cat mojo-lite.psgi
#perl
use strict;
use warnings;
use Plack::Builder qw{builder enable mount};
use Mojolicious::Lite qw{app};
use DateTime;get '/' => sub {
my $c = shift;
$c->render(
json => {
int => 1,
float => 2.23423,
exp => 34.45e27,
string => "hello world!",
dt => DateTime->now,
}
);
}; get '/env' => sub {
my $c = shift;
$c->render(
text => join("", map {sprintf "%s: %s\n", $_, $ENV{$_}} sort keys %ENV),
);
}; sub authen_cb {
my($username, $password, $env) = @_;
return $username eq 'user' && $password eq 'pass';
} builder {
enable "Auth::Basic", authenticator => \&authen_cb; app->start; #app from Mojolicious::Lite
};
--- Thanks,
Mike
mrdvt92
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20150609/ed4ede36/attachment.html>
More information about the Houston
mailing list