File Coverage

blib/lib/Perl/Critic/Policy/Modules/ProhibitMultiplePackages.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 4 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 49 50 98.0


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Modules::ProhibitMultiplePackages;
2              
3 40     40   26419 use 5.010001;
  40         169  
4 40     40   298 use strict;
  40         103  
  40         884  
5 40     40   251 use warnings;
  40         93  
  40         1150  
6 40     40   255 use Readonly;
  40         131  
  40         2228  
7              
8 40     40   329 use Perl::Critic::Utils qw{ :severities };
  40         149  
  40         2177  
9 40     40   5430 use parent 'Perl::Critic::Policy';
  40         363  
  40         231  
10              
11             our $VERSION = '1.146';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Multiple "package" declarations};
16             Readonly::Scalar my $EXPL => q{Limit to one per file};
17              
18             #-----------------------------------------------------------------------------
19              
20 92     92 0 1718 sub supported_parameters { return () }
21 76     76 1 380 sub default_severity { return $SEVERITY_HIGH }
22 74     74 1 294 sub default_themes { return qw( core bugs ) }
23 35     35 1 122 sub applies_to { return 'PPI::Document' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 35     35 1 178 my ( $self, $elem, $doc ) = @_;
29 35         131 my $nodes_ref = $doc->find('PPI::Statement::Package');
30 35 100       220 return if !$nodes_ref;
31 32 100       82 my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] :();
  32         137  
  1         6  
  1         5  
32              
33 32         138 return map {$self->violation($DESC, $EXPL, $_)} @matches;
  2         17  
34             }
35              
36             1;
37              
38             __END__
39              
40             #-----------------------------------------------------------------------------
41              
42             =pod
43              
44             =head1 NAME
45              
46             Perl::Critic::Policy::Modules::ProhibitMultiplePackages - Put packages (especially subclasses) in separate files.
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             Conway doesn't specifically mention this, but I find it annoying when
58             there are multiple packages in the same file. When searching for
59             methods or keywords in your editor, it makes it hard to find the right
60             chunk of code, especially if each package is a subclass of the same
61             base.
62              
63              
64             =head1 CONFIGURATION
65              
66             This Policy is not configurable except for the standard options.
67              
68              
69             =head1 AUTHOR
70              
71             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
72              
73              
74             =head1 COPYRIGHT
75              
76             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
77              
78             This program is free software; you can redistribute it and/or modify
79             it under the same terms as Perl itself. The full text of this license
80             can be found in the LICENSE file included with this module.
81              
82             =cut
83              
84             # Local Variables:
85             # mode: cperl
86             # cperl-indent-level: 4
87             # fill-column: 78
88             # indent-tabs-mode: nil
89             # c-indentation-style: bsd
90             # End:
91             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :