I have no implementation, but I think I have an approach. You can do this on-line using Plack :: Middleware :: Conditional . This way it will look like this, but you will need to fill in the missing conditions / tests. I have not seen the simple / obvious way, but I suspect you could. Since you need to go through $env, you need to set / check the HTTP_ / session in the order you want, and save the state for the next handler to find out if it should be enabled or not.
use Plack::Builder;
my $app = sub {
[ 200,
[ "Content-Type" => "text/plain" ],
[ "O HAI, PLAK!" ]
];
};
builder {
enable "Session::Cookie";
enable_if { my $env = shift;
} "Auth::Digest",
realm => "Secured", secret => "BlahBlah",
authenticator => sub { $_[0] eq $_[1] };
enable_if { my $env = shift;
} "Auth::Basic",
authenticator => sub { $_[0] eq $_[1] };
$app;
};
source
share