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 @_ from English.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 (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