PerlOutputFilterHandler runs twice...?



I've tried to set up an output filter to make my life esier in
developing a site. Rather than explicitly output SSI directives inside
the response handlers or registry scripts, I've made an output filter
like so:

package Local::GCPage;

use strict;
use warnings;

use base qw(Apache2::Filter);
use Apache2::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;

sub handler : FilterRequestHandler {
my $f = shift;

$f->print('<!--#include virtual="/elements/top.shtml" -->');

while ($f->read(my $buffer, BUFF_LEN)) {
$f->print($buffer);
}

$f->print('<!--#include virtual="/elements/bottom.shtml" -->');

return Apache2::Const::OK;
}
1;

Now, the thing is... it's running twice.

I turned off PerlSetOutputFilter to try and make it easier to read
what was going on with a tiny registry script that just says "Test
worked?<br/>\n" and got this:

<!--#include virtual="/elements/top.shtml" -->Test worked?<br/>
<!--#include virtual="/elements/bottom.shtml" -->
<!--#include virtual="/elements/top.shtml" --><!--#include virtual="/
elements/bottom.shtml" -->

Notice the top and bottom SSI tags in there twice.

I have my httpd.conf set up like so to deal with these:

<Directory "/usr/local/gc">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
DirectoryIndex index.html index.shtml index.gc index.cgi index.php
AllowOverride All
Order allow,deny
Allow from all
AddHandler perl-script .gc
PerlOptions +ParseHeaders +GlobalRequest +SetupEnv

<Files ~ "\.gc">
PerlFixupHandler Local::PrepSession
PerlOutputFilterHandler Local::GCPage
#PerlSetOutputFilter INCLUDES
</Files>
</Directory>

I'm not understanding why I get the filter run twice, once on the
actual content and then again underneath everything wrapped around an
empty string. I could easily modify the thing to make sure it has
content to wrap around, but that seems like a crappy kludge. Something
must be configured wrong.

BTW I also tried it with a DECLINED return value. Same thing. No
difference.
.