Perl::Critic::Policy::Community::IndirectObjectNotation(3pm)

Perl::Critic::Policy::Community::IndirectObjectNotation3pm

Don't call methods indirectly

Overview

Perl allows a form of method call where the method name is first, followed by the invocant (class or object to call the method on), then the argument list. This is an unfortunate legacy syntax that should no longer be used. See "Indirect Object Syntax" in perlobj and "REFERENCES" in indirect for more information.

 my $obj = new My::Class @args;   # not ok
 my $obj = My::Class->new(@args); # ok

It is difficult to detect indirect object notation by static analysis, so this policy only forbids the "new" method call by default, as it is highly unlikely to be the name of a standard subroutine call. Consider using the indirect pragma to cause the code to warn or die when indirect object notation is used.

On Perl 5.32 or newer (or automatically with "use v5.36" or newer), "The 'indirect' feature" in feature can be disabled to prevent the parser from interpreting syntax as indirect object notation.

This policy is a subclass of the Perl::Critic core policy Perl::Critic::Policy::Objects::ProhibitIndirectSyntax, and performs the same function but in the "community" theme.

Affiliation

This policy is part of Perl::Critic::Community.

Configuration

This policy can be configured, in the same way as its parent policy Perl::Critic::Policy::Objects::ProhibitIndirectSyntax, to attempt to forbid additional method names from being called indirectly. Be aware this may lead to false positives as it is difficult to detect indirect object notation by static analysis. The "new" subroutine is always forbidden in addition to these.

 [Community::IndirectObjectNotation]
 forbid = create destroy

Releases

2 releases since Debian 12 (Bookworm); the text changed 1 time.

  1. 12
  2. 13

Author

Dan Book, "[email protected]"

From libperl-critic-community-perl 1.0.4-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.