File Coverage

blib/lib/Perl/Critic/Policy/Community/IndirectObjectNotation.pm
Criterion Covered Total %
statement 13 14 92.8
branch n/a
condition n/a
subroutine 5 6 83.3
pod 2 2 100.0
total 20 22 90.9


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Community::IndirectObjectNotation;
2              
3 1     1   462 use strict;
  1         3  
  1         31  
4 1     1   6 use warnings;
  1         3  
  1         30  
5              
6 1     1   6 use Perl::Critic::Utils qw(:severities :classification :ppi);
  1         3  
  1         72  
7 1     1   436 use parent 'Perl::Critic::Policy::Objects::ProhibitIndirectSyntax';
  1         2  
  1         7  
8              
9             our $VERSION = 'v1.0.1';
10              
11 4     4 1 21766 sub default_severity { $SEVERITY_HIGHEST }
12 0     0 1   sub default_themes { 'community' }
13              
14             1;
15              
16             =head1 NAME
17              
18             Perl::Critic::Policy::Community::IndirectObjectNotation - Don't call methods
19             indirectly
20              
21             =head1 DESCRIPTION
22              
23             Perl allows a form of method call where the method name is first, followed by
24             the invocant (class or object to call the method on), then the argument list.
25             This is an unfortunate legacy syntax that should no longer be used. See
26             L<perlobj/"Indirect Object Syntax"> and L<indirect/"REFERENCES"> for more
27             information.
28              
29             my $obj = new My::Class @args; # not ok
30             my $obj = My::Class->new(@args); # ok
31              
32             It is difficult to detect indirect object notation by static analysis, so this
33             policy only forbids the C<new> method call by default, as it is highly unlikely
34             to be the name of a standard subroutine call. Consider using the L<indirect>
35             pragma to cause the code to warn or die when indirect object notation is used.
36              
37             This policy is a subclass of the L<Perl::Critic> core policy
38             L<Perl::Critic::Policy::Objects::ProhibitIndirectSyntax>, and performs the same
39             function but in the C<community> theme.
40              
41             =head1 AFFILIATION
42              
43             This policy is part of L<Perl::Critic::Community>.
44              
45             =head1 CONFIGURATION
46              
47             This policy can be configured, in the same way as its parent policy
48             L<Perl::Critic::Policy::Objects::ProhibitIndirectSyntax>, to attempt to forbid
49             additional method names from being called indirectly. Be aware this may lead to
50             false positives as it is difficult to detect indirect object notation by static
51             analysis. The C<new> subroutine is always forbidden in addition to these.
52              
53             [Community::IndirectObjectNotation]
54             forbid = create destroy
55              
56             =head1 AUTHOR
57              
58             Dan Book, C<dbook@cpan.org>
59              
60             =head1 COPYRIGHT AND LICENSE
61              
62             Copyright 2015, Dan Book.
63              
64             This library is free software; you may redistribute it and/or modify it under
65             the terms of the Artistic License version 2.0.
66              
67             =head1 SEE ALSO
68              
69             L<Perl::Critic>, L<indirect>