File Coverage

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


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Modules::ProhibitMultiplePackages;
2              
3 40     40   25758 use 5.010001;
  40         162  
4 40     40   233 use strict;
  40         94  
  40         869  
5 40     40   209 use warnings;
  40         116  
  40         1075  
6 40     40   219 use Readonly;
  40         119  
  40         2127  
7              
8 40     40   328 use Perl::Critic::Utils qw{ :severities };
  40         139  
  40         2174  
9 40     40   5219 use parent 'Perl::Critic::Policy';
  40         129  
  40         253  
10              
11             our $VERSION = '1.150';
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 89     89 0 1704 sub supported_parameters { return () }
21 74     74 1 312 sub default_severity { return $SEVERITY_HIGH }
22 74     74 1 263 sub default_themes { return qw( core bugs ) }
23 32     32 1 95 sub applies_to { return 'PPI::Document' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 32     32 1 114 my ( $self, $elem, $doc ) = @_;
29 32         117 my $nodes_ref = $doc->find('PPI::Statement::Package');
30 32 100       183 return if !$nodes_ref;
31 30 50       82 my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] :();
  30         118  
  0         0  
  0         0  
32              
33 30         116 return map {$self->violation($DESC, $EXPL, $_)} @matches;
  0            
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 :