use strict;
use warnings;
use IO::File;
sub append {
my ($self, $key, $value) = @_;
my $message = (defined $value ? "$key: $value\n" : (defined $key ? "$key\n" : "\n")); push(@{$self}, $message); }
sub flush {
my ($self) = @_;
$self->append;
STDOUT->printflush(@{$self});
@{$self} = ();
}
my $buff = _Buffer->new;
$buff->append(event => "message");
$buff->append(data => "fired message event");
$buff->flush;
$buff->append("data: message")->flush;
dXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwoKcGFja2FnZSBfQnVmZmVyOwp1c2UgSU86OkZpbGU7CgpzdWIgbmV3IHsgYmxlc3MgW10sIHNoaWZ0IH0KCnN1YiBhcHBlbmQgeyAKCW15ICgkc2VsZiwgJGtleSwgJHZhbHVlKSA9IEBfOwoKCW15ICRtZXNzYWdlID0gKGRlZmluZWQgJHZhbHVlID8gIiRrZXk6ICR2YWx1ZVxuIiA6IChkZWZpbmVkICRrZXkgPyAiJGtleVxuIiA6ICJcbiIpKTsKCXB1c2goQHskc2VsZn0sICRtZXNzYWdlKTsKCXJldHVybiAkc2VsZjsKfQoKc3ViIGZsdXNoIHsKCW15ICgkc2VsZikgPSBAXzsKCgkkc2VsZi0+YXBwZW5kOwoJU1RET1VULT5wcmludGZsdXNoKEB7JHNlbGZ9KTsgCglAeyRzZWxmfSA9ICgpOwoJcmV0dXJuICRzZWxmOwp9CgpwYWNrYWdlIG1haW47CgpteSAkYnVmZiA9IF9CdWZmZXItPm5ldzsKJGJ1ZmYtPmFwcGVuZChldmVudCA9PiAibWVzc2FnZSIpOwokYnVmZi0+YXBwZW5kKGRhdGEgPT4gImZpcmVkIG1lc3NhZ2UgZXZlbnQiKTsKJGJ1ZmYtPmZsdXNoOwokYnVmZi0+YXBwZW5kKCJkYXRhOiBtZXNzYWdlIiktPmZsdXNoOwo=