Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / Subroutines / ProhibitAmpersandSigils.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC  => q{Subroutine called with "&" sigil};
23 Readonly::Scalar my $EXPL  => [ 175 ];
24
25 #-----------------------------------------------------------------------------
26
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'     }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36
37     my $psib = $elem->sprevious_sibling();
38     if ( $psib ) {
39         #Sigil is allowed if taking a reference, e.g. "\&my_sub"
40         return if $psib->isa('PPI::Token::Cast') && $psib eq q{\\};
41     }
42
43     return if ( $elem !~ m{\A [&] }mx ); # ok
44
45     $psib = $elem->sprevious_sibling();
46     return if ( $psib eq 'goto'
47                 or $psib eq 'exists'
48                 or $psib eq 'defined' ); # ok
49
50     return $self->violation( $DESC, $EXPL, $elem );
51 }
52
53 1;
54
55 __END__
56
57 #-----------------------------------------------------------------------------
58
59 =pod
60
61 =head1 NAME
62
63 Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils - Don't call functions with a leading ampersand sigil.
64
65 =head1 AFFILIATION
66
67 This Policy is part of the core L<Perl::Critic> distribution.
68
69
70 =head1 DESCRIPTION
71
72 Since Perl 5, the ampersand sigil is completely optional when invoking
73 subroutines.  And it's easily confused with the bitwise 'and' operator.
74
75   @result = &some_function(); #Not ok
76   @result = some_function();  #ok
77
78
79 =head1 CONFIGURATION
80
81 This Policy is not configurable except for the standard options.
82
83
84 =head1 AUTHOR
85
86 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
87
88 =head1 COPYRIGHT
89
90 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
91
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.
95
96 =cut
97
98 # Local Variables:
99 #   mode: cperl
100 #   cperl-indent-level: 4
101 #   fill-column: 78
102 #   indent-tabs-mode: nil
103 #   c-indentation-style: bsd
104 # End:
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :