| 1 | package Perl::Critic::Policy::Community::AmpersandSubCalls; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use parent 'Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | our $VERSION = 'v1.0.4'; | |
| 10 | |||
| 11 | 4 | ▶ | sub default_severity { $SEVERITY_HIGH } |
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||
| 12 | 0 | ▶ | sub default_themes { 'community' } |
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 13 | |||
| 14 | 1 | 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> | ||