Perl::Critic::Policy::Objects::ProhibitIndirectSyntax(3pm)

Perl::Critic::Policy::Objects::ProhibitIndirectSyntax3pm

Prohibit indirect object call syntax.

Affiliation

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

Overview

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.

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".

Caveats

The general situation can not be handled via static analysis.

Releases

9 releases since Debian 6.0 (Squeeze); the text changed 8 times.

  1. 6.0
  2. 7
  3. 8
  4. 9
  5. 10
  6. 11
  7. 12
  8. 13
  9. Arch

Author

Thomas R. Wyant, III wyant at cpan dot org

From perl-perl-critic 1.156-3 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.