Skip to content

Conversation

@leonerd
Copy link
Contributor

@leonerd leonerd commented Sep 26, 2025

  • use v5.40
  • our on package globals
  • Signatures on subs
  • Lexical subs when not required to be visible

This first required a bugfix in attributes.xs, whose details are outlined in its own commit.

  • This set of changes might require a perldelta entry, if we deem the bugfix user-visible enough to warrant calling it out specifically

@leonerd leonerd force-pushed the modernize-attributes.pm branch from e55597e to 713a9fb Compare September 26, 2025 12:13
my $svref = shift;
my $svtype = uc reftype($svref);
my $stash = _guess_stash($svref);
$stash = caller unless defined $stash;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use // here:

my $stash = _guess_stash($svref) // caller;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for 1; at the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes, both fixed

%EXPORT_TAGS = (ALL => [@EXPORT, @EXPORT_OK]);

use strict;
our @EXPORT_OK = qw(get reftype);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could just do *reftype = \&builtin::reftype in this file and drop the reftype func from attributes.xs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be reasonable too. Annoyingly, we need to keep the symbol present, in case some code out there somewhere actually calls attributes::reftype() - i.e. we can't simply use a lexical import here.

 * Reset `@warnings` array between tests so failures in one block don't leak
   into all the later ones

 * Print the next warning using `diag` if we fail because it isn't empty
…tes.xs

Previously the XS code always checked its immediate caller for warnings.
This was fine when core perl invokes it directly in a `:prototype`
warning, but was checking the wrong layer when invoked indirectly via
`attributes::import`. In that case, it meant that it was sensitive to,
and printed warnings as it coming from attributes.pm itself, rather than
the intended caller; i.e. the location of the `use attributes ...`
statement.

This is fixed by using `caller_cx()` to walk up the caller stack looking
for a call frame not from the `attributes` package.
@leonerd leonerd force-pushed the modernize-attributes.pm branch from 713a9fb to 004837f Compare September 27, 2025 12:06
 * use v5.40
 * `our` on package globals
 * Signatures on subs
 * Lexical subs when not required to be visible
 * `module_true` means no need for ending `1;`
 * Use `//` operator
 * Remove `reftype` from attributes.xs and use builtin::reftype instead
@leonerd leonerd force-pushed the modernize-attributes.pm branch from 004837f to dd15d23 Compare September 27, 2025 12:10
@JRaspass
Copy link
Contributor

LGTM 👍

@leonerd leonerd merged commit 4f8316f into Perl:blead Sep 27, 2025
33 checks passed
@leonerd leonerd deleted the modernize-attributes.pm branch September 27, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants