This gives me an error when run with Perl versions after 5.16.

Well technically, you're the one causing the error ;-) die Dumper \@_;

I'm pretty sure the difference in behavior you're seeing is because bug #29230 was fixed in Class::Struct version 0.64, which was released with v5.18.0. It appears that the constructor is supposed to initialize the fields <update> using the custom accessors </update>.

In sub set_values, you expect there to be an even number of arguments that you assign to a hash (my %args = @_;), but in sub heights_agl, you do ->set_values(Variable=>'heights_agl',@_), which means that if @_ contains an odd number of elements, you'll get the "Odd number of elements in hash assignment" warning (not a fatal error, but a useful warning).

I'm pretty sure this would happen any time you assign <update> an array ref </update> to heights_agl - so I think you need to rethink your logic anyway. Since you haven't shown what set_values is actually doing, it's a little hard to tell what the best solution would be, but perhaps you might want to change the call to something like $self->set_values(Variable=>'heights_agl',Arguments=>[@_]);?

Update: Note the documentation of Class::Struct:

Array ('@' or '*@')

The element is an array, initialized by default to ().

... As a special case, when the accessor is called with an array reference as the sole argument, this causes an assignment of the whole array element. The object reference is returned.

So I guess you'll need to extend your set_values to handle this case.


In reply to Re: Class::Struct accessor function after Perl V5.16 (updated) by haukex
in thread Class::Struct accessor function after Perl V5.16 by Anonymous Monk

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.