# current
package M::Gzip;
use strict;
use base qw/Middleware/;

sub gen_middleware {
my $app = shift;
sub {
my $env = shift;
my $res = $app->($env);
...
unshift @{$res->[1]}, 'Content-Encoding' => 'gzip';
return [$res->[0], $res->[1], M::Gzip::Streamer->new($res->[2])];
}
}

1;
# wsgi like
package M::Gzip;
use strict;
use base qw/Middleware/;

sub gen_middleware {
my $app = shift;
sub {
my ($env, $orig_starter) = @_;
my $res = $app->($env, sub {
my ($status, $header) = @_;
unshift @{$header}, 'Content-Encoding' => 'gzip';
my $writer = $orig_starter->($status, $header);
return M::GZip::Writer->new(orig_writer => $orig_starter);
});
...
return [SAME_THING_LIKE_CURRENT];
}
}

package M::Gzip::Writer;

has orig_writer => ( is => 'ro', isa => 'Object' );

sub write {
my ($self, $stuff) = @_;
$self->orig_writer->write(gzip($stuff));
}

1;