line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
27363
|
use 5.010001; |
|
40
|
|
|
|
|
179
|
|
4
|
40
|
|
|
40
|
|
264
|
use strict; |
|
40
|
|
|
|
|
152
|
|
|
40
|
|
|
|
|
979
|
|
5
|
40
|
|
|
40
|
|
242
|
use warnings; |
|
40
|
|
|
|
|
121
|
|
|
40
|
|
|
|
|
1254
|
|
6
|
40
|
|
|
40
|
|
294
|
use Readonly; |
|
40
|
|
|
|
|
133
|
|
|
40
|
|
|
|
|
2296
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
369
|
use Perl::Critic::Utils qw{ :severities :classification }; |
|
40
|
|
|
|
|
140
|
|
|
40
|
|
|
|
|
2201
|
|
9
|
40
|
|
|
40
|
|
14608
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
166
|
|
|
40
|
|
|
|
|
274
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{UNIVERSAL::isa should not be used as a function}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Use eval{$obj->isa($pkg)} instead}; ## no critic (RequireInterp); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
91
|
|
|
91
|
0
|
1614
|
sub supported_parameters { return () } |
21
|
76
|
|
|
76
|
1
|
346
|
sub default_severity { return $SEVERITY_MEDIUM } |
22
|
74
|
|
|
74
|
1
|
383
|
sub default_themes { return qw( core maintenance certrule ) } |
23
|
32
|
|
|
32
|
1
|
111
|
sub applies_to { return 'PPI::Token::Word' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
336
|
|
|
336
|
1
|
672
|
my ( $self, $elem, undef ) = @_; |
29
|
336
|
100
|
100
|
|
|
711
|
return if !($elem eq 'isa' || $elem eq 'UNIVERSAL::isa'); |
30
|
5
|
100
|
|
|
|
109
|
return if ! is_function_call($elem); # this also permits 'use UNIVERSAL::isa;' |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
24
|
return $self->violation( $DESC, $EXPL, $elem ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=pod |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa - Write C<< eval { $foo->isa($pkg) } >> instead of C<UNIVERSAL::isa($foo, $pkg)>. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 AFFILIATION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
52
|
|
|
|
|
|
|
distribution. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
print UNIVERSAL::isa($obj, 'Foo::Bar') ? 'yes' : 'no'; #not ok |
58
|
|
|
|
|
|
|
print eval { $obj->isa('Foo::Bar') } ? 'yes' : 'no'; #ok |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
As of Perl 5.9.3, the use of C<UNIVERSAL::isa> as a function has been |
61
|
|
|
|
|
|
|
deprecated and the method form is preferred instead. Formerly, the |
62
|
|
|
|
|
|
|
functional form was recommended because it gave valid results even |
63
|
|
|
|
|
|
|
when the object was C<undef> or an unblessed scalar. However, the |
64
|
|
|
|
|
|
|
functional form makes it impossible for packages to override C<isa()>, |
65
|
|
|
|
|
|
|
a technique which is crucial for implementing mock objects and some |
66
|
|
|
|
|
|
|
facades. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Another alternative to UNIVERSAL::isa is the C<_INSTANCE> method of |
69
|
|
|
|
|
|
|
Param::Util, which is faster. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
See the CPAN module L<UNIVERSAL::isa|UNIVERSAL::isa> for an incendiary |
72
|
|
|
|
|
|
|
discussion of this topic. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 CONFIGURATION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
L<Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan|Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Chris Dolan <cdolan@cpan.org> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 COPYRIGHT |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Copyright (c) 2006-2011 Chris Dolan. |
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 : |