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 / BuiltinFunctions / ProhibitUniversalCan.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitUniversalCan.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::BuiltinFunctions::ProhibitUniversalCan;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities :classification };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{UNIVERSAL::can should not be used as a function};
23 Readonly::Scalar my $EXPL => q{Use eval{$obj->can($pkg)} instead};  ##no critic 'RequireInterp';
24
25 #-----------------------------------------------------------------------------
26
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'     }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36     return if !($elem eq 'can' || $elem eq 'UNIVERSAL::can');
37     return if ! is_function_call($elem); # this also permits 'use UNIVERSAL::can;'
38
39     return $self->violation( $DESC, $EXPL, $elem );
40 }
41
42
43 1;
44
45 __END__
46
47 #-----------------------------------------------------------------------------
48
49 =pod
50
51 =head1 NAME
52
53 Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan - Write C<< eval { $foo->can($name) } >> instead of C<UNIVERSAL::can($foo, $name)>.
54
55 =head1 AFFILIATION
56
57 This Policy is part of the core L<Perl::Critic> distribution.
58
59
60 =head1 DESCRIPTION
61
62   print UNIVERSAL::can($obj, 'Foo::Bar') ? 'yes' : 'no';  #not ok
63   print eval { $obj->can('Foo::Bar') } ? 'yes' : 'no';    #ok
64
65 As of Perl 5.9.3, the use of UNIVERSAL::can 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<can()>,
70 a technique which is crucial for implementing mock objects and some
71 facades.
72
73 See the CPAN module L<UNIVERSAL::can> for a more thorough discussion
74 of this topic.
75
76
77 =head1 CONFIGURATION
78
79 This Policy is not configurable except for the standard options.
80
81
82 =head1 SEE ALSO
83
84 L<Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa>
85
86 =head1 AUTHOR
87
88 Chris Dolan <cdolan@cpan.org>
89
90 =head1 COPYRIGHT
91
92 Copyright (c) 2006-2008 Chris Dolan.  All rights reserved.
93
94 This program is free software; you can redistribute it and/or modify
95 it under the same terms as Perl itself.  The full text of this license
96 can be found in the LICENSE file included with this module.
97
98 =cut
99
100 # Local Variables:
101 #   mode: cperl
102 #   cperl-indent-level: 4
103 #   fill-column: 78
104 #   indent-tabs-mode: nil
105 #   c-indentation-style: bsd
106 # End:
107 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :