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