Skip to content

Instantly share code, notes, and snippets.

@motemen motemen/plackup-mw
Created Nov 23, 2010

Embed
What would you like to do?
#!/usr/bin/env perl
use strict;
use warnings;
my $runner = Plack::Runner::WithMiddleware->new;
$runner->parse_options(@ARGV);
$runner->run;
package Plack::Runner::WithMiddleware;
use base 'Plack::Runner';
sub prepare_devel {
my ($self, $app) = @_;
$app = $self->SUPER::prepare_devel($app);
foreach (@{ $self->{middleware_args} }) {
$app = $self->apply_middleware($app, @$_);
}
return $app;
}
sub parse_options {
my $self = shift;
my (@args, @mw_args);
foreach (@_) {
if (/^\+(.+)/) {
my ($mw, @args) = split /,/, $1;
my %args = map { split /=/, $_, 2 } @args;
if ($mw eq 'Auth::Basic' && $args{user} && $args{pass}) {
my ($user, $pass) = (delete $args{user}, delete $args{pass});
$args{authenticator} = sub {
return $_[0] eq $user && $_[1] eq $pass;
};
}
push @mw_args, [ $mw, %args ];
} else {
push @args, $_;
}
}
$self->{middleware_args} = \@mw_args;
return $self->SUPER::parse_options(@args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.