File Coverage

blib/lib/Perl/Critic/Policy/Subroutines/ProhibitQualifiedSubDeclarations.pm
Criterion Covered Total %
statement 19 20 95.0
branch 2 2 100.0
condition n/a
subroutine 8 9 88.8
pod 4 5 80.0
total 33 36 91.6


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