logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::Objects::ProhibitIndirectSyntax - Prohibit indirect object call syntax.

Affiliation

       This Policy is part of the core Perl::Critic distribution.

Author

       Thomas R. Wyant, III wyantatcpandotorg

Caveats

       The general situation can not be handled via static analysis.

Configuration

       Indirect object syntax is also hard for Perl::Critic to disambiguate, so this policy only checks certain
       subroutine calls. The names of the subroutines can be configured using 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".

Description

       Indirect object syntax is commonly used in other object-oriented languages for instantiating objects.
       Perl allows this, but to say that it supports it may be going too far. 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.

Name

       Perl::Critic::Policy::Objects::ProhibitIndirectSyntax - Prohibit indirect object call syntax.

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.

See Also