[Perl/perl5] f280de: class.c: skip leading _ in default :param/:reader ...

[email protected] (Lukas Mai via perl5-changes)
Newsgroups perl.perl5.changes
Message-ID <Perl/perl5/push/refs/heads/blead/[email protected]>
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: f280deb888ab8957a1b7b3cf8d36de5ec36f8e42
      https://github.com/Perl/perl5/commit/f280deb888ab8957a1b7b3cf8d36de5ec36f8e42
  Author: Lukas Mai <[email protected]>
  Date:   2026-08-20 (Thu, 20 Aug 2026)

  Changed paths:
    M class.c
    M pod/perlclass.pod
    M t/class/accessor.t
    M t/class/field.t
    M t/lib/croak/class

  Log Message:
  -----------
  class.c: skip leading _ in default :param/:reader names

Previously,

    field $_foo :param :reader :writer;

was equivalent to

    field $_foo :param(_foo) :reader(_foo) :writer(set__foo);

Now it means

    field $_foo :param(foo) :reader(foo) :writer(set_foo);

That is, the constructor parameter and reader/writer methods skip over a
single leading underscore in the field name if present.

It is often convenient to visually mark a field as "internal" to a class
by giving it a name that starts with an underscore. But constructor
arguments are part of the public interface of a class, so it would be
weird to have a leading _ there. (The same argument applies to generated
accessor methods.)

Object::Pad does the same thing:

> A single prefix character "_" will be removed if present.


  Commit: 7248484676bf0ee21b49f9660374a0e33b6f7796
      https://github.com/Perl/perl5/commit/7248484676bf0ee21b49f9660374a0e33b6f7796
  Author: Lukas Mai <[email protected]>
  Date:   2026-08-20 (Thu, 20 Aug 2026)

  Changed paths:
    M pod/perldelta.pod
    M t/porting/known_pod_issues.dat

  Log Message:
  -----------
  perldelta for skipped _ in default :param/:reader names


Compare: https://github.com/Perl/perl5/compare/42f87f43790f...7248484676bf

To unsubscribe from these emails, change your notification settings at https://github.com/Perl/perl5/settings/notifications
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.