Added perl environment (#311)
Perl runtime environment and example function.
This commit is contained in:
committed by
Soam Vasani
parent
1b9fa5bc30
commit
6142ac3648
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use utf8;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Getopt::Args;
|
||||
use Plack::Handler::Twiggy;
|
||||
|
||||
opt codepath => (
|
||||
isa => 'Str',
|
||||
default => '/userfunc/user',
|
||||
comment => 'Path to the user code',
|
||||
);
|
||||
|
||||
opt port => (
|
||||
isa => 'Int',
|
||||
default => 8888,
|
||||
comment => 'Port to listen on',
|
||||
);
|
||||
|
||||
my $options = optargs();
|
||||
|
||||
{
|
||||
package App::Fission::Perl;
|
||||
|
||||
use Dancer2;
|
||||
|
||||
our $userfunc;
|
||||
|
||||
post '/specialize' => sub {
|
||||
if($userfunc) {
|
||||
send_error('Not a generic container', 400);
|
||||
}
|
||||
|
||||
$userfunc = require($options->{codepath});
|
||||
return '';
|
||||
};
|
||||
|
||||
any '/' => sub {
|
||||
return $userfunc ? $userfunc->(request) : send_error('Not yet specialized', 500);
|
||||
};
|
||||
}
|
||||
|
||||
my $handler = Plack::Handler::Twiggy->new(port => $options->{port});
|
||||
$handler->run(App::Fission::Perl->to_app);
|
||||
Reference in New Issue
Block a user