1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitUniversalIsa.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa;
15 use Perl::Critic::Utils qw{ :severities :classification };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{UNIVERSAL::isa should not be used as a function};
23 Readonly::Scalar my $EXPL => q{Use eval{$obj->isa($pkg)} instead}; ##no critic 'RequireInterp';
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_MEDIUM }
29 sub default_themes { return qw( core maintenance ) }
30 sub applies_to { return 'PPI::Token::Word' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, undef ) = @_;
36 return if !($elem eq 'isa' || $elem eq 'UNIVERSAL::isa');
37 return if ! is_function_call($elem); # this also permits 'use UNIVERSAL::isa;'
39 return $self->violation( $DESC, $EXPL, $elem );
47 #-----------------------------------------------------------------------------
53 Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa - Write C<< eval { $foo->isa($pkg) } >> instead of C<UNIVERSAL::isa($foo, $pkg)>.
57 This Policy is part of the core L<Perl::Critic> distribution.
62 print UNIVERSAL::isa($obj, 'Foo::Bar') ? 'yes' : 'no'; #not ok
63 print eval { $obj->isa('Foo::Bar') } ? 'yes' : 'no'; #ok
65 As of Perl 5.9.3, the use of C<UNIVERSAL::isa> as a function has been
66 deprecated and the method form is preferred instead. Formerly, the
67 functional form was recommended because it gave valid results even
68 when the object was C<undef> or an unblessed scalar. However, the
69 functional form makes it impossible for packages to override C<isa()>,
70 a technique which is crucial for implementing mock objects and some
73 Another alternative to UNIVERSAL::isa is the C<_INSTANCE> method of
74 Param::Util, which is faster.
76 See the CPAN module L<UNIVERSAL::isa> for an incendiary discussion of
82 This Policy is not configurable except for the standard options.
87 L<Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan>
91 Chris Dolan <cdolan@cpan.org>
95 Copyright (c) 2006-2008 Chris Dolan. All rights reserved.
97 This program is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself. The full text of this license
99 can be found in the LICENSE file included with this module.
105 # cperl-indent-level: 4
107 # indent-tabs-mode: nil
108 # c-indentation-style: bsd
110 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :