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 / ProhibitBuiltinHomonyms.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Subroutines/ProhibitBuiltinHomonyms.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::ProhibitBuiltinHomonyms;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities :data_conversion :classification };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Array my @ALLOW => qw( import AUTOLOAD DESTROY );
23 Readonly::Hash my %ALLOW => hashify( @ALLOW );
24 Readonly::Scalar my $DESC  => q{Subroutine name is a homonym for builtin function};
25 Readonly::Scalar my $EXPL  => [177];
26
27 #-----------------------------------------------------------------------------
28
29 sub supported_parameters { return ()                    }
30 sub default_severity     { return $SEVERITY_HIGH        }
31 sub default_themes       { return qw( core bugs pbp )   }
32 sub applies_to           { return 'PPI::Statement::Sub' }
33
34 #-----------------------------------------------------------------------------
35
36 sub violates {
37     my ( $self, $elem, undef ) = @_;
38     return if $elem->isa('PPI::Statement::Scheduled'); #e.g. BEGIN, INIT, END
39     return if exists $ALLOW{ $elem->name() };
40     if ( is_perl_builtin( $elem ) ) {
41         return $self->violation( $DESC, $EXPL, $elem );
42     }
43     return;    #ok!
44 }
45
46 1;
47
48 __END__
49
50 #-----------------------------------------------------------------------------
51
52 =pod
53
54 =head1 NAME
55
56 Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms - Don't declare your own C<open> function.
57
58 =head1 AFFILIATION
59
60 This Policy is part of the core L<Perl::Critic> distribution.
61
62
63 =head1 DESCRIPTION
64
65 Common sense dictates that you shouldn't declare subroutines with the
66 same name as one of Perl's built-in functions. See C<`perldoc
67 perlfunc`> for a list of built-ins.
68
69   sub open {}  #not ok
70   sub exit {}  #not ok
71   sub print {} #not ok
72
73   #You get the idea...
74
75 Exceptions are made for C<BEGIN>, C<END>, C<INIT> and C<CHECK> blocks,
76 as well as C<AUTOLOAD>, C<DESTROY>, and C<import> subroutines.
77
78
79 =head1 CONFIGURATION
80
81 This Policy is not configurable except for the standard options.
82
83
84 =head1 CAVEATS
85
86 It is reasonable to declare an B<object> method with the same name as
87 a Perl built-in function, since they are easily distinguished from
88 each other.  However, at this time, Perl::Critic cannot tell whether a
89 subroutine is static or an object method.
90
91 =head1 AUTHOR
92
93 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
94
95 =head1 COPYRIGHT
96
97 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
98
99 This program is free software; you can redistribute it and/or modify
100 it under the same terms as Perl itself.  The full text of this license
101 can be found in the LICENSE file included with this module.
102
103 =cut
104
105 # Local Variables:
106 #   mode: cperl
107 #   cperl-indent-level: 4
108 #   fill-column: 78
109 #   indent-tabs-mode: nil
110 #   c-indentation-style: bsd
111 # End:
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :