[pm-h] Looking for PSGI web server Daemon
Michael R. Davis
mrdvt92 at yahoo.com
Mon Jun 8 19:32:31 PDT 2015
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/a00f69d9/attachment-0001.html>
More information about the Houston
mailing list