Created
November 23, 2010 15:31
-
-
Save motemen/711938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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