Perl::...bCalls(3pm)

πŸ“¦
version 1.0.4 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’… NAME πŸ’…

Perl::Critic::Policy::Community::AmpersandSubCalls β€” bestie, do NOT call your subroutines with &. Just don't. 🫢


✨ DESCRIPTION ✨

Okay so, storytime: back in the day, the ampersand (&) was literally required to call a subroutine. Ancient lore. But in modern Perl? It's not just unnecessary β€” it actually changes the behavior in ways you probably did not sign up for. 😭

Calling a subroutine with an ampersand ignores the subroutine's prototype if it has one, which can change what arguments the subroutine actually receives. Which is giving chaos, honestly. πŸ’€

And plot twist: calling a subroutine as &foo; with no arguments will pass on the contents of @_ from the current subroutine. Surprising?? Understatement. The audacity. 🚩

So unless you're doing it intentionally for that exact behavior β€” which, iykyk β€” the ampersand should simply be omitted. Periodt.

my $value = &foo();  # not ok
my $sum = &foo(1,2); # not ok
my $value = foo();   # ok
my $sum = foo 1,2;   # ok

This policy is a subclass of the core policy Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils, and it performs the same function β€” but in the community theme. Same slay, different aesthetic. πŸ‘‘


🌸 AFFILIATION 🌸

This policy is part of Perl::Critic::Community. It's in the group chat. πŸ’œ


πŸŽ€ CONFIGURATION πŸŽ€

This policy is not configurable except for the standard options. No knobs, no switches, no little toggles to fiddle with. It is what it is, and what it is is correct. ✨


πŸ¦‹ AUTHOR πŸ¦‹

Dan Book, dbook@cpan.org


Copyright 2015, Dan Book.

This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.


⭐ SEE ALSO ⭐

  • Perl::Critic

okay bestie that's the whole page, you ate that πŸ’… this was perl v5.40.1, dated 2025-03-22, brought to you by User Contributed Perl Documentation β€” stay iconic, go remove those ampersands, mwah 🫢✨

πŸ“¦ where this page comes from