1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Subroutines/ProhibitAmpersandSigils.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Subroutine called with "&" sigil};
23 Readonly::Scalar my $EXPL => [ 175 ];
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_LOW }
29 sub default_themes { return qw(core pbp maintenance) }
30 sub applies_to { return 'PPI::Token::Symbol' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, undef ) = @_;
37 my $psib = $elem->sprevious_sibling();
39 #Sigil is allowed if taking a reference, e.g. "\&my_sub"
40 return if $psib->isa('PPI::Token::Cast') && $psib eq q{\\};
43 return if ( $elem !~ m{\A [&] }mx ); # ok
45 $psib = $elem->sprevious_sibling();
46 return if ( $psib eq 'goto'
48 or $psib eq 'defined' ); # ok
50 return $self->violation( $DESC, $EXPL, $elem );
57 #-----------------------------------------------------------------------------
63 Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils - Don't call functions with a leading ampersand sigil.
67 This Policy is part of the core L<Perl::Critic> distribution.
72 Since Perl 5, the ampersand sigil is completely optional when invoking
73 subroutines. And it's easily confused with the bitwise 'and' operator.
75 @result = &some_function(); #Not ok
76 @result = some_function(); #ok
81 This Policy is not configurable except for the standard options.
86 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
90 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
92 This program is free software; you can redistribute it and/or modify
93 it under the same terms as Perl itself. The full text of this license
94 can be found in the LICENSE file included with this module.
100 # cperl-indent-level: 4
102 # indent-tabs-mode: nil
103 # c-indentation-style: bsd
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :