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   26929 use 5.010001;
  40         167  
4 40     40   240 use strict;
  40         117  
  40         1067  
5 40     40   270 use warnings;
  40         123  
  40         1094  
6 40     40   392 use Readonly;
  40         118  
  40         2374  
7              
8 40     40   315 use Perl::Critic::Utils qw{ :severities };
  40         333  
  40         2173  
9 40     40   5349 use parent 'Perl::Critic::Policy';
  40         125  
  40         503  
10              
11             our $VERSION = '1.148';
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 1663 sub supported_parameters { return () }
21 76     76 1 362 sub default_severity { return $SEVERITY_HIGH }
22 74     74 1 303 sub default_themes { return qw( core bugs ) }
23 35     35 1 123 sub applies_to { return 'PPI::Document' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 35     35 1 143 my ( $self, $elem, $doc ) = @_;
29 35         123 my $nodes_ref = $doc->find('PPI::Statement::Package');
30 35 100       211 return if !$nodes_ref;
31 32 100       101 my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] :();
  32         129  
  1         5  
  1         4  
32              
33 32         135 return map {$self->violation($DESC, $EXPL, $_)} @matches;
  2         14  
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 :