$tmpfh->autoflush(1);
$msg = \($msg->as_string) if $ref ne 'SCALAR';
print $tmpfh $$msg or die "failed to print: $!";
sysseek($tmpfh, 0, SEEK_SET) or
die "sysseek(fh) failed: $!";
$tmpfh->autoflush(1);
$msg = \($msg->as_string) if $ref ne 'SCALAR';
print $tmpfh $$msg or die "failed to print: $!";
sysseek($tmpfh, 0, SEEK_SET) or
die "sysseek(fh) failed: $!";