File Coverage

blib/lib/Perl/Critic/Policy/Community/AmpersandSubCalls.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::AmpersandSubCalls;
2              
3 1     1   468 use strict;
  1         3  
  1         33  
4 1     1   5 use warnings;
  1         3  
  1         31  
5              
6 1     1   6 use Perl::Critic::Utils qw(:severities :classification :ppi);
  1         3  
  1         101  
7 1     1   450 use parent 'Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils';
  1         3  
  1         7  
8              
9             our $VERSION = 'v1.0.1';
10              
11 4     4 1 70532 sub default_severity { $SEVERITY_HIGH }
12 0     0 1   sub default_themes { 'community' }
13              
14             1;
15              
16             =head1 NAME
17              
18             Perl::Critic::Policy::Community::AmpersandSubCalls - Don't use & to call
19             subroutines
20              
21             =head1 DESCRIPTION
22              
23             Ampersands (C<&>) were once needed to call subroutines, but in modern Perl they
24             are not only unnecessary but actually change the behavior from what you may
25             expect. Calling a subroutine with an ampersand ignores the subroutine's
26             prototype if any, which may change what arguments the subroutine receives.
27             Additionally, calling a subroutine as C<&foo;> with no arguments will pass on
28             the contents of C<@_> from the current subroutine, which may be quite
29             surprising. Unless used intentionally for this behavior, the ampersand should
30             simply be omitted.
31              
32             my $value = &foo(); # not ok
33             my $sum = &foo(1,2); # not ok
34             my $value = foo(); # ok
35             my $sum = foo 1,2; # ok
36              
37             This policy is a subclass of the core policy
38             L<Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils>, and performs the
39             same 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 is not configurable except for the standard options.
48              
49             =head1 AUTHOR
50              
51             Dan Book, C<dbook@cpan.org>
52              
53             =head1 COPYRIGHT AND LICENSE
54              
55             Copyright 2015, Dan Book.
56              
57             This library is free software; you may redistribute it and/or modify it under
58             the terms of the Artistic License version 2.0.
59              
60             =head1 SEE ALSO
61              
62             L<Perl::Critic>