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) $
6 ##############################################################################
8 package Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms;
15 use Perl::Critic::Utils qw{ :severities :data_conversion :classification };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
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];
27 #-----------------------------------------------------------------------------
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' }
34 #-----------------------------------------------------------------------------
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 );
50 #-----------------------------------------------------------------------------
56 Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms - Don't declare your own C<open> function.
60 This Policy is part of the core L<Perl::Critic> distribution.
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.
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.
81 This Policy is not configurable except for the standard options.
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.
93 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
97 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
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.
107 # cperl-indent-level: 4
109 # indent-tabs-mode: nil
110 # c-indentation-style: bsd
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :