[Catalyst] "Use of uninitialized value $buffer" error

Merlyn Kline merlyn at zynet.net
Mon Jun 22 09:18:40 GMT 2009


> I'm getting an error that looks like:
>
> Use of uninitialized value $buffer in concatenation (.) or
> string at /usr/share/perl5/Catalyst/Engine/CGI.pm line 220.

Deep in my job list I have some notes surrounding this issue saying that I
need to investigate further and possibly submit a patch or two.
Unfortunately these notes (a) refer to an old version of Catalyst using
FastCGI and (b) turn out not to be quite as lucid as I'd recalled them
being. Basically, though, the obvious proximal cause of this would be
calling the write method with no parameter. This might seem an odd thing to
do but might be as a result of a loop writing something in chunks and
getting an empty chunk at the end or, as in my case, might be an attempt to
work around a related problem where the simple concatenation of the buffer
to the headers (as in the code you cited, below) causes problems because the
headers are not UTF8 encoded and the buffer is, so perl tries to fix the
encoding and ends up with the wrong thing - calling write() with no
parameters (or, in later bodges, an empty string) fixes this by flushing the
headers into the output stream before the buffer is concatenated to them.

Hope this is a useful clue.

Merlyn


> ---
> around write => sub {
>     my $orig = shift;
>     my ( $self, $c, $buffer ) = @_;
>
>     # Prepend the headers if they have not yet been sent
>     if ( $self->_has_header_buf ) {
>         $buffer = $self->_clear_header_buf . $buffer;
>     }
>
>     return $self->$orig( $c, $buffer );
> };
> ---




More information about the Catalyst mailing list