Perl::...tSyntax(3pm)

πŸ’… NAME

okay so this page is Perl::...tSyntax(3pm) from User Contributed Perl Documentation, and the policy it's serving is Perl::Critic::Policy::Objects::ProhibitIndirectSyntax β€” the one that says: Prohibit indirect object call syntax. bestie, we're policing vibes and syntax today πŸ’–

✨ AFFILIATION

This Policy is part of the core Perl::Critic distribution. core distribution, no gatekeeping ✨

πŸ¦‹ DESCRIPTION

Indirect object syntax is that thing other object-oriented languages use for instantiating objects. Perl allows it, but saying Perl β€œsupports” it may be going too far. iykyk. Instead of writing:

my $foo = new Foo;

it is preferable to write:

my $foo = Foo->new;

The problem is that Perl needs to make a number of assumptions at compile time to disambiguate the first form, so it tends to be fragile and to produce hard-to-track-down bugs. literally the worst kind of bug hunt 😭

πŸŽ€ CONFIGURATION

Indirect object syntax is also hard for Perl::Critic to disambiguate, so this policy only checks certain subroutine calls. You can configure the names of the subroutines with the forbid configuration option:

[Objects::ProhibitIndirectSyntax]
forbid = create destroy

The new subroutine is configured by default; any additional forbid values are in addition to new. so new is always on the guest list πŸ’…

πŸ™ˆ CAVEATS

The general situation can not be handled via static analysis. that's the caveat, bestie β€” static analysis can't catch the whole general situation.

🌈 SEE ALSO

Perl::Critic::Policy::Dynamic::NoIndirect and indirect both do a better job with this, but they require that you compile/execute your code. slay, but only if you compile/execute your code 🫢

πŸ‘‘ AUTHOR

Thomas R. Wyant, III β€” wyant at cpan dot org. iconic.

Copyright (c) 2009-2023 Tom Wyant

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.


That's the whole page, bestie. Source/version vibes: perl v5.42.0, dated 2024-10-23. Bye! πŸ’–

πŸ“¦ where this page comes from