usualoma
7/29/2013 - 8:12 PM

AliasedSearch.pm

package Plack::Middleware::MT::AliasedSearch;

use strict;
use warnings;
use utf8;
use parent 'Plack::Middleware';
use Plack::Util::Accessor qw(recipes);

sub call {
    my ( $self, $env ) = @_;

    for my $recipe ( @{ $self->recipes } ) {
        if ( $env->{PATH_INFO} =~ m!\A/$recipe->{from}\z! ) {
            $env->{QUERY_STRING} = $recipe->{to};
        }
    }

    $self->app->($env);
}

1;