Middleware 

my $app = sub {
    ...
}
my $mw = sub {
    my($env) = @_;
    # Mess with $env
    my $resp = $app->($env);
    # Mess with $resp
    return $resp;
}