I looked at the code, and it looks to me to be a bug, but I don't know for sure what TheDamian intended.

Here is what is happening. Your argument list is always being turned into a reference to an array. If you process it that way in your tie implementation, it works just fine. If you don't, then you get your result.

Now if you look in the implementation, in import the variable $tiedata is defined in the following snippet:

if ($cmd =~ /^autotie((?:ref)?)$/) { my $tiedata = '($was_arrayref ? $data : @$data)'; $tiedata = ($1 ? '$ref, ' : '') . $tiedata; my $mapping = shift;
Now that looks to me to be an error, if you had an array reference, then leave it alone, if you didn't then try to dereference it as an array reference? If you didn't have an array reference, what possible sense does it make to dereference it as one?

Well if you try switching which branch of the trinary operator the array dereference takes place in, that code reads much more sensibly, and your test works entirely as you expected it to. However if you do that, 2 tests in the test suite fail. So I suspect that this is a bug in the code which was enshrined in the tests.

But I can't be sure of that without asking TheDamian. (I sent him a message.)


In reply to Re (tilly) 1: autotie in Attribute Handlers by tilly
in thread autotie in Attribute Handlers by davorg

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.