Perl::...monyms(3pm)

πŸ’… NAME πŸ’…

Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms β€” okay so basically: do NOT declare your own open function, bestie. That's the whole vibe. 🚫

(this lil page lives in the Perl::...monyms(3pm) manpage section, iykyk)

πŸŽ€ AFFILIATION πŸŽ€

This Policy is part of the core Perl::Critic distribution. She's iconic, she ships with the whole thing. πŸ‘‘

✨ DESCRIPTION ✨

So like. Common sense literally dictates that you shouldn't declare subroutines with the same name as one of Perl's built-in functions or keywords. It's giving "why would you do that to yourself." 😭

  • Wanna see the built-in functions? Check perlfunc.
  • Wanna see the keywords? Check perlsyn.

Now look at these crimes against humanity:

sub open {}    #not ok
sub exit {}    #not ok
sub print {}   #not ok
sub foreach {} #not ok
sub if {}      #not ok

#You get the idea...

Not ok. Not one of them. Ngl every single one of these is a red flag 🚩 and the policy will come for them.

BUT β€” and this is the good part β€” exceptions are made for BEGIN, END, INIT and CHECK blocks, as well as AUTOLOAD, DESTROY, and import subroutines. Those ones ate and left no crumbs. 🫢

🌸 CONFIGURATION 🌸

You can configure additional builtin homonyms to accept by specifying them in a space-delimited list to the allow option:

[Subroutines::ProhibitBuiltinHomonyms]
allow = default index

These are added to the default list of exemptions from this policy. So the above allows sub default {} and sub index {}. Slay, she's flexible. ✨

πŸ’€ CAVEATS πŸ’€

It is reasonable to declare an object method with the same name as a Perl built-in function, since they are easily distinguished from each other. Like, fair, we get it, method call syntax is different, no cap.

However β€” and this is the tragic part πŸ˜” β€” at this time, Perl::Critic cannot tell whether a subroutine is static or an object method. So she's out here judging everyone equally. It's not personal, it's just policy. πŸ™ˆ

πŸ¦‹ AUTHOR πŸ¦‹

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>

Copyright (c) 2005-2022 Imaginative Software Systems. All 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.


And that's the page, bestie! πŸ’– This was perl v5.42.0, dated 2024-10-23, and you read it in Perl::...monyms(3pm). Go forth and don't name your sub print. πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from