line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Subroutines::ProhibitQualifiedSubDeclarations; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
550
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
3
|
use base 'Perl::Critic::Policy'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Perl::Critic::Utils qw( :severities &is_qualified_name ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.05; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
0
|
19752
|
sub supported_parameters { return } |
16
|
4
|
|
|
4
|
1
|
28
|
sub default_severity { return $SEVERITY_MEDIUM } |
17
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw( strictersubs bugs ) } |
18
|
3
|
|
|
3
|
1
|
24572
|
sub applies_to { return 'PPI::Statement::Sub' } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $desc = q{Subroutine declared with a qualified name}; |
23
|
|
|
|
|
|
|
my $expl = q{Remove package name from sub declaration}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
|
|
|
|
|
|
|
29
|
8
|
|
|
8
|
1
|
534
|
my ($self, $elem, undef) = @_; |
30
|
|
|
|
|
|
|
|
31
|
8
|
100
|
|
|
|
17
|
if ( is_qualified_name( $elem->name() ) ) { |
32
|
4
|
|
|
|
|
106
|
return $self->violation( $desc, $expl, $elem ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
78
|
return; #ok! |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perl::Critic::Policy::Subroutines::ProhibitQualifiedSubDeclarations |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 AFFILIATION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This policy is part of L<Perl::Critic::StricterSubs|Perl::Critic::StricterSubs>. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Perl permits you to declare subroutines into any package that you |
57
|
|
|
|
|
|
|
want. This can be downright dangerous if that package is already |
58
|
|
|
|
|
|
|
defined elsewhere. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
package Foo; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub Bar::frobulate {} #not ok |
63
|
|
|
|
|
|
|
sub frobulate {} #ok |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Even if you declare a subroutine into the current package, using |
66
|
|
|
|
|
|
|
a fully-qualified name is just weird. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
package Foo; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub Foo::frobulate {} #not ok |
71
|
|
|
|
|
|
|
sub frobulate {} #ok |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
So this Policy catches any subroutine declaration that contains "::" |
74
|
|
|
|
|
|
|
in the subroutine's name. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 CAVEATS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Overriding subroutines in other packages is a common testing |
79
|
|
|
|
|
|
|
technique. So you may want to disable this policy when critiquing |
80
|
|
|
|
|
|
|
test scripts. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <thaljef@cpan.org> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (c) 2007 Jeffrey Ryan Thalhammer. All rights reserved. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
############################################################################## |
93
|
|
|
|
|
|
|
# Local Variables: |
94
|
|
|
|
|
|
|
# mode: cperl |
95
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
96
|
|
|
|
|
|
|
# fill-column: 78 |
97
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
98
|
|
|
|
|
|
|
# c-indentation-style: bsd |
99
|
|
|
|
|
|
|
# End: |
100
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab : |