You can just tie it together. builderfunct from Plack :: Builder will port your application to Middleware (or several). Then you just transfer it as a new Twiggy app.
use Plack::Builder;
use Twiggy::Server;
my $app = sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $session = $env->{'psgix.session'};
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ "Hello, you've been here for ", $session->{counter}++, "th time!" ],
];
};
$app = builder {
enable 'Session', store => 'File';
$app;
};
my $twiggy = Twiggy::Server->new(port => 3000);
$twiggy->register_service($app);
AE::cv->recv;
Please note that the buildernew application will return, but it will not end in $appunless you have assigned it. You can also just put builderin register_serviceas follows:
my $twiggy = Twiggy::Server->new(port => 3000);
$twiggy->register_service(builder {
enable 'Session', store => 'File';
$app;
});
Or, of course, you could get rid of Twiggy :: Server and run the command line tool twiggyor plackupfrom Twiggy.
source
share