XML::Writer blesses $doc for some reason. I presume IO::Compress::gzip checks for that even though it would have no effect in this case. Copying $doc doesn't copy the blessing.

use strict; use warnings; use Devel::Peek qw( Dump ); use Scalar::Util qw( blessed ); use XML::Writer qw( ); my $writer = new XML::Writer(OUTPUT => \my $doc); $writer->startTag("root"); $writer->startTag("foo"); $writer->endTag("foo"); $writer->endTag("root"); $writer->end(); Dump $doc; print(blessed(\$doc)?1:0, "\n"); # 1 my $copy = $doc; Dump $copy; print(blessed(\$copy)?1:0, "\n"); # 0
SV = PVMG(0x18c5614) at 0x182a39c REFCNT = 2 FLAGS = (PADMY,OBJECT,POK,pPOK) IV = 0 NV = 0 PV = 0x1922fbc "<root><foo></foo></root>\n"\0 CUR = 25 LEN = 28 STASH = 0x19154b4 "XML::Writer::_String" 1 SV = PVMG(0x18c5654) at 0x1915784 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) IV = 0 NV = 0 PV = 0x1925184 "<root><foo></foo></root>\n"\0 CUR = 25 LEN = 28 0

In reply to Re: XML::Writer oddness by ikegami
in thread XML::Writer oddness by TedHopp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.