Code in a class block behaves like code in a package block: It is evaluated once. So last_one_was_bad is executed once. The next_count++ statement is executed on every creation of a WithACounter object (if next_count was flagged as a :param, then it would be executed only if the caller didn't specify it).
Also: it looks like the my variables there are essentially "class static" members — so called in other languages e.g. C#. Is that an accurate characterization?

Pretty much yes. There is a discussion whether the class system needs its own syntax for "class static" members, but this is about convenience details which are not yet implemented: A "field" in Object::Pad can get attributes like :reader which will create appropriate accessor functions. You might want to permit a field $foo :static :reader, but there was some opposition against my $foo :reader which would make the syntax of the existing my keyword depend on the context. Damian Conway points out that a my variable is a private implementation detail, but a static field with a reader is part of the class interface (and maybe subject to inheritance). As far as Perl 5.38 is concerned, the distinction doesn't exist.


In reply to Re: perl 5.38: can the body of a class declaration contain arbitrary code? by haj
in thread perl 5.38: can the body of a class declaration contain arbitrary code? by jdporter

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.