Perl::...anyArgs(3pm)
π NAME (yes bestie, it's literally called that)
Perl::Critic::Policy::Subroutines::ProhibitManyArgs β aka the "too many arguments" policy, and honestly? it's giving concerned bestie energy π«Ά
This page lives in the Perl::...anyArgs(3pm) slot of your man pages (User Contributed Perl Documentation, no less π), and it's about one very specific vibe check: your subs are taking way too many args.
β¨ AFFILIATION β¨
Okay so this Policy is part of the core Perl::Critic distribution. Like, it ships with the gang π no extra install, she's already there.
πΈ DESCRIPTION πΈ
Subroutines that expect large numbers of arguments are hard to use β and why? because programmers routinely have to go look at the documentation just to remember the order of those arguments π like bestie, if I gotta open a doc file to remember whether it's ($name, $age, $haircolor) or ($age, $name, $haircolor), something has gone wrong.
Many arguments is often a sign that a subroutine should be refactored, or that an object should be passed to the routine. Periodt. π₯ That's the whole thesis.
π CONFIGURATION π
By default, this policy allows up to 5 arguments without warning. Five! That's the threshold, that's the vibe check line β
Wanna change this threshold? Pop some entries in a .perlcriticrc file like this:
[Subroutines::ProhibitManyArgs]
max_arguments = 6
And if you want to ignore $self or $class in your argument count β as long as they're the first argument β use:
[Subroutines::ProhibitManyArgs]
skip_object = 1
Because $self showing up first is just main character energy and shouldn't be counted against you π iykyk.
π CAVEATS π
Real talk, some limits:
- PPI doesn't currently detect anonymous subroutines, so we don't check those. Not a bug, just a "not yet" β this should just work when PPI gains that feature π
- We don't check for
@ARG, the alias for@_fromEnglish.pm. That's deprecated anyway, so likeβ¦ we're not gonna waste our time π
π¦ CREDITS π¦
Initial development of this policy was supported by a grant from the Perl Foundation. Shoutout, fr fr π
π AUTHOR π
Chris Dolan <cdolan@cpan.org> β iconic behavior, we stan π
π COPYRIGHT π
Copyright (c) 2007-2023 Chris Dolan. Many rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.
ngl, "Many rights reserved" is such a serve. Not all the rights. Many of them. The good ones π
And that's the whole page bestie! β¨ This cutie was rendered from perl v5.42.0 on 2024-10-23 β so if you're reading this on some other version, hi from the past, hope your subs have fewer args now πππ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms