Perl::...otation(3pm)
π NAME π
Perl::Critic::Policy::Community::IndirectObjectNotation β bestie, we do not call methods indirectly around here. That's the whole vibe of this page, and it's a Perl::...otation(3pm) manual page, so you already know it's gonna be a lil nerdy and a lot correct. β¨
π¦ DESCRIPTION π¦
Okay so, plot twist: Perl lets you call a method in a cursed way where the method name goes first, then the invocant (that's the class or object you're calling the method on, bestie), and then the argument list trails behind like it's late to the group chat.
This is an unfortunate legacy syntax that should no longer be used. Periodt.
Wanna read more? Go check "Indirect Object Syntax" in perlobj and "REFERENCES" in indirect. Iykyk. π
my $obj = new My::Class @args; # not ok
my $obj = My::Class->new(@args); # ok
So here's the tea, and it's a lil sad: it is difficult to detect indirect object notation by static analysis, so this policy only forbids the new method call by default, because new is highly unlikely to be the name of a standard subroutine call. Fr fr. If you want more coverage, consider using the indirect pragma to cause the code to warn or die when indirect object notation is used. π¨
Now on Perl 5.32 or newer (or automatically with use v5.36 or newer, slay), "The 'indirect' feature" in feature can be disabled to prevent the parser from interpreting syntax as indirect object notation. The parser said no. π«Ά
Also, this policy is a subclass of the Perl::Critic core policy Perl::Critic::Policy::Objects::ProhibitIndirectSyntax, and it performs the same function but in the "community" theme. Same energy, cuter outfit. π
πΈ AFFILIATION πΈ
This policy is part of Perl::Critic::Community. It's giving community. π
β¨ CONFIGURATION β¨
You can configure this policy β in the same way as its parent policy Perl::Critic::Policy::Objects::ProhibitIndirectSyntax β to attempt to forbid additional method names from being called indirectly. Iconic, honestly.
Be aware this may lead to false positives as it is difficult to detect indirect object notation by static analysis. π Not me getting false positives in the club.
And the new subroutine is always forbidden in addition to these. No exceptions, bestie.
[Community::IndirectObjectNotation]
forbid = create destroy
π AUTHOR π
Dan Book, "dbook@cpan.org" β thank you for your service, king. π«‘
π COPYRIGHT AND LICENSE π
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. Redistribute responsibly, bestie. β¨
π SEE ALSO π
Perl::Criticπindirectπ
okay that's the whole page, you ate it up, go write some My::Class->new(@args) and make the parser proud. π
This was brought to you by perl v5.40.1, dated 2025-03-22, and the original manual page header Perl::...otation(3pm) β mwah, bye bestie! π
ππ¦
π¦ where this page comes from
- debian trixie: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu resolute: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu stonking: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms